@@ -320,9 +320,8 @@ impl<'tcx> ResolverAstLowering<'tcx> {
320320/// Relaxed bounds should only be allowed in places where we later
321321/// (namely during HIR ty lowering) perform *sized elaboration*.
322322#[ derive( Clone , Copy , Debug ) ]
323- enum RelaxedBoundPolicy < ' a > {
323+ enum RelaxedBoundPolicy {
324324 Allowed ,
325- AllowedIfOnTyParam ( NodeId , & ' a [ ast:: GenericParam ] ) ,
326325 Forbidden ( RelaxedBoundForbiddenReason ) ,
327326}
328327
@@ -332,7 +331,9 @@ enum RelaxedBoundForbiddenReason {
332331 SuperTrait ,
333332 TraitAlias ,
334333 AssocTyBounds ,
335- LateBoundVarsInScope ,
334+ /// We do not allow where bounds doing relaxed bounds,
335+ /// except if it's for generic parameters of the current item.
336+ WhereBound ,
336337}
337338
338339/// Context of `impl Trait` in code, which determines whether it is allowed in an HIR subtree,
@@ -1965,7 +1966,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
19651966 fn lower_param_bound (
19661967 & mut self ,
19671968 tpb : & GenericBound ,
1968- rbp : RelaxedBoundPolicy < ' _ > ,
1969+ rbp : RelaxedBoundPolicy ,
19691970 itctx : ImplTraitContext ,
19701971 ) -> hir:: GenericBound < ' hir > {
19711972 match tpb {
@@ -2203,7 +2204,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
22032204 fn lower_poly_trait_ref (
22042205 & mut self ,
22052206 PolyTraitRef { bound_generic_params, modifiers, trait_ref, span, parens : _ } : & PolyTraitRef ,
2206- rbp : RelaxedBoundPolicy < ' _ > ,
2207+ rbp : RelaxedBoundPolicy ,
22072208 itctx : ImplTraitContext ,
22082209 ) -> hir:: PolyTraitRef < ' hir > {
22092210 let bound_generic_params =
@@ -2227,7 +2228,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
22272228 & self ,
22282229 trait_ref : hir:: TraitRef < ' _ > ,
22292230 span : Span ,
2230- rbp : RelaxedBoundPolicy < ' _ > ,
2231+ rbp : RelaxedBoundPolicy ,
22312232 ) {
22322233 // Even though feature `more_maybe_bounds` enables the user to relax all default bounds
22332234 // other than `Sized` in a lot more positions (thereby bypassing the given policy), we don't
@@ -2240,14 +2241,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
22402241
22412242 match rbp {
22422243 RelaxedBoundPolicy :: Allowed => return ,
2243- RelaxedBoundPolicy :: AllowedIfOnTyParam ( id, params) => {
2244- if let Some ( res) = self . get_partial_res ( id) . and_then ( |r| r. full_res ( ) )
2245- && let Res :: Def ( DefKind :: TyParam , def_id) = res
2246- && params. iter ( ) . any ( |p| def_id == self . local_def_id ( p. id ) . to_def_id ( ) )
2247- {
2248- return ;
2249- }
2250- }
22512244 RelaxedBoundPolicy :: Forbidden ( reason) => {
22522245 let gate = |context, subject| {
22532246 let extended = self . tcx . features ( ) . more_maybe_bounds ( ) ;
@@ -2287,7 +2280,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
22872280 return ;
22882281 }
22892282 RelaxedBoundForbiddenReason :: AssocTyBounds
2290- | RelaxedBoundForbiddenReason :: LateBoundVarsInScope => { }
2283+ | RelaxedBoundForbiddenReason :: WhereBound => { }
22912284 } ;
22922285 }
22932286 }
@@ -2309,7 +2302,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
23092302 fn lower_param_bounds (
23102303 & mut self ,
23112304 bounds : & [ GenericBound ] ,
2312- rbp : RelaxedBoundPolicy < ' _ > ,
2305+ rbp : RelaxedBoundPolicy ,
23132306 itctx : ImplTraitContext ,
23142307 ) -> hir:: GenericBounds < ' hir > {
23152308 self . arena . alloc_from_iter ( self . lower_param_bounds_mut ( bounds, rbp, itctx) )
@@ -2318,7 +2311,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
23182311 fn lower_param_bounds_mut (
23192312 & mut self ,
23202313 bounds : & [ GenericBound ] ,
2321- rbp : RelaxedBoundPolicy < ' _ > ,
2314+ rbp : RelaxedBoundPolicy ,
23222315 itctx : ImplTraitContext ,
23232316 ) -> impl Iterator < Item = hir:: GenericBound < ' hir > > {
23242317 bounds. iter ( ) . map ( move |bound| self . lower_param_bound ( bound, rbp, itctx) )
0 commit comments