@@ -48,6 +48,7 @@ use rustc_data_structures::fingerprint::Fingerprint;
48
48
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
49
49
use rustc_data_structures:: sorted_map:: SortedMap ;
50
50
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
51
+ use rustc_data_structures:: stack:: ensure_sufficient_stack;
51
52
use rustc_data_structures:: sync:: Lrc ;
52
53
use rustc_errors:: struct_span_err;
53
54
use rustc_hir as hir;
@@ -1166,13 +1167,14 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1166
1167
}
1167
1168
1168
1169
fn lower_ty_direct ( & mut self , t : & Ty , mut itctx : ImplTraitContext < ' _ , ' hir > ) -> hir:: Ty < ' hir > {
1169
- let kind = match t. kind {
1170
- TyKind :: Infer => hir:: TyKind :: Infer ,
1171
- TyKind :: Err => hir:: TyKind :: Err ,
1172
- TyKind :: Slice ( ref ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
1173
- TyKind :: Ptr ( ref mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
1174
- TyKind :: Rptr ( ref region, ref mt) => {
1175
- let region = region. unwrap_or_else ( || {
1170
+ ensure_sufficient_stack ( || {
1171
+ let kind = match t. kind {
1172
+ TyKind :: Infer => hir:: TyKind :: Infer ,
1173
+ TyKind :: Err => hir:: TyKind :: Err ,
1174
+ TyKind :: Slice ( ref ty) => hir:: TyKind :: Slice ( self . lower_ty ( ty, itctx) ) ,
1175
+ TyKind :: Ptr ( ref mt) => hir:: TyKind :: Ptr ( self . lower_mt ( mt, itctx) ) ,
1176
+ TyKind :: Rptr ( ref region, ref mt) => {
1177
+ let region = region. unwrap_or_else ( || {
1176
1178
let Some ( LifetimeRes :: ElidedAnchor { start, end } ) = self . resolver . get_lifetime_res ( t. id ) else {
1177
1179
panic ! ( )
1178
1180
} ;
@@ -1183,56 +1185,53 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1183
1185
id : start,
1184
1186
}
1185
1187
} ) ;
1186
- let lifetime = self . lower_lifetime ( & region) ;
1187
- hir:: TyKind :: Rptr ( lifetime, self . lower_mt ( mt, itctx) )
1188
- }
1189
- TyKind :: BareFn ( ref f) => self . with_lifetime_binder ( t. id , |this| {
1190
- hir:: TyKind :: BareFn ( this. arena . alloc ( hir:: BareFnTy {
1191
- generic_params : this. lower_generic_params (
1192
- & f. generic_params ,
1193
- ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
1194
- ) ,
1195
- unsafety : this. lower_unsafety ( f. unsafety ) ,
1196
- abi : this. lower_extern ( f. ext ) ,
1197
- decl : this. lower_fn_decl ( & f. decl , None , FnDeclKind :: Pointer , None ) ,
1198
- param_names : this. lower_fn_params_to_names ( & f. decl ) ,
1199
- } ) )
1200
- } ) ,
1201
- TyKind :: Never => hir:: TyKind :: Never ,
1202
- TyKind :: Tup ( ref tys) => {
1203
- hir:: TyKind :: Tup ( self . arena . alloc_from_iter (
1188
+ let lifetime = self . lower_lifetime ( & region) ;
1189
+ hir:: TyKind :: Rptr ( lifetime, self . lower_mt ( mt, itctx) )
1190
+ }
1191
+ TyKind :: BareFn ( ref f) => self . with_lifetime_binder ( t. id , |this| {
1192
+ hir:: TyKind :: BareFn ( this. arena . alloc ( hir:: BareFnTy {
1193
+ generic_params : this. lower_generic_params (
1194
+ & f. generic_params ,
1195
+ ImplTraitContext :: Disallowed ( ImplTraitPosition :: Generic ) ,
1196
+ ) ,
1197
+ unsafety : this. lower_unsafety ( f. unsafety ) ,
1198
+ abi : this. lower_extern ( f. ext ) ,
1199
+ decl : this. lower_fn_decl ( & f. decl , None , FnDeclKind :: Pointer , None ) ,
1200
+ param_names : this. lower_fn_params_to_names ( & f. decl ) ,
1201
+ } ) )
1202
+ } ) ,
1203
+ TyKind :: Never => hir:: TyKind :: Never ,
1204
+ TyKind :: Tup ( ref tys) => hir:: TyKind :: Tup ( self . arena . alloc_from_iter (
1204
1205
tys. iter ( ) . map ( |ty| self . lower_ty_direct ( ty, itctx. reborrow ( ) ) ) ,
1205
- ) )
1206
- }
1207
- TyKind :: Paren ( ref ty) => {
1208
- return self . lower_ty_direct ( ty, itctx) ;
1209
- }
1210
- TyKind :: Path ( ref qself, ref path) => {
1211
- return self . lower_path_ty ( t, qself, path, ParamMode :: Explicit , itctx) ;
1212
- }
1213
- TyKind :: ImplicitSelf => {
1214
- let res = self . expect_full_res ( t. id ) ;
1215
- let res = self . lower_res ( res) ;
1216
- hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1217
- None ,
1218
- self . arena . alloc ( hir:: Path {
1219
- res,
1220
- segments : arena_vec ! [ self ; hir:: PathSegment :: from_ident(
1221
- Ident :: with_dummy_span( kw:: SelfUpper )
1222
- ) ] ,
1223
- span : self . lower_span ( t. span ) ,
1224
- } ) ,
1225
- ) )
1226
- }
1227
- TyKind :: Array ( ref ty, ref length) => {
1228
- hir:: TyKind :: Array ( self . lower_ty ( ty, itctx) , self . lower_array_length ( length) )
1229
- }
1230
- TyKind :: Typeof ( ref expr) => hir:: TyKind :: Typeof ( self . lower_anon_const ( expr) ) ,
1231
- TyKind :: TraitObject ( ref bounds, kind) => {
1232
- let mut lifetime_bound = None ;
1233
- let ( bounds, lifetime_bound) = self . with_dyn_type_scope ( true , |this| {
1234
- let bounds =
1235
- this. arena . alloc_from_iter ( bounds. iter ( ) . filter_map (
1206
+ ) ) ,
1207
+ TyKind :: Paren ( ref ty) => {
1208
+ return self . lower_ty_direct ( ty, itctx) ;
1209
+ }
1210
+ TyKind :: Path ( ref qself, ref path) => {
1211
+ return self . lower_path_ty ( t, qself, path, ParamMode :: Explicit , itctx) ;
1212
+ }
1213
+ TyKind :: ImplicitSelf => {
1214
+ let res = self . expect_full_res ( t. id ) ;
1215
+ let res = self . lower_res ( res) ;
1216
+ hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1217
+ None ,
1218
+ self . arena . alloc ( hir:: Path {
1219
+ res,
1220
+ segments : arena_vec ! [ self ; hir:: PathSegment :: from_ident(
1221
+ Ident :: with_dummy_span( kw:: SelfUpper )
1222
+ ) ] ,
1223
+ span : self . lower_span ( t. span ) ,
1224
+ } ) ,
1225
+ ) )
1226
+ }
1227
+ TyKind :: Array ( ref ty, ref length) => {
1228
+ hir:: TyKind :: Array ( self . lower_ty ( ty, itctx) , self . lower_array_length ( length) )
1229
+ }
1230
+ TyKind :: Typeof ( ref expr) => hir:: TyKind :: Typeof ( self . lower_anon_const ( expr) ) ,
1231
+ TyKind :: TraitObject ( ref bounds, kind) => {
1232
+ let mut lifetime_bound = None ;
1233
+ let ( bounds, lifetime_bound) = self . with_dyn_type_scope ( true , |this| {
1234
+ let bounds = this. arena . alloc_from_iter ( bounds. iter ( ) . filter_map (
1236
1235
|bound| match * bound {
1237
1236
GenericBound :: Trait (
1238
1237
ref ty,
@@ -1252,80 +1251,84 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
1252
1251
}
1253
1252
} ,
1254
1253
) ) ;
1255
- let lifetime_bound =
1256
- lifetime_bound. unwrap_or_else ( || this. elided_dyn_bound ( t. span ) ) ;
1257
- ( bounds, lifetime_bound)
1258
- } ) ;
1259
- hir:: TyKind :: TraitObject ( bounds, lifetime_bound, kind)
1260
- }
1261
- TyKind :: ImplTrait ( def_node_id, ref bounds) => {
1262
- let span = t. span ;
1263
- match itctx {
1264
- ImplTraitContext :: ReturnPositionOpaqueTy { origin } => self
1265
- . lower_opaque_impl_trait ( span, origin, def_node_id, |this| {
1266
- this. lower_param_bounds ( bounds, itctx)
1267
- } ) ,
1268
- ImplTraitContext :: TypeAliasesOpaqueTy => {
1269
- let nested_itctx = ImplTraitContext :: TypeAliasesOpaqueTy ;
1270
- self . lower_opaque_impl_trait (
1271
- span,
1272
- hir:: OpaqueTyOrigin :: TyAlias ,
1273
- def_node_id,
1274
- |this| this. lower_param_bounds ( bounds, nested_itctx) ,
1275
- )
1276
- }
1277
- ImplTraitContext :: Universal ( in_band_ty_params, parent_def_id) => {
1278
- // Add a definition for the in-band `Param`.
1279
- let def_id = self . resolver . local_def_id ( def_node_id) ;
1254
+ let lifetime_bound =
1255
+ lifetime_bound. unwrap_or_else ( || this. elided_dyn_bound ( t. span ) ) ;
1256
+ ( bounds, lifetime_bound)
1257
+ } ) ;
1258
+ hir:: TyKind :: TraitObject ( bounds, lifetime_bound, kind)
1259
+ }
1260
+ TyKind :: ImplTrait ( def_node_id, ref bounds) => {
1261
+ let span = t. span ;
1262
+ match itctx {
1263
+ ImplTraitContext :: ReturnPositionOpaqueTy { origin } => self
1264
+ . lower_opaque_impl_trait ( span, origin, def_node_id, |this| {
1265
+ this. lower_param_bounds ( bounds, itctx)
1266
+ } ) ,
1267
+ ImplTraitContext :: TypeAliasesOpaqueTy => {
1268
+ let nested_itctx = ImplTraitContext :: TypeAliasesOpaqueTy ;
1269
+ self . lower_opaque_impl_trait (
1270
+ span,
1271
+ hir:: OpaqueTyOrigin :: TyAlias ,
1272
+ def_node_id,
1273
+ |this| this. lower_param_bounds ( bounds, nested_itctx) ,
1274
+ )
1275
+ }
1276
+ ImplTraitContext :: Universal ( in_band_ty_params, parent_def_id) => {
1277
+ // Add a definition for the in-band `Param`.
1278
+ let def_id = self . resolver . local_def_id ( def_node_id) ;
1280
1279
1281
- let hir_bounds = self . lower_param_bounds (
1282
- bounds,
1283
- ImplTraitContext :: Universal ( in_band_ty_params, parent_def_id) ,
1284
- ) ;
1285
- // Set the name to `impl Bound1 + Bound2`.
1286
- let ident = Ident :: from_str_and_span ( & pprust:: ty_to_string ( t) , span) ;
1287
- in_band_ty_params. push ( hir:: GenericParam {
1288
- hir_id : self . lower_node_id ( def_node_id) ,
1289
- name : ParamName :: Plain ( self . lower_ident ( ident) ) ,
1290
- pure_wrt_drop : false ,
1291
- bounds : hir_bounds,
1292
- span : self . lower_span ( span) ,
1293
- kind : hir:: GenericParamKind :: Type { default : None , synthetic : true } ,
1294
- } ) ;
1280
+ let hir_bounds = self . lower_param_bounds (
1281
+ bounds,
1282
+ ImplTraitContext :: Universal ( in_band_ty_params, parent_def_id) ,
1283
+ ) ;
1284
+ // Set the name to `impl Bound1 + Bound2`.
1285
+ let ident = Ident :: from_str_and_span ( & pprust:: ty_to_string ( t) , span) ;
1286
+ in_band_ty_params. push ( hir:: GenericParam {
1287
+ hir_id : self . lower_node_id ( def_node_id) ,
1288
+ name : ParamName :: Plain ( self . lower_ident ( ident) ) ,
1289
+ pure_wrt_drop : false ,
1290
+ bounds : hir_bounds,
1291
+ span : self . lower_span ( span) ,
1292
+ kind : hir:: GenericParamKind :: Type {
1293
+ default : None ,
1294
+ synthetic : true ,
1295
+ } ,
1296
+ } ) ;
1295
1297
1296
- hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1298
+ hir:: TyKind :: Path ( hir:: QPath :: Resolved (
1297
1299
None ,
1298
1300
self . arena . alloc ( hir:: Path {
1299
1301
span : self . lower_span ( span) ,
1300
1302
res : Res :: Def ( DefKind :: TyParam , def_id. to_def_id ( ) ) ,
1301
1303
segments : arena_vec ! [ self ; hir:: PathSegment :: from_ident( self . lower_ident( ident) ) ] ,
1302
1304
} ) ,
1303
1305
) )
1304
- }
1305
- ImplTraitContext :: Disallowed ( position) => {
1306
- let mut err = struct_span_err ! (
1307
- self . sess,
1308
- t. span,
1309
- E0562 ,
1310
- "`impl Trait` only allowed in function and inherent method return types, not in {}" ,
1311
- position
1312
- ) ;
1313
- err. emit ( ) ;
1314
- hir:: TyKind :: Err
1306
+ }
1307
+ ImplTraitContext :: Disallowed ( position) => {
1308
+ let mut err = struct_span_err ! (
1309
+ self . sess,
1310
+ t. span,
1311
+ E0562 ,
1312
+ "`impl Trait` only allowed in function and inherent method return types, not in {}" ,
1313
+ position
1314
+ ) ;
1315
+ err. emit ( ) ;
1316
+ hir:: TyKind :: Err
1317
+ }
1315
1318
}
1316
1319
}
1317
- }
1318
- TyKind :: MacCall ( _) => panic ! ( "`TyKind::MacCall` should have been expanded by now" ) ,
1319
- TyKind :: CVarArgs => {
1320
- self . sess . delay_span_bug (
1321
- t. span ,
1322
- "`TyKind::CVarArgs` should have been handled elsewhere" ,
1323
- ) ;
1324
- hir:: TyKind :: Err
1325
- }
1326
- } ;
1320
+ TyKind :: MacCall ( _) => panic ! ( "`TyKind::MacCall` should have been expanded by now" ) ,
1321
+ TyKind :: CVarArgs => {
1322
+ self . sess . delay_span_bug (
1323
+ t. span ,
1324
+ "`TyKind::CVarArgs` should have been handled elsewhere" ,
1325
+ ) ;
1326
+ hir:: TyKind :: Err
1327
+ }
1328
+ } ;
1327
1329
1328
- hir:: Ty { kind, span : self . lower_span ( t. span ) , hir_id : self . lower_node_id ( t. id ) }
1330
+ hir:: Ty { kind, span : self . lower_span ( t. span ) , hir_id : self . lower_node_id ( t. id ) }
1331
+ } )
1329
1332
}
1330
1333
1331
1334
#[ tracing:: instrument( level = "debug" , skip( self , lower_bounds) ) ]
0 commit comments