@@ -2,7 +2,6 @@ use super::{AnonymousLifetimeMode, LoweringContext, ParamMode};
2
2
use super :: { ImplTraitContext , ImplTraitPosition } ;
3
3
use crate :: Arena ;
4
4
5
- use rustc_ast:: node_id:: NodeMap ;
6
5
use rustc_ast:: ptr:: P ;
7
6
use rustc_ast:: visit:: { self , AssocCtxt , FnCtxt , FnKind , Visitor } ;
8
7
use rustc_ast:: * ;
@@ -1351,8 +1350,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
1351
1350
generics : & Generics ,
1352
1351
itctx : ImplTraitContext < ' _ , ' hir > ,
1353
1352
) -> GenericsCtor < ' hir > {
1354
- // Collect `?Trait` bounds in where clause and move them to parameter definitions.
1355
- let mut add_bounds: NodeMap < Vec < _ > > = Default :: default ( ) ;
1353
+ // Error if `?Trait` bounds in where clauses don't refer directly to type paramters.
1354
+ // Note: we used to clone these bounds directly onto the type parameter (and avoid lowering
1355
+ // these into hir when we lower thee where clauses), but this makes it quite difficult to
1356
+ // keep track of the Span info. Now, `add_implicitly_sized` in `AstConv` checks both param bounds and
1357
+ // where clauses for `?Sized`.
1356
1358
for pred in & generics. where_clause . predicates {
1357
1359
if let WherePredicate :: BoundPredicate ( ref bound_pred) = * pred {
1358
1360
' next_bound: for bound in & bound_pred. bounds {
@@ -1368,7 +1370,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
1368
1370
{
1369
1371
for param in & generics. params {
1370
1372
if def_id == self . resolver . local_def_id ( param. id ) . to_def_id ( ) {
1371
- add_bounds. entry ( param. id ) . or_default ( ) . push ( bound. clone ( ) ) ;
1372
1373
continue ' next_bound;
1373
1374
}
1374
1375
}
@@ -1386,7 +1387,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
1386
1387
}
1387
1388
1388
1389
GenericsCtor {
1389
- params : self . lower_generic_params_mut ( & generics. params , & add_bounds , itctx) . collect ( ) ,
1390
+ params : self . lower_generic_params_mut ( & generics. params , itctx) . collect ( ) ,
1390
1391
where_clause : self . lower_where_clause ( & generics. where_clause ) ,
1391
1392
span : self . lower_span ( generics. span ) ,
1392
1393
}
@@ -1419,32 +1420,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
1419
1420
ref bounded_ty,
1420
1421
ref bounds,
1421
1422
span,
1422
- } ) => {
1423
- self . with_in_scope_lifetime_defs ( & bound_generic_params, |this| {
1424
- hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
1425
- bound_generic_params : this. lower_generic_params (
1426
- bound_generic_params,
1427
- & NodeMap :: default ( ) ,
1428
- ImplTraitContext :: disallowed ( ) ,
1429
- ) ,
1430
- bounded_ty : this. lower_ty ( bounded_ty, ImplTraitContext :: disallowed ( ) ) ,
1431
- bounds : this. arena . alloc_from_iter ( bounds. iter ( ) . map (
1432
- |bound| match bound {
1433
- // We used to ignore `?Trait` bounds, as they were copied into type
1434
- // parameters already, but we need to keep them around only for
1435
- // diagnostics when we suggest removal of `?Sized` bounds. See
1436
- // `suggest_constraining_type_param`. This will need to change if
1437
- // we ever allow something *other* than `?Sized`.
1438
- GenericBound :: Trait ( p, TraitBoundModifier :: Maybe ) => {
1439
- hir:: GenericBound :: Unsized ( this. lower_span ( p. span ) )
1440
- }
1441
- _ => this. lower_param_bound ( bound, ImplTraitContext :: disallowed ( ) ) ,
1442
- } ,
1443
- ) ) ,
1444
- span : this. lower_span ( span) ,
1445
- } )
1423
+ } ) => self . with_in_scope_lifetime_defs ( & bound_generic_params, |this| {
1424
+ hir:: WherePredicate :: BoundPredicate ( hir:: WhereBoundPredicate {
1425
+ bound_generic_params : this
1426
+ . lower_generic_params ( bound_generic_params, ImplTraitContext :: disallowed ( ) ) ,
1427
+ bounded_ty : this. lower_ty ( bounded_ty, ImplTraitContext :: disallowed ( ) ) ,
1428
+ bounds : this. arena . alloc_from_iter ( bounds. iter ( ) . map ( |bound| {
1429
+ this. lower_param_bound ( bound, ImplTraitContext :: disallowed ( ) )
1430
+ } ) ) ,
1431
+ span : this. lower_span ( span) ,
1446
1432
} )
1447
- }
1433
+ } ) ,
1448
1434
WherePredicate :: RegionPredicate ( WhereRegionPredicate {
1449
1435
ref lifetime,
1450
1436
ref bounds,
0 commit comments