@@ -81,13 +81,6 @@ struct AstValidator<'a> {
8181 is_assoc_ty_bound_banned : bool ,
8282
8383 lint_buffer : & ' a mut LintBuffer ,
84-
85- /// This is slightly complicated. Our representation for poly-trait-refs contains a single
86- /// binder and thus we only allow a single level of quantification. However,
87- /// the syntax of Rust permits quantification in two places in where clauses,
88- /// e.g., `T: for <'a> Foo<'a>` and `for <'a, 'b> &'b T: Foo<'a>`. If both are
89- /// defined, then error.
90- trait_ref_hack : bool ,
9184}
9285
9386impl < ' a > AstValidator < ' a > {
@@ -1227,17 +1220,33 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12271220 // A type binding, eg `for<'c> Foo: Send+Clone+'c`
12281221 self . check_late_bound_lifetime_defs ( & bound_pred. bound_generic_params ) ;
12291222
1230- self . visit_ty ( & bound_pred. bounded_ty ) ;
1231-
1232- self . trait_ref_hack = !bound_pred. bound_generic_params . is_empty ( ) ;
1233- walk_list ! ( self , visit_param_bound, & bound_pred. bounds) ;
1234- walk_list ! ( self , visit_generic_param, & bound_pred. bound_generic_params) ;
1235- self . trait_ref_hack = false ;
1236- }
1237- _ => {
1238- self . visit_where_predicate ( predicate) ;
1223+ // This is slightly complicated. Our representation for poly-trait-refs contains a single
1224+ // binder and thus we only allow a single level of quantification. However,
1225+ // the syntax of Rust permits quantification in two places in where clauses,
1226+ // e.g., `T: for <'a> Foo<'a>` and `for <'a, 'b> &'b T: Foo<'a>`. If both are
1227+ // defined, then error.
1228+ if !bound_pred. bound_generic_params . is_empty ( ) {
1229+ for bound in & bound_pred. bounds {
1230+ match bound {
1231+ GenericBound :: Trait ( t, _) => {
1232+ if !t. bound_generic_params . is_empty ( ) {
1233+ struct_span_err ! (
1234+ self . err_handler( ) ,
1235+ t. span,
1236+ E0316 ,
1237+ "nested quantification of lifetimes"
1238+ )
1239+ . emit ( ) ;
1240+ }
1241+ }
1242+ GenericBound :: Outlives ( _) => { }
1243+ }
1244+ }
1245+ }
12391246 }
1247+ _ => { }
12401248 }
1249+ self . visit_where_predicate ( predicate) ;
12411250 }
12421251 }
12431252
@@ -1289,19 +1298,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
12891298
12901299 fn visit_poly_trait_ref ( & mut self , t : & ' a PolyTraitRef , m : & ' a TraitBoundModifier ) {
12911300 self . check_late_bound_lifetime_defs ( & t. bound_generic_params ) ;
1292- if self . trait_ref_hack && !t. bound_generic_params . is_empty ( ) {
1293- struct_span_err ! (
1294- self . err_handler( ) ,
1295- t. span,
1296- E0316 ,
1297- "nested quantification of lifetimes"
1298- )
1299- . emit ( ) ;
1300- }
1301- let trait_ref_hack = self . trait_ref_hack ;
1302- self . trait_ref_hack = false ;
13031301 visit:: walk_poly_trait_ref ( self , t, m) ;
1304- self . trait_ref_hack = trait_ref_hack;
13051302 }
13061303
13071304 fn visit_variant_data ( & mut self , s : & ' a VariantData ) {
@@ -1520,7 +1517,6 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) ->
15201517 is_impl_trait_banned : false ,
15211518 is_assoc_ty_bound_banned : false ,
15221519 lint_buffer : lints,
1523- trait_ref_hack : false ,
15241520 } ;
15251521 visit:: walk_crate ( & mut validator, krate) ;
15261522
0 commit comments