Skip to content

min_const_generics: ty param in const incorrect help #76701

New issue

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

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

Already on GitHub? # to your account

Closed
lcnr opened this issue Sep 14, 2020 · 1 comment · Fixed by #76719
Closed

min_const_generics: ty param in const incorrect help #76701

lcnr opened this issue Sep 14, 2020 · 1 comment · Fixed by #76719
Assignees
Labels
C-bug Category: This is a bug. const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.

Comments

@lcnr
Copy link
Contributor

lcnr commented Sep 14, 2020

#![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.

@lcnr lcnr added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. C-bug Category: This is a bug. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. F-min_const_generics const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`. labels Sep 14, 2020
@hameerabbasi
Copy link
Contributor

@rustbot claim

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
C-bug Category: This is a bug. const-generics-bad-diagnostics An error is correctly emitted, but is confusing, for `min_const_generics`. D-incorrect Diagnostics: A diagnostic that is giving misleading or incorrect information. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants