@@ -48,6 +48,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
4848use rustc_data_structures:: sorted_map:: SortedMap ;
4949use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
5050use rustc_data_structures:: sync:: Lrc ;
51+ use rustc_data_structures:: tagged_ptr:: TaggedRef ;
5152use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
5253use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
5354use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
@@ -1083,17 +1084,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
10831084 match arg {
10841085 ast:: GenericArg :: Lifetime ( lt) => GenericArg :: Lifetime ( self . lower_lifetime ( lt) ) ,
10851086 ast:: GenericArg :: Type ( ty) => {
1087+ // We cannot just match on `TyKind::Infer` as `(_)` is represented as
1088+ // `TyKind::Paren(TyKind::Infer)` and should also be lowered to `GenericArg::Infer`
1089+ if ty. is_maybe_parenthesised_infer ( ) {
1090+ return GenericArg :: Infer ( hir:: InferArg {
1091+ hir_id : self . lower_node_id ( ty. id ) ,
1092+ span : self . lower_span ( ty. span ) ,
1093+ } ) ;
1094+ }
1095+
10861096 match & ty. kind {
1087- TyKind :: Infer if self . tcx . features ( ) . generic_arg_infer ( ) => {
1088- return GenericArg :: Infer ( hir:: InferArg {
1089- hir_id : self . lower_node_id ( ty. id ) ,
1090- span : self . lower_span ( ty. span ) ,
1091- } ) ;
1092- }
10931097 // We parse const arguments as path types as we cannot distinguish them during
10941098 // parsing. We try to resolve that ambiguity by attempting resolution in both the
10951099 // type and value namespaces. If we resolved the path in the value namespace, we
10961100 // transform it into a generic const argument.
1101+ //
1102+ // FIXME: Should we be handling `(PATH_TO_CONST)`?
10971103 TyKind :: Path ( None , path) => {
10981104 if let Some ( res) = self
10991105 . resolver
@@ -1110,15 +1116,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11101116
11111117 let ct =
11121118 self . lower_const_path_to_const_arg ( path, res, ty. id , ty. span ) ;
1113- return GenericArg :: Const ( ct) ;
1119+ return GenericArg :: Const ( ct. try_as_ambig_ct ( ) . unwrap ( ) ) ;
11141120 }
11151121 }
11161122 }
11171123 _ => { }
11181124 }
1119- GenericArg :: Type ( self . lower_ty ( ty, itctx) )
1125+ GenericArg :: Type ( self . lower_ty ( ty, itctx) . try_as_ambig_ty ( ) . unwrap ( ) )
1126+ }
1127+ ast:: GenericArg :: Const ( ct) => {
1128+ GenericArg :: Const ( self . lower_anon_const_to_const_arg ( ct) . try_as_ambig_ct ( ) . unwrap ( ) )
11201129 }
1121- ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . lower_anon_const_to_const_arg ( ct) ) ,
11221130 }
11231131 }
11241132
@@ -1158,7 +1166,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11581166 let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
11591167 ( bounds, lifetime_bound)
11601168 } ) ;
1161- let kind = hir:: TyKind :: TraitObject ( bounds, lifetime_bound, TraitObjectSyntax :: None ) ;
1169+ let kind = hir:: TyKind :: TraitObject (
1170+ bounds,
1171+ TaggedRef :: new ( lifetime_bound, TraitObjectSyntax :: None ) ,
1172+ ) ;
11621173 return hir:: Ty { kind, span : self . lower_span ( t. span ) , hir_id : self . next_id ( ) } ;
11631174 }
11641175
@@ -1185,7 +1196,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
11851196
11861197 fn lower_ty_direct ( & mut self , t : & Ty , itctx : ImplTraitContext ) -> hir:: Ty < ' hir > {
11871198 let kind = match & t. kind {
1188- TyKind :: Infer => hir:: TyKind :: Infer ,
1199+ TyKind :: Infer => hir:: TyKind :: Infer ( ( ) ) ,
11891200 TyKind :: Err ( guar) => hir:: TyKind :: Err ( * guar) ,
11901201 TyKind :: Slice ( ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
11911202 TyKind :: Ptr ( mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
@@ -1309,7 +1320,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
13091320 lifetime_bound. unwrap_or_else ( || this. elided_dyn_bound ( t. span ) ) ;
13101321 ( bounds, lifetime_bound)
13111322 } ) ;
1312- hir:: TyKind :: TraitObject ( bounds, lifetime_bound, * kind)
1323+ hir:: TyKind :: TraitObject ( bounds, TaggedRef :: new ( lifetime_bound, * kind) )
13131324 }
13141325 TyKind :: ImplTrait ( def_node_id, bounds) => {
13151326 let span = t. span ;
@@ -2041,7 +2052,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
20412052 )
20422053 . stash ( c. value . span , StashKey :: UnderscoreForArrayLengths ) ;
20432054 }
2044- let ct_kind = hir:: ConstArgKind :: Infer ( self . lower_span ( c. value . span ) ) ;
2055+ let ct_kind = hir:: ConstArgKind :: Infer ( self . lower_span ( c. value . span ) , ( ) ) ;
20452056 self . arena . alloc ( hir:: ConstArg { hir_id : self . lower_node_id ( c. id ) , kind : ct_kind } )
20462057 }
20472058 _ => self . lower_anon_const_to_const_arg ( c) ,
@@ -2365,8 +2376,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
23652376 hir_id = self . next_id ( ) ;
23662377 hir:: TyKind :: TraitObject (
23672378 arena_vec ! [ self ; principal] ,
2368- self . elided_dyn_bound ( span) ,
2369- TraitObjectSyntax :: None ,
2379+ TaggedRef :: new ( self . elided_dyn_bound ( span) , TraitObjectSyntax :: None ) ,
23702380 )
23712381 }
23722382 _ => hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , path) ) ,
0 commit comments