@@ -24,11 +24,9 @@ use rustc_errors::{
2424} ;
2525use rustc_hir as hir;
2626use rustc_hir:: def:: Namespace ;
27- use rustc_hir:: def_id:: DefId ;
27+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
2828use rustc_hir:: intravisit:: Visitor ;
29- use rustc_hir:: GenericParam ;
30- use rustc_hir:: Item ;
31- use rustc_hir:: Node ;
29+ use rustc_hir:: { GenericParam , Item , Node } ;
3230use rustc_infer:: infer:: error_reporting:: TypeErrCtxt ;
3331use rustc_infer:: infer:: { InferOk , TypeTrace } ;
3432use rustc_middle:: traits:: select:: OverflowError ;
@@ -129,7 +127,7 @@ pub trait TypeErrCtxtExt<'tcx> {
129127 fn report_fulfillment_errors (
130128 & self ,
131129 errors : & [ FulfillmentError < ' tcx > ] ,
132- body_id : Option < hir :: BodyId > ,
130+ body_def_id : Option < LocalDefId > ,
133131 ) -> ErrorGuaranteed ;
134132
135133 fn report_overflow_obligation < T > (
@@ -391,7 +389,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
391389 fn report_fulfillment_errors (
392390 & self ,
393391 errors : & [ FulfillmentError < ' tcx > ] ,
394- body_id : Option < hir :: BodyId > ,
392+ body_def_id : Option < LocalDefId > ,
395393 ) -> ErrorGuaranteed {
396394 #[ derive( Debug ) ]
397395 struct ErrorDescriptor < ' tcx > {
@@ -469,7 +467,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
469467 for from_expansion in [ false , true ] {
470468 for ( error, suppressed) in iter:: zip ( errors, & is_suppressed) {
471469 if !suppressed && error. obligation . cause . span . from_expansion ( ) == from_expansion {
472- self . report_fulfillment_error ( error, body_id ) ;
470+ self . report_fulfillment_error ( error, body_def_id ) ;
473471 }
474472 }
475473 }
@@ -955,8 +953,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
955953 ) ;
956954 }
957955
958- let body_hir_id =
959- self . tcx . hir ( ) . local_def_id_to_hir_id ( obligation. cause . body_id ) ;
956+ let body_def_id = obligation. cause . body_id ;
960957 // Try to report a help message
961958 if is_fn_trait
962959 && let Ok ( ( implemented_kind, params) ) = self . type_implements_fn_trait (
@@ -1037,7 +1034,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10371034 if !self . report_similar_impl_candidates (
10381035 impl_candidates,
10391036 trait_ref,
1040- body_hir_id ,
1037+ body_def_id ,
10411038 & mut err,
10421039 true ,
10431040 ) {
@@ -1073,7 +1070,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10731070 self . report_similar_impl_candidates (
10741071 impl_candidates,
10751072 trait_ref,
1076- body_hir_id ,
1073+ body_def_id ,
10771074 & mut err,
10781075 true ,
10791076 ) ;
@@ -1497,7 +1494,7 @@ trait InferCtxtPrivExt<'tcx> {
14971494 fn report_fulfillment_error (
14981495 & self ,
14991496 error : & FulfillmentError < ' tcx > ,
1500- body_id : Option < hir :: BodyId > ,
1497+ body_def_id : Option < LocalDefId > ,
15011498 ) ;
15021499
15031500 fn report_projection_error (
@@ -1531,7 +1528,7 @@ trait InferCtxtPrivExt<'tcx> {
15311528 & self ,
15321529 impl_candidates : Vec < ImplCandidate < ' tcx > > ,
15331530 trait_ref : ty:: PolyTraitRef < ' tcx > ,
1534- body_id : hir :: HirId ,
1531+ body_def_id : LocalDefId ,
15351532 err : & mut Diagnostic ,
15361533 other : bool ,
15371534 ) -> bool ;
@@ -1564,7 +1561,7 @@ trait InferCtxtPrivExt<'tcx> {
15641561 fn maybe_report_ambiguity (
15651562 & self ,
15661563 obligation : & PredicateObligation < ' tcx > ,
1567- body_id : Option < hir :: BodyId > ,
1564+ body_def_id : Option < LocalDefId > ,
15681565 ) ;
15691566
15701567 fn predicate_can_apply (
@@ -1650,7 +1647,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16501647 fn report_fulfillment_error (
16511648 & self ,
16521649 error : & FulfillmentError < ' tcx > ,
1653- body_id : Option < hir :: BodyId > ,
1650+ body_def_id : Option < LocalDefId > ,
16541651 ) {
16551652 match error. code {
16561653 FulfillmentErrorCode :: CodeSelectionError ( ref selection_error) => {
@@ -1664,7 +1661,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
16641661 self . report_projection_error ( & error. obligation , e) ;
16651662 }
16661663 FulfillmentErrorCode :: CodeAmbiguity => {
1667- self . maybe_report_ambiguity ( & error. obligation , body_id ) ;
1664+ self . maybe_report_ambiguity ( & error. obligation , body_def_id ) ;
16681665 }
16691666 FulfillmentErrorCode :: CodeSubtypeError ( ref expected_found, ref err) => {
16701667 self . report_mismatched_types (
@@ -2029,7 +2026,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
20292026 & self ,
20302027 impl_candidates : Vec < ImplCandidate < ' tcx > > ,
20312028 trait_ref : ty:: PolyTraitRef < ' tcx > ,
2032- body_id : hir :: HirId ,
2029+ body_def_id : LocalDefId ,
20332030 err : & mut Diagnostic ,
20342031 other : bool ,
20352032 ) -> bool {
@@ -2120,9 +2117,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
21202117 // FIXME(compiler-errors): This could be generalized, both to
21212118 // be more granular, and probably look past other `#[fundamental]`
21222119 // types, too.
2123- self . tcx
2124- . visibility ( def. did ( ) )
2125- . is_accessible_from ( body_id. owner . def_id , self . tcx )
2120+ self . tcx . visibility ( def. did ( ) ) . is_accessible_from ( body_def_id, self . tcx )
21262121 } else {
21272122 true
21282123 }
@@ -2234,7 +2229,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22342229 fn maybe_report_ambiguity (
22352230 & self ,
22362231 obligation : & PredicateObligation < ' tcx > ,
2237- body_id : Option < hir :: BodyId > ,
2232+ body_def_id : Option < LocalDefId > ,
22382233 ) {
22392234 // Unable to successfully determine, probably means
22402235 // insufficient type information, but could mean
@@ -2277,7 +2272,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
22772272 if self . tcx . lang_items ( ) . sized_trait ( ) == Some ( trait_ref. def_id ( ) ) {
22782273 if let None = self . tainted_by_errors ( ) {
22792274 self . emit_inference_failure_err (
2280- body_id ,
2275+ body_def_id ,
22812276 span,
22822277 trait_ref. self_ty ( ) . skip_binder ( ) . into ( ) ,
22832278 ErrorCode :: E0282 ,
@@ -2304,7 +2299,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23042299 let subst = data. trait_ref . substs . iter ( ) . find ( |s| s. has_non_region_infer ( ) ) ;
23052300
23062301 let mut err = if let Some ( subst) = subst {
2307- self . emit_inference_failure_err ( body_id, span, subst, ErrorCode :: E0283 , true )
2302+ self . emit_inference_failure_err (
2303+ body_def_id,
2304+ span,
2305+ subst,
2306+ ErrorCode :: E0283 ,
2307+ true ,
2308+ )
23082309 } else {
23092310 struct_span_err ! (
23102311 self . tcx. sess,
@@ -2348,12 +2349,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23482349 predicate. to_opt_poly_trait_pred ( ) . unwrap ( ) ,
23492350 ) ;
23502351 if impl_candidates. len ( ) < 10 {
2351- let hir =
2352- self . tcx . hir ( ) . local_def_id_to_hir_id ( obligation. cause . body_id ) ;
23532352 self . report_similar_impl_candidates (
23542353 impl_candidates,
23552354 trait_ref,
2356- body_id . map ( |id| id . hir_id ) . unwrap_or ( hir ) ,
2355+ body_def_id . unwrap_or ( obligation . cause . body_id ) ,
23572356 & mut err,
23582357 false ,
23592358 ) ;
@@ -2375,9 +2374,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
23752374 self . suggest_fully_qualified_path ( & mut err, def_id, span, trait_ref. def_id ( ) ) ;
23762375 }
23772376
2378- if let ( Some ( body_id ) , Some ( ty:: subst:: GenericArgKind :: Type ( _) ) ) =
2379- ( body_id , subst. map ( |subst| subst. unpack ( ) ) )
2377+ if let ( Some ( body_def_id ) , Some ( ty:: subst:: GenericArgKind :: Type ( _) ) ) =
2378+ ( body_def_id , subst. map ( |subst| subst. unpack ( ) ) )
23802379 {
2380+ let body_id = self . tcx . hir ( ) . body_owned_by ( body_def_id) ;
23812381 let mut expr_finder = FindExprBySpan :: new ( span) ;
23822382 expr_finder. visit_expr ( & self . tcx . hir ( ) . body ( body_id) . value ) ;
23832383
@@ -2473,7 +2473,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24732473 return ;
24742474 }
24752475
2476- self . emit_inference_failure_err ( body_id , span, arg, ErrorCode :: E0282 , false )
2476+ self . emit_inference_failure_err ( body_def_id , span, arg, ErrorCode :: E0282 , false )
24772477 }
24782478
24792479 ty:: PredicateKind :: Subtype ( data) => {
@@ -2487,7 +2487,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
24872487 let SubtypePredicate { a_is_expected : _, a, b } = data;
24882488 // both must be type variables, or the other would've been instantiated
24892489 assert ! ( a. is_ty_var( ) && b. is_ty_var( ) ) ;
2490- self . emit_inference_failure_err ( body_id , span, a. into ( ) , ErrorCode :: E0282 , true )
2490+ self . emit_inference_failure_err ( body_def_id , span, a. into ( ) , ErrorCode :: E0282 , true )
24912491 }
24922492 ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( data) ) => {
24932493 if predicate. references_error ( ) || self . tainted_by_errors ( ) . is_some ( ) {
@@ -2501,7 +2501,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
25012501 . find ( |g| g. has_non_region_infer ( ) ) ;
25022502 if let Some ( subst) = subst {
25032503 let mut err = self . emit_inference_failure_err (
2504- body_id ,
2504+ body_def_id ,
25052505 span,
25062506 subst,
25072507 ErrorCode :: E0284 ,
@@ -2530,7 +2530,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
25302530 let subst = data. walk ( ) . find ( |g| g. is_non_region_infer ( ) ) ;
25312531 if let Some ( subst) = subst {
25322532 let err = self . emit_inference_failure_err (
2533- body_id ,
2533+ body_def_id ,
25342534 span,
25352535 subst,
25362536 ErrorCode :: E0284 ,
0 commit comments