@@ -81,13 +81,6 @@ struct AstValidator<'a> {
81
81
is_assoc_ty_bound_banned: bool,
82
82
83
83
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,
91
84
}
92
85
93
86
impl<'a> AstValidator<'a> {
@@ -1227,17 +1220,33 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1227
1220
// A type binding, eg `for<'c> Foo: Send+Clone+'c`
1228
1221
self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
1229
1222
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
+ }
1239
1246
}
1247
+ _ => {}
1240
1248
}
1249
+ self.visit_where_predicate(predicate);
1241
1250
}
1242
1251
}
1243
1252
@@ -1289,19 +1298,7 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1289
1298
1290
1299
fn visit_poly_trait_ref(&mut self, t: &'a PolyTraitRef, m: &'a TraitBoundModifier) {
1291
1300
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;
1303
1301
visit::walk_poly_trait_ref(self, t, m);
1304
- self.trait_ref_hack = trait_ref_hack;
1305
1302
}
1306
1303
1307
1304
fn visit_variant_data(&mut self, s: &'a VariantData) {
@@ -1520,7 +1517,6 @@ pub fn check_crate(session: &Session, krate: &Crate, lints: &mut LintBuffer) ->
1520
1517
is_impl_trait_banned: false,
1521
1518
is_assoc_ty_bound_banned: false,
1522
1519
lint_buffer: lints,
1523
- trait_ref_hack: false,
1524
1520
};
1525
1521
visit::walk_crate(&mut validator, krate);
1526
1522
0 commit comments