@@ -24,11 +24,9 @@ use rustc_errors::{
24
24
} ;
25
25
use rustc_hir as hir;
26
26
use rustc_hir:: def:: Namespace ;
27
- use rustc_hir:: def_id:: DefId ;
27
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
28
28
use 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 } ;
32
30
use rustc_infer:: infer:: error_reporting:: TypeErrCtxt ;
33
31
use rustc_infer:: infer:: { InferOk , TypeTrace } ;
34
32
use rustc_middle:: traits:: select:: OverflowError ;
@@ -129,7 +127,7 @@ pub trait TypeErrCtxtExt<'tcx> {
129
127
fn report_fulfillment_errors (
130
128
& self ,
131
129
errors : & [ FulfillmentError < ' tcx > ] ,
132
- body_id : Option < hir :: BodyId > ,
130
+ body_def_id : Option < LocalDefId > ,
133
131
) -> ErrorGuaranteed ;
134
132
135
133
fn report_overflow_obligation < T > (
@@ -391,7 +389,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
391
389
fn report_fulfillment_errors (
392
390
& self ,
393
391
errors : & [ FulfillmentError < ' tcx > ] ,
394
- body_id : Option < hir :: BodyId > ,
392
+ body_def_id : Option < LocalDefId > ,
395
393
) -> ErrorGuaranteed {
396
394
#[ derive( Debug ) ]
397
395
struct ErrorDescriptor < ' tcx > {
@@ -469,7 +467,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
469
467
for from_expansion in [ false , true ] {
470
468
for ( error, suppressed) in iter:: zip ( errors, & is_suppressed) {
471
469
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 ) ;
473
471
}
474
472
}
475
473
}
@@ -955,8 +953,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
955
953
) ;
956
954
}
957
955
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 ;
960
957
// Try to report a help message
961
958
if is_fn_trait
962
959
&& let Ok ( ( implemented_kind, params) ) = self . type_implements_fn_trait (
@@ -1037,7 +1034,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1037
1034
if !self . report_similar_impl_candidates (
1038
1035
impl_candidates,
1039
1036
trait_ref,
1040
- body_hir_id ,
1037
+ body_def_id ,
1041
1038
& mut err,
1042
1039
true ,
1043
1040
) {
@@ -1073,7 +1070,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1073
1070
self . report_similar_impl_candidates (
1074
1071
impl_candidates,
1075
1072
trait_ref,
1076
- body_hir_id ,
1073
+ body_def_id ,
1077
1074
& mut err,
1078
1075
true ,
1079
1076
) ;
@@ -1497,7 +1494,7 @@ trait InferCtxtPrivExt<'tcx> {
1497
1494
fn report_fulfillment_error (
1498
1495
& self ,
1499
1496
error : & FulfillmentError < ' tcx > ,
1500
- body_id : Option < hir :: BodyId > ,
1497
+ body_def_id : Option < LocalDefId > ,
1501
1498
) ;
1502
1499
1503
1500
fn report_projection_error (
@@ -1531,7 +1528,7 @@ trait InferCtxtPrivExt<'tcx> {
1531
1528
& self ,
1532
1529
impl_candidates : Vec < ImplCandidate < ' tcx > > ,
1533
1530
trait_ref : ty:: PolyTraitRef < ' tcx > ,
1534
- body_id : hir :: HirId ,
1531
+ body_def_id : LocalDefId ,
1535
1532
err : & mut Diagnostic ,
1536
1533
other : bool ,
1537
1534
) -> bool ;
@@ -1564,7 +1561,7 @@ trait InferCtxtPrivExt<'tcx> {
1564
1561
fn maybe_report_ambiguity (
1565
1562
& self ,
1566
1563
obligation : & PredicateObligation < ' tcx > ,
1567
- body_id : Option < hir :: BodyId > ,
1564
+ body_def_id : Option < LocalDefId > ,
1568
1565
) ;
1569
1566
1570
1567
fn predicate_can_apply (
@@ -1650,7 +1647,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1650
1647
fn report_fulfillment_error (
1651
1648
& self ,
1652
1649
error : & FulfillmentError < ' tcx > ,
1653
- body_id : Option < hir :: BodyId > ,
1650
+ body_def_id : Option < LocalDefId > ,
1654
1651
) {
1655
1652
match error. code {
1656
1653
FulfillmentErrorCode :: CodeSelectionError ( ref selection_error) => {
@@ -1664,7 +1661,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
1664
1661
self . report_projection_error ( & error. obligation , e) ;
1665
1662
}
1666
1663
FulfillmentErrorCode :: CodeAmbiguity => {
1667
- self . maybe_report_ambiguity ( & error. obligation , body_id ) ;
1664
+ self . maybe_report_ambiguity ( & error. obligation , body_def_id ) ;
1668
1665
}
1669
1666
FulfillmentErrorCode :: CodeSubtypeError ( ref expected_found, ref err) => {
1670
1667
self . report_mismatched_types (
@@ -2029,7 +2026,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2029
2026
& self ,
2030
2027
impl_candidates : Vec < ImplCandidate < ' tcx > > ,
2031
2028
trait_ref : ty:: PolyTraitRef < ' tcx > ,
2032
- body_id : hir :: HirId ,
2029
+ body_def_id : LocalDefId ,
2033
2030
err : & mut Diagnostic ,
2034
2031
other : bool ,
2035
2032
) -> bool {
@@ -2120,9 +2117,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2120
2117
// FIXME(compiler-errors): This could be generalized, both to
2121
2118
// be more granular, and probably look past other `#[fundamental]`
2122
2119
// 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 )
2126
2121
} else {
2127
2122
true
2128
2123
}
@@ -2234,7 +2229,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2234
2229
fn maybe_report_ambiguity (
2235
2230
& self ,
2236
2231
obligation : & PredicateObligation < ' tcx > ,
2237
- body_id : Option < hir :: BodyId > ,
2232
+ body_def_id : Option < LocalDefId > ,
2238
2233
) {
2239
2234
// Unable to successfully determine, probably means
2240
2235
// insufficient type information, but could mean
@@ -2277,7 +2272,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2277
2272
if self . tcx . lang_items ( ) . sized_trait ( ) == Some ( trait_ref. def_id ( ) ) {
2278
2273
if let None = self . tainted_by_errors ( ) {
2279
2274
self . emit_inference_failure_err (
2280
- body_id ,
2275
+ body_def_id ,
2281
2276
span,
2282
2277
trait_ref. self_ty ( ) . skip_binder ( ) . into ( ) ,
2283
2278
ErrorCode :: E0282 ,
@@ -2304,7 +2299,13 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2304
2299
let subst = data. trait_ref . substs . iter ( ) . find ( |s| s. has_non_region_infer ( ) ) ;
2305
2300
2306
2301
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
+ )
2308
2309
} else {
2309
2310
struct_span_err ! (
2310
2311
self . tcx. sess,
@@ -2348,12 +2349,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2348
2349
predicate. to_opt_poly_trait_pred ( ) . unwrap ( ) ,
2349
2350
) ;
2350
2351
if impl_candidates. len ( ) < 10 {
2351
- let hir =
2352
- self . tcx . hir ( ) . local_def_id_to_hir_id ( obligation. cause . body_id ) ;
2353
2352
self . report_similar_impl_candidates (
2354
2353
impl_candidates,
2355
2354
trait_ref,
2356
- body_id . map ( |id| id . hir_id ) . unwrap_or ( hir ) ,
2355
+ body_def_id . unwrap_or ( obligation . cause . body_id ) ,
2357
2356
& mut err,
2358
2357
false ,
2359
2358
) ;
@@ -2375,9 +2374,10 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2375
2374
self . suggest_fully_qualified_path ( & mut err, def_id, span, trait_ref. def_id ( ) ) ;
2376
2375
}
2377
2376
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 ( ) ) )
2380
2379
{
2380
+ let body_id = self . tcx . hir ( ) . body_owned_by ( body_def_id) ;
2381
2381
let mut expr_finder = FindExprBySpan :: new ( span) ;
2382
2382
expr_finder. visit_expr ( & self . tcx . hir ( ) . body ( body_id) . value ) ;
2383
2383
@@ -2473,7 +2473,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2473
2473
return ;
2474
2474
}
2475
2475
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 )
2477
2477
}
2478
2478
2479
2479
ty:: PredicateKind :: Subtype ( data) => {
@@ -2487,7 +2487,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2487
2487
let SubtypePredicate { a_is_expected : _, a, b } = data;
2488
2488
// both must be type variables, or the other would've been instantiated
2489
2489
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 )
2491
2491
}
2492
2492
ty:: PredicateKind :: Clause ( ty:: Clause :: Projection ( data) ) => {
2493
2493
if predicate. references_error ( ) || self . tainted_by_errors ( ) . is_some ( ) {
@@ -2501,7 +2501,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2501
2501
. find ( |g| g. has_non_region_infer ( ) ) ;
2502
2502
if let Some ( subst) = subst {
2503
2503
let mut err = self . emit_inference_failure_err (
2504
- body_id ,
2504
+ body_def_id ,
2505
2505
span,
2506
2506
subst,
2507
2507
ErrorCode :: E0284 ,
@@ -2530,7 +2530,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
2530
2530
let subst = data. walk ( ) . find ( |g| g. is_non_region_infer ( ) ) ;
2531
2531
if let Some ( subst) = subst {
2532
2532
let err = self . emit_inference_failure_err (
2533
- body_id ,
2533
+ body_def_id ,
2534
2534
span,
2535
2535
subst,
2536
2536
ErrorCode :: E0284 ,
0 commit comments