Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide structured suggestion for unconstrained generic constant #122802

Merged
merged 1 commit into from Mar 25, 2024

Commits on Mar 21, 2024

  1. Provide structured suggestion for unconstrained generic constant

    ```
    error: unconstrained generic constant
      --> $DIR/const-argument-if-length.rs:18:10
       |
    LL |     pad: [u8; is_zst::<T>()],
       |          ^^^^^^^^^^^^^^^^^^^
       |
    help: try adding a `where` bound
       |
    LL | pub struct AtLeastByte<T: ?Sized> where [(); is_zst::<T>()]: {
       |                                   ++++++++++++++++++++++++++
    ```
    
    Detect when the constant expression isn't `usize` and suggest casting:
    
    ```
    error: unconstrained generic constant
     --> f300.rs:6:10
      |
    6 |     bb::<{!N}>();
      |          ^^^^
    -Ztrack-diagnostics: created at compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs:3539:36
      |
    help: try adding a `where` bound
      |
    5 | fn b<const N: bool>() where [(); {!N} as usize]: {
      |                       ++++++++++++++++++++++++++
    ```
    
    Fix rust-lang#122395.
    estebank committed Mar 21, 2024
    Copy the full SHA
    6b24fdf View commit details
    Browse the repository at this point in the history