File tree 3 files changed +46
-6
lines changed
test/ui/const-generics/defaults
3 files changed +46
-6
lines changed Original file line number Diff line number Diff line change @@ -1118,13 +1118,26 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1118
1118
fn visit_generics ( & mut self , generics : & ' a Generics ) {
1119
1119
let mut prev_ty_default = None ;
1120
1120
for param in & generics. params {
1121
- if let GenericParamKind :: Type { ref default, .. } = param. kind {
1122
- if default. is_some ( ) {
1121
+ match param. kind {
1122
+ GenericParamKind :: Lifetime => ( ) ,
1123
+ GenericParamKind :: Type { default : Some ( _) , .. } => {
1123
1124
prev_ty_default = Some ( param. ident . span ) ;
1124
- } else if let Some ( span) = prev_ty_default {
1125
- self . err_handler ( )
1126
- . span_err ( span, "type parameters with a default must be trailing" ) ;
1127
- break ;
1125
+ }
1126
+ GenericParamKind :: Type { .. } | GenericParamKind :: Const { .. } => {
1127
+ if let Some ( span) = prev_ty_default {
1128
+ let mut err = self . err_handler ( ) . struct_span_err (
1129
+ span,
1130
+ "type parameters with a default must be trailing" ,
1131
+ ) ;
1132
+ if matches ! ( param. kind, GenericParamKind :: Const { .. } ) {
1133
+ err. note (
1134
+ "using type defaults and const parameters \
1135
+ in the same parameter listing is currently not possible",
1136
+ ) ;
1137
+ }
1138
+ err. emit ( ) ;
1139
+ break ;
1140
+ }
1128
1141
}
1129
1142
}
1130
1143
}
Original file line number Diff line number Diff line change
1
+ #![ feature( const_generics) ] //~ WARN the feature `const_generics` is incomplete
2
+
3
+ struct A < T = u32 , const N : usize > {
4
+ //~^ ERROR type parameters with a default must be trailing
5
+ arg : T ,
6
+ }
7
+
8
+ fn main ( ) { }
Original file line number Diff line number Diff line change
1
+ error: type parameters with a default must be trailing
2
+ --> $DIR/wrong-order.rs:3:10
3
+ |
4
+ LL | struct A<T = u32, const N: usize> {
5
+ | ^
6
+ |
7
+ = note: using type defaults and const parameters in the same parameter listing is currently not possible
8
+
9
+ warning: the feature `const_generics` is incomplete and may not be safe to use and/or cause compiler crashes
10
+ --> $DIR/wrong-order.rs:1:12
11
+ |
12
+ LL | #![feature(const_generics)]
13
+ | ^^^^^^^^^^^^^^
14
+ |
15
+ = note: `#[warn(incomplete_features)]` on by default
16
+ = note: see issue #44580 <https://github.com/rust-lang/rust/issues/44580> for more information
17
+
18
+ error: aborting due to previous error; 1 warning emitted
19
+
You can’t perform that action at this time.
0 commit comments