@@ -48,6 +48,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
48
48
use rustc_data_structures:: sorted_map:: SortedMap ;
49
49
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
50
50
use rustc_data_structures:: sync:: Lrc ;
51
+ use rustc_data_structures:: tagged_ptr:: TaggedRef ;
51
52
use rustc_errors:: { DiagArgFromDisplay , DiagCtxtHandle , StashKey } ;
52
53
use rustc_hir:: def:: { DefKind , LifetimeRes , Namespace , PartialRes , PerNS , Res } ;
53
54
use rustc_hir:: def_id:: { CRATE_DEF_ID , LOCAL_CRATE , LocalDefId } ;
@@ -1083,17 +1084,22 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1083
1084
match arg {
1084
1085
ast:: GenericArg :: Lifetime ( lt) => GenericArg :: Lifetime ( self . lower_lifetime ( lt) ) ,
1085
1086
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
+
1086
1096
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
- }
1093
1097
// We parse const arguments as path types as we cannot distinguish them during
1094
1098
// parsing. We try to resolve that ambiguity by attempting resolution in both the
1095
1099
// type and value namespaces. If we resolved the path in the value namespace, we
1096
1100
// transform it into a generic const argument.
1101
+ //
1102
+ // FIXME: Should we be handling `(PATH_TO_CONST)`?
1097
1103
TyKind :: Path ( None , path) => {
1098
1104
if let Some ( res) = self
1099
1105
. resolver
@@ -1110,15 +1116,17 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1110
1116
1111
1117
let ct =
1112
1118
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 ( ) ) ;
1114
1120
}
1115
1121
}
1116
1122
}
1117
1123
_ => { }
1118
1124
}
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 ( ) )
1120
1129
}
1121
- ast:: GenericArg :: Const ( ct) => GenericArg :: Const ( self . lower_anon_const_to_const_arg ( ct) ) ,
1122
1130
}
1123
1131
}
1124
1132
@@ -1158,7 +1166,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1158
1166
let lifetime_bound = this. elided_dyn_bound ( t. span ) ;
1159
1167
( bounds, lifetime_bound)
1160
1168
} ) ;
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
+ ) ;
1162
1173
return hir:: Ty { kind, span : self . lower_span ( t. span ) , hir_id : self . next_id ( ) } ;
1163
1174
}
1164
1175
@@ -1185,7 +1196,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1185
1196
1186
1197
fn lower_ty_direct ( & mut self , t : & Ty , itctx : ImplTraitContext ) -> hir:: Ty < ' hir > {
1187
1198
let kind = match & t. kind {
1188
- TyKind :: Infer => hir:: TyKind :: Infer ,
1199
+ TyKind :: Infer => hir:: TyKind :: Infer ( ( ) ) ,
1189
1200
TyKind :: Err ( guar) => hir:: TyKind :: Err ( * guar) ,
1190
1201
TyKind :: Slice ( ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
1191
1202
TyKind :: Ptr ( mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
@@ -1309,7 +1320,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1309
1320
lifetime_bound. unwrap_or_else ( || this. elided_dyn_bound ( t. span ) ) ;
1310
1321
( bounds, lifetime_bound)
1311
1322
} ) ;
1312
- hir:: TyKind :: TraitObject ( bounds, lifetime_bound, * kind)
1323
+ hir:: TyKind :: TraitObject ( bounds, TaggedRef :: new ( lifetime_bound, * kind) )
1313
1324
}
1314
1325
TyKind :: ImplTrait ( def_node_id, bounds) => {
1315
1326
let span = t. span ;
@@ -2041,7 +2052,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2041
2052
)
2042
2053
. stash ( c. value . span , StashKey :: UnderscoreForArrayLengths ) ;
2043
2054
}
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 ) , ( ) ) ;
2045
2056
self . arena . alloc ( hir:: ConstArg { hir_id : self . lower_node_id ( c. id ) , kind : ct_kind } )
2046
2057
}
2047
2058
_ => self . lower_anon_const_to_const_arg ( c) ,
@@ -2365,8 +2376,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
2365
2376
hir_id = self . next_id ( ) ;
2366
2377
hir:: TyKind :: TraitObject (
2367
2378
arena_vec ! [ self ; principal] ,
2368
- self . elided_dyn_bound ( span) ,
2369
- TraitObjectSyntax :: None ,
2379
+ TaggedRef :: new ( self . elided_dyn_bound ( span) , TraitObjectSyntax :: None ) ,
2370
2380
)
2371
2381
}
2372
2382
_ => hir:: TyKind :: Path ( hir:: QPath :: Resolved ( None , path) ) ,
0 commit comments