@@ -14,7 +14,7 @@ use rustc_span::{DUMMY_SP, Span};
14
14
use rustc_trait_selection:: traits:: { ObligationCause , ObligationCtxt } ;
15
15
use tracing:: debug;
16
16
17
- use crate :: { FnCtxt , TypeckRootCtxt , errors} ;
17
+ use crate :: { FnCtxt , errors} ;
18
18
19
19
#[ derive( Copy , Clone ) ]
20
20
pub ( crate ) enum DivergingFallbackBehavior {
@@ -419,7 +419,7 @@ impl<'tcx> FnCtxt<'_, 'tcx> {
419
419
root_vid : ty:: TyVid ,
420
420
) {
421
421
let unsafe_infer_vars = unsafe_infer_vars. get_or_init ( || {
422
- let unsafe_infer_vars = compute_unsafe_infer_vars ( self . root_ctxt , self . body_id ) ;
422
+ let unsafe_infer_vars = compute_unsafe_infer_vars ( self , self . body_id ) ;
423
423
debug ! ( ?unsafe_infer_vars) ;
424
424
unsafe_infer_vars
425
425
} ) ;
@@ -569,27 +569,26 @@ pub(crate) enum UnsafeUseReason {
569
569
///
570
570
/// `compute_unsafe_infer_vars` will return `{ id(?X) -> (hir_id, span, Call) }`
571
571
fn compute_unsafe_infer_vars < ' a , ' tcx > (
572
- root_ctxt : & ' a TypeckRootCtxt < ' tcx > ,
572
+ fcx : & ' a FnCtxt < ' a , ' tcx > ,
573
573
body_id : LocalDefId ,
574
574
) -> UnordMap < ty:: TyVid , ( HirId , Span , UnsafeUseReason ) > {
575
- let body =
576
- root_ctxt. tcx . hir ( ) . maybe_body_owned_by ( body_id) . expect ( "body id must have an owner" ) ;
575
+ let body = fcx. tcx . hir ( ) . maybe_body_owned_by ( body_id) . expect ( "body id must have an owner" ) ;
577
576
let mut res = UnordMap :: default ( ) ;
578
577
579
578
struct UnsafeInferVarsVisitor < ' a , ' tcx > {
580
- root_ctxt : & ' a TypeckRootCtxt < ' tcx > ,
579
+ fcx : & ' a FnCtxt < ' a , ' tcx > ,
581
580
res : & ' a mut UnordMap < ty:: TyVid , ( HirId , Span , UnsafeUseReason ) > ,
582
581
}
583
582
584
583
impl Visitor < ' _ > for UnsafeInferVarsVisitor < ' _ , ' _ > {
585
584
fn visit_expr ( & mut self , ex : & ' _ hir:: Expr < ' _ > ) {
586
- let typeck_results = self . root_ctxt . typeck_results . borrow ( ) ;
585
+ let typeck_results = self . fcx . typeck_results . borrow ( ) ;
587
586
588
587
match ex. kind {
589
588
hir:: ExprKind :: MethodCall ( ..) => {
590
589
if let Some ( def_id) = typeck_results. type_dependent_def_id ( ex. hir_id )
591
- && let method_ty = self . root_ctxt . tcx . type_of ( def_id) . instantiate_identity ( )
592
- && let sig = method_ty. fn_sig ( self . root_ctxt . tcx )
590
+ && let method_ty = self . fcx . tcx . type_of ( def_id) . instantiate_identity ( )
591
+ && let sig = method_ty. fn_sig ( self . fcx . tcx )
593
592
&& let hir:: Safety :: Unsafe = sig. safety ( )
594
593
{
595
594
let mut collector = InferVarCollector {
@@ -609,7 +608,7 @@ fn compute_unsafe_infer_vars<'a, 'tcx>(
609
608
let func_ty = typeck_results. expr_ty ( func) ;
610
609
611
610
if func_ty. is_fn ( )
612
- && let sig = func_ty. fn_sig ( self . root_ctxt . tcx )
611
+ && let sig = func_ty. fn_sig ( self . fcx . tcx )
613
612
&& let hir:: Safety :: Unsafe = sig. safety ( )
614
613
{
615
614
let mut collector = InferVarCollector {
@@ -640,7 +639,7 @@ fn compute_unsafe_infer_vars<'a, 'tcx>(
640
639
// If this path refers to an unsafe function, collect inference variables which may affect it.
641
640
// `is_fn` excludes closures, but those can't be unsafe.
642
641
if ty. is_fn ( )
643
- && let sig = ty. fn_sig ( self . root_ctxt . tcx )
642
+ && let sig = ty. fn_sig ( self . fcx . tcx )
644
643
&& let hir:: Safety :: Unsafe = sig. safety ( )
645
644
{
646
645
let mut collector = InferVarCollector {
@@ -698,7 +697,7 @@ fn compute_unsafe_infer_vars<'a, 'tcx>(
698
697
}
699
698
}
700
699
701
- UnsafeInferVarsVisitor { root_ctxt , res : & mut res } . visit_expr ( & body. value ) ;
700
+ UnsafeInferVarsVisitor { fcx , res : & mut res } . visit_expr ( & body. value ) ;
702
701
703
702
debug ! ( ?res, "collected the following unsafe vars for {body_id:?}" ) ;
704
703
0 commit comments