@@ -1242,13 +1242,17 @@ fn check_fn<'a, 'tcx>(
12421242 let mut fcx = FnCtxt :: new ( inherited, param_env, body. value . hir_id ) ;
12431243 * fcx. ps . borrow_mut ( ) = UnsafetyState :: function ( fn_sig. unsafety , fn_id) ;
12441244
1245+ let tcx = fcx. tcx ;
1246+ let sess = tcx. sess ;
1247+ let hir = tcx. hir ( ) ;
1248+
12451249 let declared_ret_ty = fn_sig. output ( ) ;
12461250 fcx. require_type_is_sized ( declared_ret_ty, decl. output . span ( ) , traits:: SizedReturnType ) ;
12471251 let revealed_ret_ty =
12481252 fcx. instantiate_opaque_types_from_value ( fn_id, & declared_ret_ty, decl. output . span ( ) ) ;
12491253 debug ! ( "check_fn: declared_ret_ty: {}, revealed_ret_ty: {}" , declared_ret_ty, revealed_ret_ty) ;
12501254 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 (
12521256 fn_sig. inputs ( ) . iter ( ) . cloned ( ) ,
12531257 revealed_ret_ty,
12541258 fn_sig. c_variadic ,
@@ -1258,7 +1262,7 @@ fn check_fn<'a, 'tcx>(
12581262
12591263 let span = body. value . span ;
12601264
1261- fn_maybe_err ( fcx . tcx , span, fn_sig. abi ) ;
1265+ fn_maybe_err ( tcx, span, fn_sig. abi ) ;
12621266
12631267 if body. generator_kind . is_some ( ) && can_be_generator. is_some ( ) {
12641268 let yield_ty = fcx
@@ -1267,23 +1271,23 @@ fn check_fn<'a, 'tcx>(
12671271 fcx. yield_ty = Some ( yield_ty) ;
12681272 }
12691273
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 ( ) ;
12721276 GatherLocalsVisitor { fcx : & fcx, parent_id : outer_hir_id } . visit_body ( body) ;
12731277
12741278 // C-variadic fns also have a `VaList` input that's not listed in `fn_sig`
12751279 // (as it's created inside the body itself, not passed in from outside).
12761280 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 (
12781282 lang_items:: VaListTypeLangItem ,
12791283 Some ( body. params . last ( ) . unwrap ( ) . span ) ,
12801284 ) ;
1281- let region = fcx . tcx . mk_region ( ty:: ReScope ( region:: Scope {
1285+ let region = tcx. mk_region ( ty:: ReScope ( region:: Scope {
12821286 id : body. value . hir_id . local_id ,
12831287 data : region:: ScopeData :: CallSite ,
12841288 } ) ) ;
12851289
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 ( ) ] ) )
12871291 } else {
12881292 None
12891293 } ;
@@ -1297,7 +1301,7 @@ fn check_fn<'a, 'tcx>(
12971301 // The check for a non-trivial pattern is a hack to avoid duplicate warnings
12981302 // for simple cases like `fn foo(x: Trait)`,
12991303 // 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 {
13011305 fcx. require_type_is_sized ( param_ty, decl. output . span ( ) , traits:: SizedArgumentType ) ;
13021306 }
13031307
@@ -1358,11 +1362,11 @@ fn check_fn<'a, 'tcx>(
13581362 fcx. demand_suptype ( span, revealed_ret_ty, actual_return_ty) ;
13591363
13601364 // 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 ( ) ;
13641368 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, & [ ] ) ;
13661370 let trait_ref = ty:: TraitRef :: new ( term_id, substs) ;
13671371 let return_ty_span = decl. output . span ( ) ;
13681372 let cause = traits:: ObligationCause :: new (
@@ -1381,15 +1385,15 @@ fn check_fn<'a, 'tcx>(
13811385 }
13821386
13831387 // 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 ( ) {
13871391 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 `!`" ) ;
13891393 }
13901394
13911395 let inputs = fn_sig. inputs ( ) ;
1392- let span = fcx . tcx . hir ( ) . span ( fn_id) ;
1396+ let span = hir. span ( fn_id) ;
13931397 if inputs. len ( ) == 1 {
13941398 let arg_is_panic_info = match inputs[ 0 ] . kind {
13951399 ty:: Ref ( region, ty, mutbl) => match ty. kind {
@@ -1404,52 +1408,50 @@ fn check_fn<'a, 'tcx>(
14041408 } ;
14051409
14061410 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`" ) ;
14101412 }
14111413
1412- if let Node :: Item ( item) = fcx . tcx . hir ( ) . get ( fn_id) {
1414+ if let Node :: Item ( item) = hir. get ( fn_id) {
14131415 if let ItemKind :: Fn ( _, ref generics, _) = item. kind {
14141416 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" ) ;
14161418 }
14171419 }
14181420 }
14191421 } 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" ) ;
14221424 }
14231425 } 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`" ) ;
14251427 }
14261428 }
14271429 }
14281430
14291431 // 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 ( ) {
14331435 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 `!`" ) ;
14351437 }
14361438
14371439 let inputs = fn_sig. inputs ( ) ;
1438- let span = fcx . tcx . hir ( ) . span ( fn_id) ;
1440+ let span = hir. span ( fn_id) ;
14391441 if inputs. len ( ) == 1 {
14401442 let arg_is_alloc_layout = match inputs[ 0 ] . kind {
14411443 ty:: Adt ( ref adt, _) => adt. did == alloc_layout_did,
14421444 _ => false ,
14431445 } ;
14441446
14451447 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`" ) ;
14471449 }
14481450
1449- if let Node :: Item ( item) = fcx . tcx . hir ( ) . get ( fn_id) {
1451+ if let Node :: Item ( item) = hir. get ( fn_id) {
14501452 if let ItemKind :: Fn ( _, ref generics, _) = item. kind {
14511453 if !generics. params . is_empty ( ) {
1452- fcx . tcx . sess . span_err (
1454+ sess. span_err (
14531455 span,
14541456 "`#[alloc_error_handler]` function should have no type \
14551457 parameters",
@@ -1458,11 +1460,11 @@ fn check_fn<'a, 'tcx>(
14581460 }
14591461 }
14601462 } 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" ) ;
14631465 }
14641466 } 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`" ) ;
14661468 }
14671469 }
14681470 }
0 commit comments