Skip to content
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
25 changes: 19 additions & 6 deletions src/librustc_ast_passes/ast_validation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1118,13 +1118,26 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
fn visit_generics(&mut self, generics: &'a Generics) {
let mut prev_ty_default = None;
for param in &generics.params {
if let GenericParamKind::Type { ref default, .. } = param.kind {
if default.is_some() {
match param.kind {
GenericParamKind::Lifetime => (),
GenericParamKind::Type { default: Some(_), .. } => {
prev_ty_default = Some(param.ident.span);
} else if let Some(span) = prev_ty_default {
self.err_handler()
.span_err(span, "type parameters with a default must be trailing");
break;
}
GenericParamKind::Type { .. } | GenericParamKind::Const { .. } => {
if let Some(span) = prev_ty_default {
let mut err = self.err_handler().struct_span_err(
span,
"type parameters with a default must be trailing",
);
if matches!(param.kind, GenericParamKind::Const { .. }) {
err.note(
"using type defaults and const parameters \
in the same parameter list is currently not permitted",
);
}
err.emit();
break;
}
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/const-generics/defaults/wrong-order.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete

struct A<T = u32, const N: usize> {
//~^ ERROR type parameters with a default must be trailing
arg: T,
}

fn main() {}
19 changes: 19 additions & 0 deletions src/test/ui/const-generics/defaults/wrong-order.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
error: type parameters with a default must be trailing
--> $DIR/wrong-order.rs:3:10
|
LL | struct A<T = u32, const N: usize> {
| ^
|
= note: using type defaults and const parameters in the same parameter list is currently not permitted

warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/wrong-order.rs:1:12
|
LL | #![feature(const_generics)]
| ^^^^^^^^^^^^^^
|
= note: `#[warn(incomplete_features)]` on by default
= note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information

error: aborting due to previous error; 1 warning emitted