2
2
#![ deny( rustc:: diagnostic_outside_of_impl) ]
3
3
//! Error reporting machinery for lifetime errors.
4
4
5
+ use either:: Either ;
5
6
use rustc_data_structures:: fx:: FxHashSet ;
6
7
use rustc_errors:: { Applicability , Diagnostic , DiagnosticBuilder , ErrorGuaranteed , MultiSpan } ;
7
8
use rustc_hir:: def_id:: DefId ;
@@ -16,7 +17,7 @@ use rustc_infer::infer::{
16
17
NllRegionVariableOrigin , RelateParamBound ,
17
18
} ;
18
19
use rustc_middle:: hir:: place:: PlaceBase ;
19
- use rustc_middle:: mir:: { ConstraintCategory , ReturnConstraint } ;
20
+ use rustc_middle:: mir:: { ConstraintCategory , ReturnConstraint , TerminatorKind } ;
20
21
use rustc_middle:: ty:: subst:: InternalSubsts ;
21
22
use rustc_middle:: ty:: Region ;
22
23
use rustc_middle:: ty:: TypeVisitor ;
@@ -39,7 +40,7 @@ use crate::{
39
40
MirBorrowckCtxt ,
40
41
} ;
41
42
42
- impl < ' tcx > ConstraintDescription for ConstraintCategory < ' tcx > {
43
+ impl ConstraintDescription for ConstraintCategory {
43
44
fn description ( & self ) -> & ' static str {
44
45
// Must end with a space. Allows for empty names to be provided.
45
46
match self {
@@ -115,15 +116,15 @@ pub(crate) enum RegionErrorKind<'tcx> {
115
116
116
117
/// Information about the various region constraints involved in a borrow checker error.
117
118
#[ derive( Clone , Debug ) ]
118
- pub struct ErrorConstraintInfo < ' tcx > {
119
+ pub struct ErrorConstraintInfo {
119
120
// fr: outlived_fr
120
121
pub ( super ) fr : RegionVid ,
121
122
pub ( super ) fr_is_local : bool ,
122
123
pub ( super ) outlived_fr : RegionVid ,
123
124
pub ( super ) outlived_fr_is_local : bool ,
124
125
125
126
// Category and span for best blame constraint
126
- pub ( super ) category : ConstraintCategory < ' tcx > ,
127
+ pub ( super ) category : ConstraintCategory ,
127
128
pub ( super ) span : Span ,
128
129
}
129
130
@@ -498,7 +499,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
498
499
/// ```
499
500
fn report_fnmut_error (
500
501
& self ,
501
- errci : & ErrorConstraintInfo < ' tcx > ,
502
+ errci : & ErrorConstraintInfo ,
502
503
kind : ReturnConstraint ,
503
504
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
504
505
let ErrorConstraintInfo { outlived_fr, span, .. } = errci;
@@ -571,7 +572,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
571
572
#[ instrument( level = "debug" , skip( self ) ) ]
572
573
fn report_escaping_data_error (
573
574
& self ,
574
- errci : & ErrorConstraintInfo < ' tcx > ,
575
+ errci : & ErrorConstraintInfo ,
575
576
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
576
577
let ErrorConstraintInfo { span, category, .. } = errci;
577
578
@@ -675,7 +676,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
675
676
/// ```
676
677
fn report_general_error (
677
678
& self ,
678
- errci : & ErrorConstraintInfo < ' tcx > ,
679
+ errci : & ErrorConstraintInfo ,
679
680
) -> DiagnosticBuilder < ' tcx , ErrorGuaranteed > {
680
681
let ErrorConstraintInfo {
681
682
fr,
@@ -788,15 +789,20 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
788
789
diag : & mut Diagnostic ,
789
790
f : Region < ' tcx > ,
790
791
o : Region < ' tcx > ,
791
- category : & ConstraintCategory < ' tcx > ,
792
+ category : & ConstraintCategory ,
792
793
) {
793
794
if !o. is_static ( ) {
794
795
return ;
795
796
}
796
797
797
798
let tcx = self . infcx . tcx ;
798
799
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) ;
800
806
let ( fn_did, substs) = match func_ty. kind ( ) {
801
807
ty:: FnDef ( fn_did, substs) => ( fn_did, substs) ,
802
808
_ => return ,
0 commit comments