Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add test for forward declared const param defaults #85896

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_resolve/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -2617,7 +2617,7 @@ impl<'a> Resolver<'a> {
let res_error = if rib_ident.name == kw::SelfUpper {
ResolutionError::SelfInTyParamDefault
} else {
ResolutionError::ForwardDeclaredTyParam
ResolutionError::ForwardDeclaredGenericParam
};
self.report_error(span, res_error);
}
Expand Down
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/defaults/forward-declared.rs
Original file line number Diff line number Diff line change
@@ -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() {}
27 changes: 27 additions & 0 deletions src/test/ui/const-generics/defaults/forward-declared.stderr
Original file line number Diff line number Diff line change
@@ -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`.