-
Notifications
You must be signed in to change notification settings - Fork 14k
Closed
Labels
C-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.An error is correctly emitted, but is confusing, for `min_const_generics`.
Description
#![feature(min_const_generics)]
fn test<T>() -> [u8; std::mem::size_of::<T>()] {
todo!()
}emits
error: generic parameters must not be used inside of non trivial constant values
--> src/lib.rs:3:42
|
3 | fn test<T>() -> [u8; std::mem::size_of::<T>()] {
| ^ non-trivial anonymous constants must not depend on the parameter `T`
|
= help: it is currently only allowed to use either `T` or `{ T }` as generic constants
The help is incorrect here, as type parameters in constants are not supported at all with min_const_generics.
The error is emitted here
rust/compiler/rustc_resolve/src/diagnostics.rs
Lines 469 to 485 in b5f55b7
| ResolutionError::ParamInNonTrivialAnonConst(name) => { | |
| let mut err = self.session.struct_span_err( | |
| span, | |
| "generic parameters must not be used inside of non trivial constant values", | |
| ); | |
| err.span_label( | |
| span, | |
| &format!( | |
| "non-trivial anonymous constants must not depend on the parameter `{}`", | |
| name | |
| ), | |
| ); | |
| err.help( | |
| &format!("it is currently only allowed to use either `{0}` or `{{ {0} }}` as generic constants", name) | |
| ); | |
| err | |
| } |
We probably want to change ParamInNonTrivialAnonConst to instead contain an Option which is only Some for const parameters.
For type parameters we can instead emit a note saying
note: type parameters are currently not permitted in anonymous constants
If you need more help feel free to ask either here on on zulip.
Metadata
Metadata
Assignees
Labels
C-bugCategory: This is a bug.Category: This is a bug.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.E-easyCall for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.E-mentorCall for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.An error is correctly emitted, but is confusing, for `min_const_generics`.