@@ -1084,7 +1084,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10841084 AssocItemConstraintKind :: Equality { term } => {
10851085 let term = match term {
10861086 Term :: Ty ( ty) => self . lower_ty ( ty, itctx) . into ( ) ,
1087- Term :: Const ( c) => self . lower_anon_const_to_const_arg ( c) . into ( ) ,
1087+ Term :: Const ( c) => self . lower_anon_const_to_const_arg ( c, false ) . into ( ) ,
10881088 } ;
10891089 hir:: AssocItemConstraintKind :: Equality { term }
10901090 }
@@ -1210,9 +1210,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
12101210 }
12111211 GenericArg :: Type ( self . lower_ty ( ty, itctx) . try_as_ambig_ty ( ) . unwrap ( ) )
12121212 }
1213- ast:: GenericArg :: Const ( ct) => {
1214- GenericArg :: Const ( self . lower_anon_const_to_const_arg ( ct) . try_as_ambig_ct ( ) . unwrap ( ) )
1215- }
1213+ ast:: GenericArg :: Const ( ct) => GenericArg :: Const (
1214+ self . lower_anon_const_to_const_arg ( ct, false ) . try_as_ambig_ct ( ) . unwrap ( ) ,
1215+ ) ,
12161216 }
12171217 }
12181218
@@ -2024,7 +2024,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20242024 false
20252025 }
20262026 } )
2027- . map ( |def| self . lower_anon_const_to_const_arg ( def) ) ;
2027+ . map ( |def| self . lower_anon_const_to_const_arg ( def, false ) ) ;
20282028
20292029 (
20302030 hir:: ParamName :: Plain ( self . lower_ident ( param. ident ) ) ,
@@ -2236,7 +2236,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
22362236 let ct_kind = hir:: ConstArgKind :: Infer ( self . lower_span ( c. value . span ) , ( ) ) ;
22372237 self . arena . alloc ( hir:: ConstArg { hir_id : self . lower_node_id ( c. id ) , kind : ct_kind } )
22382238 }
2239- _ => self . lower_anon_const_to_const_arg ( c) ,
2239+ _ => self . lower_anon_const_to_const_arg ( c, false ) ,
22402240 }
22412241 }
22422242
@@ -2305,12 +2305,21 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23052305
23062306 /// See [`hir::ConstArg`] for when to use this function vs
23072307 /// [`Self::lower_anon_const_to_anon_const`].
2308- fn lower_anon_const_to_const_arg ( & mut self , anon : & AnonConst ) -> & ' hir hir:: ConstArg < ' hir > {
2309- self . arena . alloc ( self . lower_anon_const_to_const_arg_direct ( anon) )
2308+ fn lower_anon_const_to_const_arg (
2309+ & mut self ,
2310+ anon : & AnonConst ,
2311+ always_lower_to_anon_const : bool ,
2312+ ) -> & ' hir hir:: ConstArg < ' hir > {
2313+ self . arena
2314+ . alloc ( self . lower_anon_const_to_const_arg_direct ( anon, always_lower_to_anon_const) )
23102315 }
23112316
23122317 #[ instrument( level = "debug" , skip( self ) ) ]
2313- fn lower_anon_const_to_const_arg_direct ( & mut self , anon : & AnonConst ) -> hir:: ConstArg < ' hir > {
2318+ fn lower_anon_const_to_const_arg_direct (
2319+ & mut self ,
2320+ anon : & AnonConst ,
2321+ always_lower_to_anon_const : bool ,
2322+ ) -> hir:: ConstArg < ' hir > {
23142323 let tcx = self . tcx ;
23152324 // Unwrap a block, so that e.g. `{ P }` is recognised as a parameter. Const arguments
23162325 // currently have to be wrapped in curly brackets, so it's necessary to special-case.
@@ -2329,6 +2338,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23292338 && path. is_potential_trivial_const_arg ( tcx. features ( ) . min_generic_const_args ( ) )
23302339 && ( tcx. features ( ) . min_generic_const_args ( )
23312340 || matches ! ( maybe_res, Some ( Res :: Def ( DefKind :: ConstParam , _) ) ) )
2341+ && !always_lower_to_anon_const
23322342 {
23332343 let qpath = self . lower_qpath (
23342344 expr. id ,
0 commit comments