22#![ deny( rustc:: diagnostic_outside_of_impl) ]
33//! Error reporting machinery for lifetime errors.
44
5- use either:: Either ;
65use rustc_data_structures:: fx:: FxHashSet ;
76use rustc_errors:: { Applicability , Diagnostic , DiagnosticBuilder , ErrorGuaranteed , MultiSpan } ;
87use rustc_hir:: def_id:: DefId ;
@@ -17,7 +16,7 @@ use rustc_infer::infer::{
1716 NllRegionVariableOrigin , RelateParamBound ,
1817} ;
1918use rustc_middle:: hir:: place:: PlaceBase ;
20- use rustc_middle:: mir:: { ConstraintCategory , ReturnConstraint , TerminatorKind } ;
19+ use rustc_middle:: mir:: { ConstraintCategory , ReturnConstraint } ;
2120use rustc_middle:: ty:: subst:: InternalSubsts ;
2221use rustc_middle:: ty:: Region ;
2322use rustc_middle:: ty:: TypeVisitor ;
@@ -40,7 +39,7 @@ use crate::{
4039 MirBorrowckCtxt ,
4140} ;
4241
43- impl ConstraintDescription for ConstraintCategory {
42+ impl < ' tcx > ConstraintDescription for ConstraintCategory < ' tcx > {
4443 fn description ( & self ) -> & ' static str {
4544 // Must end with a space. Allows for empty names to be provided.
4645 match self {
@@ -116,15 +115,15 @@ pub(crate) enum RegionErrorKind<'tcx> {
116115
117116/// Information about the various region constraints involved in a borrow checker error.
118117#[ derive( Clone , Debug ) ]
119- pub struct ErrorConstraintInfo {
118+ pub struct ErrorConstraintInfo < ' tcx > {
120119 // fr: outlived_fr
121120 pub ( super ) fr : RegionVid ,
122121 pub ( super ) fr_is_local : bool ,
123122 pub ( super ) outlived_fr : RegionVid ,
124123 pub ( super ) outlived_fr_is_local : bool ,
125124
126125 // Category and span for best blame constraint
127- pub ( super ) category : ConstraintCategory ,
126+ pub ( super ) category : ConstraintCategory < ' tcx > ,
128127 pub ( super ) span : Span ,
129128}
130129
@@ -499,7 +498,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
499498 /// ```
500499 fn report_fnmut_error (
501500 & self ,
502- errci : & ErrorConstraintInfo ,
501+ errci : & ErrorConstraintInfo < ' tcx > ,
503502 kind : ReturnConstraint ,
504503 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
505504 let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
@@ -572,7 +571,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
572571 #[ instrument( level = "debug" , skip( self ) ) ]
573572 fn report_escaping_data_error (
574573 & self ,
575- errci : & ErrorConstraintInfo ,
574+ errci : & ErrorConstraintInfo < ' tcx > ,
576575 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
577576 let ErrorConstraintInfo { span, category, .. } = errci;
578577
@@ -676,7 +675,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
676675 /// ```
677676 fn report_general_error (
678677 & self ,
679- errci : & ErrorConstraintInfo ,
678+ errci : & ErrorConstraintInfo < ' tcx > ,
680679 ) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
681680 let ErrorConstraintInfo {
682681 fr,
@@ -789,20 +788,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
789788 diag : & mut Diagnostic ,
790789 f : Region < ' tcx > ,
791790 o : Region < ' tcx > ,
792- category : & ConstraintCategory ,
791+ category : & ConstraintCategory < ' tcx > ,
793792 ) {
794793 if !o. is_static ( ) {
795794 return ;
796795 }
797796
798797 let tcx = self . infcx . tcx ;
799798
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) ;
799+ let instance = if let ConstraintCategory :: CallArgument ( Some ( func_ty) ) = category {
806800 let ( fn_did, substs) = match func_ty. kind ( ) {
807801 ty:: FnDef ( fn_did, substs) => ( fn_did, substs) ,
808802 _ => return ,
0 commit comments