@@ -1242,13 +1242,17 @@ fn check_fn<'a, 'tcx>(
1242
1242
let mut fcx = FnCtxt :: new ( inherited, param_env, body. value . hir_id ) ;
1243
1243
* fcx. ps . borrow_mut ( ) = UnsafetyState :: function ( fn_sig. unsafety , fn_id) ;
1244
1244
1245
+ let tcx = fcx. tcx ;
1246
+ let sess = tcx. sess ;
1247
+ let hir = tcx. hir ( ) ;
1248
+
1245
1249
let declared_ret_ty = fn_sig. output ( ) ;
1246
1250
fcx. require_type_is_sized ( declared_ret_ty, decl. output . span ( ) , traits:: SizedReturnType ) ;
1247
1251
let revealed_ret_ty =
1248
1252
fcx. instantiate_opaque_types_from_value ( fn_id, & declared_ret_ty, decl. output . span ( ) ) ;
1249
1253
debug ! ( "check_fn: declared_ret_ty: {}, revealed_ret_ty: {}" , declared_ret_ty, revealed_ret_ty) ;
1250
1254
fcx. ret_coercion = Some ( RefCell :: new ( CoerceMany :: new ( revealed_ret_ty) ) ) ;
1251
- fn_sig = fcx . tcx . mk_fn_sig (
1255
+ fn_sig = tcx. mk_fn_sig (
1252
1256
fn_sig. inputs ( ) . iter ( ) . cloned ( ) ,
1253
1257
revealed_ret_ty,
1254
1258
fn_sig. c_variadic ,
@@ -1258,7 +1262,7 @@ fn check_fn<'a, 'tcx>(
1258
1262
1259
1263
let span = body. value . span ;
1260
1264
1261
- fn_maybe_err ( fcx . tcx , span, fn_sig. abi ) ;
1265
+ fn_maybe_err ( tcx, span, fn_sig. abi ) ;
1262
1266
1263
1267
if body. generator_kind . is_some ( ) && can_be_generator. is_some ( ) {
1264
1268
let yield_ty = fcx
@@ -1267,23 +1271,23 @@ fn check_fn<'a, 'tcx>(
1267
1271
fcx. yield_ty = Some ( yield_ty) ;
1268
1272
}
1269
1273
1270
- let outer_def_id = fcx . tcx . closure_base_def_id ( fcx . tcx . hir ( ) . local_def_id ( fn_id) ) ;
1271
- let outer_hir_id = fcx . tcx . hir ( ) . as_local_hir_id ( outer_def_id) . unwrap ( ) ;
1274
+ let outer_def_id = tcx. closure_base_def_id ( hir. local_def_id ( fn_id) ) ;
1275
+ let outer_hir_id = hir. as_local_hir_id ( outer_def_id) . unwrap ( ) ;
1272
1276
GatherLocalsVisitor { fcx : & fcx, parent_id : outer_hir_id } . visit_body ( body) ;
1273
1277
1274
1278
// C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
1275
1279
// (as it's created inside the body itself, not passed in from outside).
1276
1280
let maybe_va_list = if fn_sig. c_variadic {
1277
- let va_list_did = fcx . tcx . require_lang_item (
1281
+ let va_list_did = tcx. require_lang_item (
1278
1282
lang_items:: VaListTypeLangItem ,
1279
1283
Some ( body. params . last ( ) . unwrap ( ) . span ) ,
1280
1284
) ;
1281
- let region = fcx . tcx . mk_region ( ty:: ReScope ( region:: Scope {
1285
+ let region = tcx. mk_region ( ty:: ReScope ( region:: Scope {
1282
1286
id : body. value . hir_id . local_id ,
1283
1287
data : region:: ScopeData :: CallSite ,
1284
1288
} ) ) ;
1285
1289
1286
- Some ( fcx . tcx . type_of ( va_list_did) . subst ( fcx . tcx , & [ region. into ( ) ] ) )
1290
+ Some ( tcx. type_of ( va_list_did) . subst ( tcx, & [ region. into ( ) ] ) )
1287
1291
} else {
1288
1292
None
1289
1293
} ;
@@ -1297,7 +1301,7 @@ fn check_fn<'a, 'tcx>(
1297
1301
// The check for a non-trivial pattern is a hack to avoid duplicate warnings
1298
1302
// for simple cases like `fn foo(x: Trait)`,
1299
1303
// where we would error once on the parameter as a whole, and once on the binding `x`.
1300
- if param. pat . simple_ident ( ) . is_none ( ) && !fcx . tcx . features ( ) . unsized_locals {
1304
+ if param. pat . simple_ident ( ) . is_none ( ) && !tcx. features ( ) . unsized_locals {
1301
1305
fcx. require_type_is_sized ( param_ty, decl. output . span ( ) , traits:: SizedArgumentType ) ;
1302
1306
}
1303
1307
@@ -1358,11 +1362,11 @@ fn check_fn<'a, 'tcx>(
1358
1362
fcx. demand_suptype ( span, revealed_ret_ty, actual_return_ty) ;
1359
1363
1360
1364
// Check that the main return type implements the termination trait.
1361
- if let Some ( term_id) = fcx . tcx . lang_items ( ) . termination ( ) {
1362
- if let Some ( ( def_id, EntryFnType :: Main ) ) = fcx . tcx . entry_fn ( LOCAL_CRATE ) {
1363
- let main_id = fcx . tcx . hir ( ) . as_local_hir_id ( def_id) . unwrap ( ) ;
1365
+ if let Some ( term_id) = tcx. lang_items ( ) . termination ( ) {
1366
+ if let Some ( ( def_id, EntryFnType :: Main ) ) = tcx. entry_fn ( LOCAL_CRATE ) {
1367
+ let main_id = hir. as_local_hir_id ( def_id) . unwrap ( ) ;
1364
1368
if main_id == fn_id {
1365
- let substs = fcx . tcx . mk_substs_trait ( declared_ret_ty, & [ ] ) ;
1369
+ let substs = tcx. mk_substs_trait ( declared_ret_ty, & [ ] ) ;
1366
1370
let trait_ref = ty:: TraitRef :: new ( term_id, substs) ;
1367
1371
let return_ty_span = decl. output . span ( ) ;
1368
1372
let cause = traits:: ObligationCause :: new (
@@ -1381,15 +1385,15 @@ fn check_fn<'a, 'tcx>(
1381
1385
}
1382
1386
1383
1387
// Check that a function marked as `#[panic_handler]` has signature `fn(&PanicInfo) -> !`
1384
- if let Some ( panic_impl_did) = fcx . tcx . lang_items ( ) . panic_impl ( ) {
1385
- if panic_impl_did == fcx . tcx . hir ( ) . local_def_id ( fn_id) {
1386
- if let Some ( panic_info_did) = fcx . tcx . lang_items ( ) . panic_info ( ) {
1388
+ if let Some ( panic_impl_did) = tcx. lang_items ( ) . panic_impl ( ) {
1389
+ if panic_impl_did == hir. local_def_id ( fn_id) {
1390
+ if let Some ( panic_info_did) = tcx. lang_items ( ) . panic_info ( ) {
1387
1391
if declared_ret_ty. kind != ty:: Never {
1388
- fcx . tcx . sess . span_err ( decl. output . span ( ) , "return type should be `!`" ) ;
1392
+ sess. span_err ( decl. output . span ( ) , "return type should be `!`" ) ;
1389
1393
}
1390
1394
1391
1395
let inputs = fn_sig. inputs ( ) ;
1392
- let span = fcx . tcx . hir ( ) . span ( fn_id) ;
1396
+ let span = hir. span ( fn_id) ;
1393
1397
if inputs. len ( ) == 1 {
1394
1398
let arg_is_panic_info = match inputs[ 0 ] . kind {
1395
1399
ty:: Ref ( region, ty, mutbl) => match ty. kind {
@@ -1404,52 +1408,50 @@ fn check_fn<'a, 'tcx>(
1404
1408
} ;
1405
1409
1406
1410
if !arg_is_panic_info {
1407
- fcx. tcx
1408
- . sess
1409
- . span_err ( decl. inputs [ 0 ] . span , "argument should be `&PanicInfo`" ) ;
1411
+ sess. span_err ( decl. inputs [ 0 ] . span , "argument should be `&PanicInfo`" ) ;
1410
1412
}
1411
1413
1412
- if let Node :: Item ( item) = fcx . tcx . hir ( ) . get ( fn_id) {
1414
+ if let Node :: Item ( item) = hir. get ( fn_id) {
1413
1415
if let ItemKind :: Fn ( _, ref generics, _) = item. kind {
1414
1416
if !generics. params . is_empty ( ) {
1415
- fcx . tcx . sess . span_err ( span, "should have no type parameters" ) ;
1417
+ sess. span_err ( span, "should have no type parameters" ) ;
1416
1418
}
1417
1419
}
1418
1420
}
1419
1421
} else {
1420
- let span = fcx . tcx . sess . source_map ( ) . def_span ( span) ;
1421
- fcx . tcx . sess . span_err ( span, "function should have one argument" ) ;
1422
+ let span = sess. source_map ( ) . def_span ( span) ;
1423
+ sess. span_err ( span, "function should have one argument" ) ;
1422
1424
}
1423
1425
} else {
1424
- fcx . tcx . sess . err ( "language item required, but not found: `panic_info`" ) ;
1426
+ sess. err ( "language item required, but not found: `panic_info`" ) ;
1425
1427
}
1426
1428
}
1427
1429
}
1428
1430
1429
1431
// Check that a function marked as `#[alloc_error_handler]` has signature `fn(Layout) -> !`
1430
- if let Some ( alloc_error_handler_did) = fcx . tcx . lang_items ( ) . oom ( ) {
1431
- if alloc_error_handler_did == fcx . tcx . hir ( ) . local_def_id ( fn_id) {
1432
- if let Some ( alloc_layout_did) = fcx . tcx . lang_items ( ) . alloc_layout ( ) {
1432
+ if let Some ( alloc_error_handler_did) = tcx. lang_items ( ) . oom ( ) {
1433
+ if alloc_error_handler_did == hir. local_def_id ( fn_id) {
1434
+ if let Some ( alloc_layout_did) = tcx. lang_items ( ) . alloc_layout ( ) {
1433
1435
if declared_ret_ty. kind != ty:: Never {
1434
- fcx . tcx . sess . span_err ( decl. output . span ( ) , "return type should be `!`" ) ;
1436
+ sess. span_err ( decl. output . span ( ) , "return type should be `!`" ) ;
1435
1437
}
1436
1438
1437
1439
let inputs = fn_sig. inputs ( ) ;
1438
- let span = fcx . tcx . hir ( ) . span ( fn_id) ;
1440
+ let span = hir. span ( fn_id) ;
1439
1441
if inputs. len ( ) == 1 {
1440
1442
let arg_is_alloc_layout = match inputs[ 0 ] . kind {
1441
1443
ty:: Adt ( ref adt, _) => adt. did == alloc_layout_did,
1442
1444
_ => false ,
1443
1445
} ;
1444
1446
1445
1447
if !arg_is_alloc_layout {
1446
- fcx . tcx . sess . span_err ( decl. inputs [ 0 ] . span , "argument should be `Layout`" ) ;
1448
+ sess. span_err ( decl. inputs [ 0 ] . span , "argument should be `Layout`" ) ;
1447
1449
}
1448
1450
1449
- if let Node :: Item ( item) = fcx . tcx . hir ( ) . get ( fn_id) {
1451
+ if let Node :: Item ( item) = hir. get ( fn_id) {
1450
1452
if let ItemKind :: Fn ( _, ref generics, _) = item. kind {
1451
1453
if !generics. params . is_empty ( ) {
1452
- fcx . tcx . sess . span_err (
1454
+ sess. span_err (
1453
1455
span,
1454
1456
"`#[alloc_error_handler]` function should have no type \
1455
1457
parameters",
@@ -1458,11 +1460,11 @@ fn check_fn<'a, 'tcx>(
1458
1460
}
1459
1461
}
1460
1462
} else {
1461
- let span = fcx . tcx . sess . source_map ( ) . def_span ( span) ;
1462
- fcx . tcx . sess . span_err ( span, "function should have one argument" ) ;
1463
+ let span = sess. source_map ( ) . def_span ( span) ;
1464
+ sess. span_err ( span, "function should have one argument" ) ;
1463
1465
}
1464
1466
} else {
1465
- fcx . tcx . sess . err ( "language item required, but not found: `alloc_layout`" ) ;
1467
+ sess. err ( "language item required, but not found: `alloc_layout`" ) ;
1466
1468
}
1467
1469
}
1468
1470
}
0 commit comments