@@ -61,7 +61,7 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet};
6161use rustc_errors:: { pluralize, struct_span_err, Diagnostic , ErrorGuaranteed } ;
6262use rustc_errors:: { Applicability , DiagnosticBuilder , DiagnosticStyledString , MultiSpan } ;
6363use rustc_hir as hir;
64- use rustc_hir:: def_id:: DefId ;
64+ use rustc_hir:: def_id:: { DefId , LocalDefId } ;
6565use rustc_hir:: lang_items:: LangItem ;
6666use rustc_hir:: { Item , ItemKind , Node } ;
6767use rustc_middle:: dep_graph:: DepContext ;
@@ -2285,7 +2285,9 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22852285 bound_kind : GenericKind < ' tcx > ,
22862286 sub : Region < ' tcx > ,
22872287 ) {
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 ( ) ;
22892291 }
22902292
22912293 pub fn construct_generic_bound_failure (
@@ -2294,31 +2296,29 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22942296 origin : Option < SubregionOrigin < ' tcx > > ,
22952297 bound_kind : GenericKind < ' tcx > ,
22962298 sub : Region < ' tcx > ,
2299+ owner : Option < LocalDefId > ,
22972300 ) -> DiagnosticBuilder < ' a , ErrorGuaranteed > {
22982301 let hir = self . tcx . hir ( ) ;
22992302 // Attempt to obtain the span of the parameter so we can
23002303 // 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+ } ) ;
23222322
23232323 let span = match generics {
23242324 // 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> {
26062606 None ,
26072607 ) ;
26082608 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 ( ) ;
26142611 let t = self . resolve_vars_if_possible ( t) ;
26152612 match t. kind ( ) {
26162613 // We've got:
0 commit comments