22#![ deny( rustc:: diagnostic_outside_of_impl) ]
33//! Error reporting machinery for lifetime errors.
44
5+ use either:: Either ;
56use rustc_data_structures:: fx:: FxHashSet ;
67use rustc_errors:: { Applicability , Diagnostic , DiagnosticBuilder , ErrorGuaranteed , MultiSpan } ;
78use rustc_hir:: def_id:: DefId ;
@@ -16,7 +17,7 @@ use rustc_infer::infer::{
1617 NllRegionVariableOrigin , RelateParamBound ,
1718} ;
1819use rustc_middle:: hir:: place:: PlaceBase ;
19- use rustc_middle:: mir:: { ConstraintCategory , ReturnConstraint } ;
20+ use rustc_middle:: mir:: { ConstraintCategory , ReturnConstraint , TerminatorKind } ;
2021use rustc_middle:: ty:: subst:: InternalSubsts ;
2122use rustc_middle:: ty:: Region ;
2223use rustc_middle:: ty:: TypeVisitor ;
@@ -39,7 +40,7 @@ use crate::{
3940 MirBorrowckCtxt ,
4041} ;
4142
42- impl < ' tcx > ConstraintDescription for ConstraintCategory < ' tcx > {
43+ impl ConstraintDescription for ConstraintCategory {
4344 fn description ( & self ) -> & ' static str {
4445 // Must end with a space. Allows for empty names to be provided.
4546 match self {
@@ -115,15 +116,15 @@ pub(crate) enum RegionErrorKind<'tcx> {
115116
116117/// Information about the various region constraints involved in a borrow checker error.
117118#[ derive( Clone , Debug ) ]
118- pub struct ErrorConstraintInfo < ' tcx > {
119+ pub struct ErrorConstraintInfo {
119120 // fr: outlived_fr
120121 pub ( super ) fr : RegionVid ,
121122 pub ( super ) fr_is_local : bool ,
122123 pub ( super ) outlived_fr : RegionVid ,
123124 pub ( super ) outlived_fr_is_local : bool ,
124125
125126 // Category and span for best blame constraint
126- pub ( super ) category : ConstraintCategory < ' tcx > ,
127+ pub ( super ) category : ConstraintCategory ,
127128 pub ( super ) span : Span ,
128129}
129130
@@ -498,7 +499,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
498499 /// ```
499500 fn report_fnmut_error (
500501 & self ,
501- errci : & ErrorConstraintInfo < ' tcx > ,
502+ errci : & ErrorConstraintInfo ,
502503 kind : ReturnConstraint ,
503504 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
504505 let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
@@ -571,7 +572,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
571572 #[ instrument( level = "debug" , skip( self ) ) ]
572573 fn report_escaping_data_error (
573574 & self ,
574- errci : & ErrorConstraintInfo < ' tcx > ,
575+ errci : & ErrorConstraintInfo ,
575576 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
576577 let ErrorConstraintInfo { span, category, .. } = errci;
577578
@@ -675,7 +676,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
675676 /// ```
676677 fn report_general_error (
677678 & self ,
678- errci : & ErrorConstraintInfo < ' tcx > ,
679+ errci : & ErrorConstraintInfo ,
679680 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
680681 let ErrorConstraintInfo {
681682 fr,
@@ -788,15 +789,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
788789 diag : & mut Diagnostic ,
789790 f : Region < ' tcx > ,
790791 o : Region < ' tcx > ,
791- category : & ConstraintCategory < ' tcx > ,
792+ category : & ConstraintCategory ,
792793 ) {
793794 if !o. is_static ( ) {
794795 return ;
795796 }
796797
797798 let tcx = self . infcx . tcx ;
798799
799- let instance = if let ConstraintCategory :: CallArgument ( Some ( func_ty) ) = category {
800+ let instance =
801+ if let ConstraintCategory :: CallArgument ( location) = category
802+ && let Either :: Right ( term) = self . body . stmt_at ( * location)
803+ && let TerminatorKind :: Call { func, .. } = & term. kind
804+ {
805+ let func_ty = func. ty ( self . body , tcx) ;
800806 let ( fn_did, substs) = match func_ty. kind ( ) {
801807 ty:: FnDef ( fn_did, substs) => ( fn_did, substs) ,
802808 _ => return ,
0 commit comments