@@ -136,6 +136,33 @@ impl<'a> AstValidator<'a> {
136
136
in patterns")
137
137
}
138
138
}
139
+
140
+ fn check_late_bound_lifetime_defs ( & self , params : & Vec < GenericParam > ) {
141
+ // Check: Only lifetime parameters
142
+ let non_lifetime_param_spans : Vec < _ > = params. iter ( )
143
+ . filter_map ( |param| match * param {
144
+ GenericParam :: Lifetime ( _) => None ,
145
+ GenericParam :: Type ( ref t) => Some ( t. span ) ,
146
+ } ) . collect ( ) ;
147
+ if !non_lifetime_param_spans. is_empty ( ) {
148
+ self . err_handler ( ) . span_err ( non_lifetime_param_spans,
149
+ "only lifetime parameters can be used in this context" ) ;
150
+ }
151
+
152
+ // Check: No bounds on lifetime parameters
153
+ for param in params. iter ( ) {
154
+ match * param {
155
+ GenericParam :: Lifetime ( ref l) => {
156
+ if !l. bounds . is_empty ( ) {
157
+ let spans : Vec < _ > = l. bounds . iter ( ) . map ( |b| b. span ) . collect ( ) ;
158
+ self . err_handler ( ) . span_err ( spans,
159
+ "lifetime bounds cannot be used in this context" ) ;
160
+ }
161
+ }
162
+ GenericParam :: Type ( _) => { }
163
+ }
164
+ }
165
+ }
139
166
}
140
167
141
168
impl < ' a > Visitor < ' a > for AstValidator < ' a > {
@@ -157,6 +184,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
157
184
struct_span_err ! ( self . session, span, E0561 ,
158
185
"patterns aren't allowed in function pointer types" ) . emit ( ) ;
159
186
} ) ;
187
+ self . check_late_bound_lifetime_defs ( & bfty. generic_params ) ;
160
188
}
161
189
TyKind :: TraitObject ( ref bounds, ..) => {
162
190
let mut any_lifetime_bounds = false ;
@@ -417,6 +445,19 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
417
445
418
446
visit:: walk_pat ( self , pat)
419
447
}
448
+
449
+ fn visit_where_predicate ( & mut self , p : & ' a WherePredicate ) {
450
+ if let & WherePredicate :: BoundPredicate ( ref bound_predicate) = p {
451
+ // A type binding, eg `for<'c> Foo: Send+Clone+'c`
452
+ self . check_late_bound_lifetime_defs ( & bound_predicate. bound_generic_params ) ;
453
+ }
454
+ visit:: walk_where_predicate ( self , p) ;
455
+ }
456
+
457
+ fn visit_poly_trait_ref ( & mut self , t : & ' a PolyTraitRef , m : & ' a TraitBoundModifier ) {
458
+ self . check_late_bound_lifetime_defs ( & t. bound_generic_params ) ;
459
+ visit:: walk_poly_trait_ref ( self , t, m) ;
460
+ }
420
461
}
421
462
422
463
// Bans nested `impl Trait`, e.g. `impl Into<impl Debug>`.
0 commit comments