Skip to content

min_const_generics: ty param in const incorrect help #76701

Closed
@lcnr

Description

@lcnr
#![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

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.D-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.E-easyCall 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.const-generics-bad-diagnosticsAn error is correctly emitted, but is confusing, for `min_const_generics`.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions