@@ -61,7 +61,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
61
61
use rustc_errors:: { pluralize, struct_span_err, Diagnostic , ErrorGuaranteed } ;
62
62
use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticStyledString , MultiSpan } ;
63
63
use rustc_hir as hir;
64
- use rustc_hir:: def_id:: DefId ;
64
+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
65
65
use rustc_hir:: lang_items:: LangItem ;
66
66
use rustc_hir:: { Item , ItemKind , Node } ;
67
67
use rustc_middle:: dep_graph:: DepContext ;
@@ -2285,7 +2285,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2285
2285
bound_kind : GenericKind < ' tcx > ,
2286
2286
sub : Region < ' tcx > ,
2287
2287
) {
2288
- self . construct_generic_bound_failure ( span, origin, bound_kind, sub) . emit ( ) ;
2288
+ let owner =
2289
+ self . in_progress_typeck_results . map ( |typeck_results| typeck_results. borrow ( ) . hir_owner ) ;
2290
+ self . construct_generic_bound_failure ( span, origin, bound_kind, sub, owner) . emit ( ) ;
2289
2291
}
2290
2292
2291
2293
pub fn construct_generic_bound_failure (
@@ -2294,31 +2296,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2294
2296
origin : Option < SubregionOrigin < ' tcx > > ,
2295
2297
bound_kind : GenericKind < ' tcx > ,
2296
2298
sub : Region < ' tcx > ,
2299
+ owner : Option < LocalDefId > ,
2297
2300
) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
2298
2301
let hir = self . tcx . hir ( ) ;
2299
2302
// Attempt to obtain the span of the parameter so we can
2300
2303
// suggest adding an explicit lifetime bound to it.
2301
- let generics = self
2302
- . in_progress_typeck_results
2303
- . map ( |typeck_results| typeck_results. borrow ( ) . hir_owner )
2304
- . map ( |owner| {
2305
- let hir_id = hir. local_def_id_to_hir_id ( owner) ;
2306
- let parent_id = hir. get_parent_item ( hir_id) ;
2307
- (
2308
- // Parent item could be a `mod`, so we check the HIR before calling:
2309
- if let Some ( Node :: Item ( Item {
2310
- kind : ItemKind :: Trait ( ..) | ItemKind :: Impl { .. } ,
2311
- ..
2312
- } ) ) = hir. find_by_def_id ( parent_id)
2313
- {
2314
- Some ( self . tcx . generics_of ( parent_id) )
2315
- } else {
2316
- None
2317
- } ,
2318
- self . tcx . generics_of ( owner. to_def_id ( ) ) ,
2319
- hir. span ( hir_id) ,
2320
- )
2321
- } ) ;
2304
+ let generics = owner. map ( |owner| {
2305
+ let hir_id = hir. local_def_id_to_hir_id ( owner) ;
2306
+ let parent_id = hir. get_parent_item ( hir_id) ;
2307
+ (
2308
+ // Parent item could be a `mod`, so we check the HIR before calling:
2309
+ if let Some ( Node :: Item ( Item {
2310
+ kind : ItemKind :: Trait ( ..) | ItemKind :: Impl { .. } ,
2311
+ ..
2312
+ } ) ) = hir. find_by_def_id ( parent_id)
2313
+ {
2314
+ Some ( self . tcx . generics_of ( parent_id) )
2315
+ } else {
2316
+ None
2317
+ } ,
2318
+ self . tcx . generics_of ( owner. to_def_id ( ) ) ,
2319
+ hir. span ( hir_id) ,
2320
+ )
2321
+ } ) ;
2322
2322
2323
2323
let span = match generics {
2324
2324
// This is to get around the trait identity obligation, that has a `DUMMY_SP` as signal
@@ -2606,11 +2606,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
2606
2606
None ,
2607
2607
) ;
2608
2608
if let Some ( infer:: RelateParamBound ( _, t, _) ) = origin {
2609
- let return_impl_trait = self
2610
- . in_progress_typeck_results
2611
- . map ( |typeck_results| typeck_results. borrow ( ) . hir_owner )
2612
- . and_then ( |owner| self . tcx . return_type_impl_trait ( owner) )
2613
- . is_some ( ) ;
2609
+ let return_impl_trait =
2610
+ owner. and_then ( |owner| self . tcx . return_type_impl_trait ( owner) ) . is_some ( ) ;
2614
2611
let t = self . resolve_vars_if_possible ( t) ;
2615
2612
match t. kind ( ) {
2616
2613
// We've got:
0 commit comments