1
Fork 0

Rollup merge of #77825 - ethanboxx:min_const_generics_diagnostic, r=lcnr

`min_const_generics` diagnostics improvements

As disscussed in [zulip/project-const-generics/non-trivial anonymous constant](https://rust-lang.zulipchat.com/#narrow/stream/260443-project-const-generics/topic/non-trivial.20anonymous.20constants).

This is my first PR on the compiler.

@lcnr is mentoring me on this PR.

Related to #60551.
This commit is contained in:
Yuki Okushi 2020-10-14 06:02:29 +09:00 committed by GitHub
commit c44cc7e236
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 185 additions and 192 deletions

View file

@ -469,24 +469,17 @@ impl<'a> Resolver<'a> {
ResolutionError::ParamInNonTrivialAnonConst { name, is_type } => {
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
),
"generic parameters may not be used in const operations",
);
err.span_label(span, &format!("cannot perform const operation using `{}`", name));
if is_type {
err.note("type parameters are currently not permitted in anonymous constants");
err.note("type parameters may not be used in const expressions");
} else {
err.help(
&format!("it is currently only allowed to use either `{0}` or `{{ {0} }}` as generic constants",
name
)
);
err.help(&format!(
"const parameters may only be used as standalone arguments, i.e. `{}`",
name
));
}
err

View file

@ -218,7 +218,7 @@ enum ResolutionError<'a> {
ParamInTyOfConstParam(Symbol),
/// constant values inside of type parameter defaults must not depend on generic parameters.
ParamInAnonConstInTyDefault(Symbol),
/// generic parameters must not be used inside of non-trivial constant values.
/// generic parameters must not be used inside const evaluations.
///
/// This error is only emitted when using `min_const_generics`.
ParamInNonTrivialAnonConst { name: Symbol, is_type: bool },