@@ -2,7 +2,6 @@ use super::{AnonymousLifetimeMode, LoweringContext, ParamMode};
22use super :: { ImplTraitContext , ImplTraitPosition } ;
33use crate :: Arena ;
44
5- use rustc_ast:: node_id:: NodeMap ;
65use rustc_ast:: ptr:: P ;
76use rustc_ast:: visit:: { self , AssocCtxt , FnCtxt , FnKind , Visitor } ;
87use rustc_ast:: * ;
@@ -1351,8 +1350,11 @@ impl<'hir> LoweringContext<'_, 'hir> {
13511350 generics : & Generics ,
13521351 itctx : ImplTraitContext < ' _ , ' hir > ,
13531352 ) -> 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`.
13561358 for pred in & generics. where_clause . predicates {
13571359 if let WherePredicate :: BoundPredicate ( ref bound_pred) = * pred {
13581360 ' next_bound: for bound in & bound_pred. bounds {
@@ -1368,7 +1370,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
13681370 {
13691371 for param in & generics. params {
13701372 if def_id == self . resolver . local_def_id ( param. id ) . to_def_id ( ) {
1371- add_bounds. entry ( param. id ) . or_default ( ) . push ( bound. clone ( ) ) ;
13721373 continue ' next_bound;
13731374 }
13741375 }
@@ -1386,7 +1387,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
13861387 }
13871388
13881389 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 ( ) ,
13901391 where_clause : self . lower_where_clause ( & generics. where_clause ) ,
13911392 span : self . lower_span ( generics. span ) ,
13921393 }
@@ -1419,32 +1420,17 @@ impl<'hir> LoweringContext<'_, 'hir> {
14191420 ref bounded_ty,
14201421 ref bounds,
14211422 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) ,
14461432 } )
1447- }
1433+ } ) ,
14481434 WherePredicate :: RegionPredicate ( WhereRegionPredicate {
14491435 ref lifetime,
14501436 ref bounds,
0 commit comments