@@ -1213,8 +1213,41 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1213
1213
deny_equality_constraints(self, predicate, generics);
1214
1214
}
1215
1215
}
1216
-
1217
- visit::walk_generics(self, generics)
1216
+ walk_list!(self, visit_generic_param, &generics.params);
1217
+ for predicate in &generics.where_clause.predicates {
1218
+ match predicate {
1219
+ WherePredicate::BoundPredicate(bound_pred) => {
1220
+ // A type binding, eg `for<'c> Foo: Send+Clone+'c`
1221
+ self.check_late_bound_lifetime_defs(&bound_pred.bound_generic_params);
1222
+
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
+ }
1246
+ }
1247
+ _ => {}
1248
+ }
1249
+ self.visit_where_predicate(predicate);
1250
+ }
1218
1251
}
1219
1252
1220
1253
fn visit_generic_param(&mut self, param: &'a GenericParam) {
@@ -1263,14 +1296,6 @@ impl<'a> Visitor<'a> for AstValidator<'a> {
1263
1296
visit::walk_pat(self, pat)
1264
1297
}
1265
1298
1266
- fn visit_where_predicate(&mut self, p: &'a WherePredicate) {
1267
- if let &WherePredicate::BoundPredicate(ref bound_predicate) = p {
1268
- // A type binding, eg `for<'c> Foo: Send+Clone+'c`
1269
- self.check_late_bound_lifetime_defs(&bound_predicate.bound_generic_params);
1270
- }
1271
- visit::walk_where_predicate(self, p);
1272
- }
1273
-
1274
1299
fn visit_poly_trait_ref(&mut self, t: &'a PolyTraitRef, m: &'a TraitBoundModifier) {
1275
1300
self.check_late_bound_lifetime_defs(&t.bound_generic_params);
1276
1301
visit::walk_poly_trait_ref(self, t, m);
0 commit comments