Repository navigation
Tweak output on misused const parameter to provide more context and more accurate suggestion - #164775
Conversation
|
r? @wesleywiser rustbot has assigned @wesleywiser. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
aa81524 to
d5fa09c
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
69d8e14 to
8cb71cd
Compare
This comment has been minimized.
This comment has been minimized.
| | ^^^^^^^^^^^^^^^^ expected `u32`, found `u64` | ||
| | ------------ ^^^^^^^^^^^^^^^^ expected `u32`, found `u64` | ||
| | | | ||
| | found this const parameter |
There was a problem hiding this comment.
Is there a better message we can give than this? I'm not sure exactly what this note is trying to tell me 🙂
Maybe?
error: the constant `N` is not of type `u32`
--> $DIR/mismatched-types-with-generic-in-ace.rs:15:29
|
LL | fn bar<const N: u64, T: Foo<ASSOC<N> = { N }>>() {}
| ------------ ^^^^^^^^^^^^^^^^ expected `u32`, found `u64`
| |
| `N` is defined here
8cb71cd to
ff0444a
Compare
This comment has been minimized.
This comment has been minimized.
```
error[E0107]: missing generics for struct `a::Foo`
--> $DIR/impl-block-missing-const-generics.rs:6:10
|
LL | impl Foo {}
| ^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `AHA`
--> $DIR/impl-block-missing-const-generics.rs:4:12
|
LL | struct Foo<const AHA: usize>{}
| ^^^ ----------------
help: add missing generic argument
|
LL | impl<const AHA: usize> Foo<AHA> {}
| ++++++++++++++++++ +++++
```
Previously we only suggested `Foo<AHA>` without the `impl<const AHA: usize>`.
``` error: the constant `N` is not of type `usize` --> $DIR/const-in-impl-fn-return-type.rs:12:32 | LL | fn func<const N: u32>() -> [(); N]; | ------------ ^^^^^^^ expected `usize`, found `u32` | | | found this const parameter | = note: the length of array `[(); N]` must be type `usize` ```
``` error: the constant `B` is not of type `usize` --> $DIR/check_const_arg_type_in_free_alias.rs:15:30 | LL | type ArrLen<const B: bool> = [(); B]; | ------------- ^^^^^^^ expected `usize`, found `bool` | | | found this const parameter | = note: the length of array `[(); B]` must be type `usize` ```
```
error: the constant `N` is not of type `usize`
--> $DIR/bad-subst-const-kind.rs:8:26
|
LL | impl<const N: u64> Q for [u8; N] {
| ------------ ^^^^^^^ expected `usize`, found `u64`
| |
| `N` defined here
|
= note: the length of array `[u8; N]` must be type `usize`
```
|
@bors r+ rollup |
| LL | impl<T, 'a> Reborrow for PhantomData<'a, T> {} | ||
| | ++ +++ |
There was a problem hiding this comment.
Note to self: need to follow up and suggest <'a, T> instead of <T, 'a>. Applying the suggestion should provide a appropriate suggestion already, but better to handle eagerly if possible. This bug is likely present in more than one suggestion.
There was a problem hiding this comment.
The fix is a single line. I'll push to this PR and take your reapproval as a given @wesleywiser :)
ff0444a to
ca9e035
Compare
|
This pull request was unapproved. |
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r=wesleywiser |
…sleywiser
Tweak output on misused `const` parameter to provide more context and more accurate suggestion
When missing `const` param in `impl`, provide complete suggestion:
```
error[E0107]: missing generics for struct `a::Foo`
--> $DIR/impl-block-missing-const-generics.rs:6:10
|
LL | impl Foo {}
| ^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `AHA`
--> $DIR/impl-block-missing-const-generics.rs:4:12
|
LL | struct Foo<const AHA: usize>{}
| ^^^ ----------------
help: add missing generic argument
|
LL | impl<const AHA: usize> Foo<AHA> {}
| ++++++++++++++++++ +++++
```
Previously we only suggested `Foo<AHA>` without the `impl<const AHA: usize>`.
Fix rust-lang#91119.
Point at `const` param declaration when constant is not expected type:
```
error: the constant `N` is not of type `usize`
--> $DIR/const-in-impl-fn-return-type.rs:12:32
|
LL | fn func<const N: u32>() -> [(); N];
| ------------ ^^^^^^^ expected `usize`, found `u32`
| |
| found this const parameter
|
= note: the length of array `[(); N]` must be type `usize`
```
…uwer Rollup of 6 pull requests Successful merges: - #164775 (Tweak output on misused `const` parameter to provide more context and more accurate suggestion) - #165448 (Update `Vec::retain_unstable` docs to say that this method is generally faster than `Vec::retain_mut`) - #165503 (update Enzyme submodule) - #165505 (DFV: Reject `#[non_exhaustive]` on enum variants with default field values) - #165514 (Remove unused `WhereEqPredicate` and `ScopeId` types) - #165519 (Update books)
…uwer Rollup of 6 pull requests Successful merges: - #164775 (Tweak output on misused `const` parameter to provide more context and more accurate suggestion) - #165448 (Update `Vec::retain_unstable` docs to say that this method is generally faster than `Vec::retain_mut`) - #165503 (update Enzyme submodule) - #165505 (DFV: Reject `#[non_exhaustive]` on enum variants with default field values) - #165514 (Remove unused `WhereEqPredicate` and `ScopeId` types) - #165519 (Update books)
…sleywiser
Tweak output on misused `const` parameter to provide more context and more accurate suggestion
When missing `const` param in `impl`, provide complete suggestion:
```
error[E0107]: missing generics for struct `a::Foo`
--> $DIR/impl-block-missing-const-generics.rs:6:10
|
LL | impl Foo {}
| ^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `AHA`
--> $DIR/impl-block-missing-const-generics.rs:4:12
|
LL | struct Foo<const AHA: usize>{}
| ^^^ ----------------
help: add missing generic argument
|
LL | impl<const AHA: usize> Foo<AHA> {}
| ++++++++++++++++++ +++++
```
Previously we only suggested `Foo<AHA>` without the `impl<const AHA: usize>`.
Fix rust-lang#91119.
Point at `const` param declaration when constant is not expected type:
```
error: the constant `N` is not of type `usize`
--> $DIR/const-in-impl-fn-return-type.rs:12:32
|
LL | fn func<const N: u32>() -> [(); N];
| ------------ ^^^^^^^ expected `usize`, found `u32`
| |
| found this const parameter
|
= note: the length of array `[(); N]` must be type `usize`
```
…sleywiser
Tweak output on misused `const` parameter to provide more context and more accurate suggestion
When missing `const` param in `impl`, provide complete suggestion:
```
error[E0107]: missing generics for struct `a::Foo`
--> $DIR/impl-block-missing-const-generics.rs:6:10
|
LL | impl Foo {}
| ^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `AHA`
--> $DIR/impl-block-missing-const-generics.rs:4:12
|
LL | struct Foo<const AHA: usize>{}
| ^^^ ----------------
help: add missing generic argument
|
LL | impl<const AHA: usize> Foo<AHA> {}
| ++++++++++++++++++ +++++
```
Previously we only suggested `Foo<AHA>` without the `impl<const AHA: usize>`.
Fix rust-lang#91119.
Point at `const` param declaration when constant is not expected type:
```
error: the constant `N` is not of type `usize`
--> $DIR/const-in-impl-fn-return-type.rs:12:32
|
LL | fn func<const N: u32>() -> [(); N];
| ------------ ^^^^^^^ expected `usize`, found `u32`
| |
| found this const parameter
|
= note: the length of array `[(); N]` must be type `usize`
```
…uwer Rollup of 19 pull requests Successful merges: - #164784 (Introduce OptimizationObjective and fix the entry shim's size attributes) - #165037 (Drop array elements in order after a partial move) - #165078 (Use the `2.38` binutils version in CI) - #159374 (Lower #[no_mangle] to #[symbol_name]/#[link_name]) - #163284 (feat(Reborrow): Allow multiple lifetimes) - #164775 (Tweak output on misused `const` parameter to provide more context and more accurate suggestion) - #165194 (name elided lifetimes in `use<...>` suggestion when `impl Trait` params are present) - #165222 (Anonymize inner binders when checking refining) - #165335 (Fallible type ops) - #165388 (Accept variadic SysV64, Win64, and Aapcs FnAbis in rustc_public) - #165448 (Update `Vec::retain_unstable` docs to say that this method is generally faster than `Vec::retain_mut`) - #165494 (fix Miri ICE on exit with () return type) - #165503 (update Enzyme submodule) - #165505 (DFV: Reject `#[non_exhaustive]` on enum variants with default field values) - #165512 (Fix warnings for the L4Re targets) - #165514 (Remove unused `WhereEqPredicate` and `ScopeId` types) - #165518 (style-guide: Remove ABI explicitness prescription for extern items) - #165519 (Update books) - #165534 (rename MIR_borrow_checking timing scope to less confusing name)
Rollup of 15 pull requests Successful merges: - #165037 (Drop array elements in order after a partial move) - #165550 (Make `Literal::cstr_value` return a `CString`) - #159374 (Lower #[no_mangle] to #[symbol_name]/#[link_name]) - #163284 (feat(Reborrow): Allow multiple lifetimes) - #164775 (Tweak output on misused `const` parameter to provide more context and more accurate suggestion) - #165194 (name elided lifetimes in `use<...>` suggestion when `impl Trait` params are present) - #165222 (Anonymize inner binders when checking refining) - #165335 (Fallible type ops) - #165388 (Accept variadic SysV64, Win64, and Aapcs FnAbis in rustc_public) - #165448 (Update `Vec::retain_unstable` docs to say that this method is generally faster than `Vec::retain_mut`) - #165494 (fix Miri ICE on exit with () return type) - #165505 (DFV: Reject `#[non_exhaustive]` on enum variants with default field values) - #165512 (Fix warnings for the L4Re targets) - #165514 (Remove unused `WhereEqPredicate` and `ScopeId` types) - #165518 (style-guide: Remove ABI explicitness prescription for extern items)
Rollup merge of #164775 - estebank:missing-const-param, r=wesleywiser Tweak output on misused `const` parameter to provide more context and more accurate suggestion When missing `const` param in `impl`, provide complete suggestion: ``` error[E0107]: missing generics for struct `a::Foo` --> $DIR/impl-block-missing-const-generics.rs:6:10 | LL | impl Foo {} | ^^^ expected 1 generic argument | note: struct defined here, with 1 generic parameter: `AHA` --> $DIR/impl-block-missing-const-generics.rs:4:12 | LL | struct Foo<const AHA: usize>{} | ^^^ ---------------- help: add missing generic argument | LL | impl<const AHA: usize> Foo<AHA> {} | ++++++++++++++++++ +++++ ``` Previously we only suggested `Foo<AHA>` without the `impl<const AHA: usize>`. Fix #91119. Point at `const` param declaration when constant is not expected type: ``` error: the constant `N` is not of type `usize` --> $DIR/const-in-impl-fn-return-type.rs:12:32 | LL | fn func<const N: u32>() -> [(); N]; | ------------ ^^^^^^^ expected `usize`, found `u32` | | | found this const parameter | = note: the length of array `[(); N]` must be type `usize` ```
When missing
constparam inimpl, provide complete suggestion:Previously we only suggested
Foo<AHA>without theimpl<const AHA: usize>.Fix #91119.
Point at
constparam declaration when constant is not expected type: