Add test for forward declared const param defaults

This commit is contained in:
Ellen 2021-06-01 17:44:49 +01:00
parent 80af6b091f
commit ba680aa5f2
4 changed files with 45 additions and 3 deletions

View File

@ -450,7 +450,7 @@ impl<'a> Resolver<'a> {
err.span_label(shadowed_binding_span, msg);
err
}
ResolutionError::ForwardDeclaredTyParam => {
ResolutionError::ForwardDeclaredGenericParam => {
let mut err = struct_span_err!(
self.session,
span,

View File

@ -242,7 +242,7 @@ enum ResolutionError<'a> {
shadowed_binding_span: Span,
},
/// Error E0128: generic parameters with a default cannot use forward-declared identifiers.
ForwardDeclaredTyParam, // FIXME(const_generics_defaults)
ForwardDeclaredGenericParam,
/// ERROR E0770: the type of const parameters must not depend on other generic parameters.
ParamInTyOfConstParam(Symbol),
/// generic parameters must not be used inside const evaluations.
@ -2617,7 +2617,7 @@ fn validate_res_from_ribs(
let res_error = if rib_ident.name == kw::SelfUpper {
ResolutionError::SelfInTyParamDefault
} else {
ResolutionError::ForwardDeclaredTyParam
ResolutionError::ForwardDeclaredGenericParam
};
self.report_error(span, res_error);
}

View File

@ -0,0 +1,15 @@
#![feature(const_generics_defaults)]
struct Foo<const N: usize = M, const M: usize = 10>;
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
enum Bar<const N: usize = M, const M: usize = 10> {}
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
struct Foo2<const N: usize = N>;
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
enum Bar2<const N: usize = N> {}
//~^ ERROR generic parameters with a default cannot use forward declared identifiers
fn main() {}

View File

@ -0,0 +1,27 @@
error[E0128]: generic parameters with a default cannot use forward declared identifiers
--> $DIR/forward-declared.rs:3:29
|
LL | struct Foo<const N: usize = M, const M: usize = 10>;
| ^ defaulted generic parameters cannot be forward declared
error[E0128]: generic parameters with a default cannot use forward declared identifiers
--> $DIR/forward-declared.rs:6:27
|
LL | enum Bar<const N: usize = M, const M: usize = 10> {}
| ^ defaulted generic parameters cannot be forward declared
error[E0128]: generic parameters with a default cannot use forward declared identifiers
--> $DIR/forward-declared.rs:9:30
|
LL | struct Foo2<const N: usize = N>;
| ^ defaulted generic parameters cannot be forward declared
error[E0128]: generic parameters with a default cannot use forward declared identifiers
--> $DIR/forward-declared.rs:12:28
|
LL | enum Bar2<const N: usize = N> {}
| ^ defaulted generic parameters cannot be forward declared
error: aborting due to 4 previous errors
For more information about this error, try `rustc --explain E0128`.