@@ -313,9 +313,8 @@ impl<'tcx> ResolverAstLowering<'tcx> {
313313/// Relaxed bounds should only be allowed in places where we later
314314/// (namely during HIR ty lowering) perform *sized elaboration*.
315315#[ derive( Clone , Copy , Debug ) ]
316- enum RelaxedBoundPolicy < ' a > {
316+ enum RelaxedBoundPolicy {
317317 Allowed ,
318- AllowedIfOnTyParam ( NodeId , & ' a [ ast:: GenericParam ] ) ,
319318 Forbidden ( RelaxedBoundForbiddenReason ) ,
320319}
321320
@@ -325,7 +324,9 @@ enum RelaxedBoundForbiddenReason {
325324 SuperTrait ,
326325 TraitAlias ,
327326 AssocTyBounds ,
328- LateBoundVarsInScope ,
327+ /// We do not allow where bounds doing relaxed bounds,
328+ /// except if it's for generic parameters of the current item.
329+ WhereBound ,
329330}
330331
331332/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
@@ -1950,7 +1951,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19501951 fn lower_param_bound (
19511952 & mut self ,
19521953 tpb : & GenericBound ,
1953- rbp : RelaxedBoundPolicy < ' _ > ,
1954+ rbp : RelaxedBoundPolicy ,
19541955 itctx : ImplTraitContext ,
19551956 ) -> hir:: GenericBound < ' hir > {
19561957 match tpb {
@@ -2188,7 +2189,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
21882189 fn lower_poly_trait_ref (
21892190 & mut self ,
21902191 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens : _ } : & PolyTraitRef ,
2191- rbp : RelaxedBoundPolicy < ' _ > ,
2192+ rbp : RelaxedBoundPolicy ,
21922193 itctx : ImplTraitContext ,
21932194 ) -> hir:: PolyTraitRef < ' hir > {
21942195 let bound_generic_params =
@@ -2212,7 +2213,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
22122213 & self ,
22132214 trait_ref : hir:: TraitRef < ' _ > ,
22142215 span : Span ,
2215- rbp : RelaxedBoundPolicy < ' _ > ,
2216+ rbp : RelaxedBoundPolicy ,
22162217 ) {
22172218 // Even though feature `more_maybe_bounds` enables the user to relax all default bounds
22182219 // other than `Sized` in a lot more positions (thereby bypassing the given policy), we don't
@@ -2225,14 +2226,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
22252226
22262227 match rbp {
22272228 RelaxedBoundPolicy :: Allowed => return ,
2228- RelaxedBoundPolicy :: AllowedIfOnTyParam ( id, params) => {
2229- if let Some ( res) = self . get_partial_res ( id) . and_then ( |r| r. full_res ( ) )
2230- && let Res :: Def ( DefKind :: TyParam , def_id) = res
2231- && params. iter ( ) . any ( |p| def_id == self . local_def_id ( p. id ) . to_def_id ( ) )
2232- {
2233- return ;
2234- }
2235- }
22362229 RelaxedBoundPolicy :: Forbidden ( reason) => {
22372230 let gate = |context, subject| {
22382231 let extended = self . tcx . features ( ) . more_maybe_bounds ( ) ;
@@ -2272,7 +2265,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
22722265 return ;
22732266 }
22742267 RelaxedBoundForbiddenReason :: AssocTyBounds
2275- | RelaxedBoundForbiddenReason :: LateBoundVarsInScope => { }
2268+ | RelaxedBoundForbiddenReason :: WhereBound => { }
22762269 } ;
22772270 }
22782271 }
@@ -2294,7 +2287,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
22942287 fn lower_param_bounds (
22952288 & mut self ,
22962289 bounds : & [ GenericBound ] ,
2297- rbp : RelaxedBoundPolicy < ' _ > ,
2290+ rbp : RelaxedBoundPolicy ,
22982291 itctx : ImplTraitContext ,
22992292 ) -> hir:: GenericBounds < ' hir > {
23002293 self . arena . alloc_from_iter ( self . lower_param_bounds_mut ( bounds, rbp, itctx) )
@@ -2303,7 +2296,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
23032296 fn lower_param_bounds_mut (
23042297 & mut self ,
23052298 bounds : & [ GenericBound ] ,
2306- rbp : RelaxedBoundPolicy < ' _ > ,
2299+ rbp : RelaxedBoundPolicy ,
23072300 itctx : ImplTraitContext ,
23082301 ) -> impl Iterator < Item = hir:: GenericBound < ' hir > > {
23092302 bounds. iter ( ) . map ( move |bound| self . lower_param_bound ( bound, rbp, itctx) )
0 commit comments