Change InferCtxtBuilder from enter to build

This commit is contained in:
Cameron Steffen
2022-09-19 22:03:59 -05:00
parent 3b328e7049
commit 6819e85501
10 changed files with 87 additions and 102 deletions

View File

@@ -831,11 +831,10 @@ fn walk_parents<'tcx>(
// Trait methods taking `self` // Trait methods taking `self`
arg_ty arg_ty
} && impl_ty.is_ref() } && impl_ty.is_ref()
&& cx.tcx.infer_ctxt().enter(|infcx| && let infcx = cx.tcx.infer_ctxt().build()
infcx && infcx
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env) .type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
.must_apply_modulo_regions() .must_apply_modulo_regions()
)
{ {
return Some(Position::MethodReceiverRefImpl) return Some(Position::MethodReceiverRefImpl)
} }
@@ -1119,9 +1118,8 @@ fn needless_borrow_impl_arg_position<'tcx>(
let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty); let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty);
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
cx.tcx let infcx = cx.tcx.infer_ctxt().build();
.infer_ctxt() infcx.predicate_must_hold_modulo_regions(&obligation)
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
}) })
}; };

View File

@@ -106,9 +106,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
}; };
let fn_def_id = cx.tcx.hir().local_def_id(hir_id); let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body); ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
});
for node in v.set { for node in v.set {
span_lint_hir( span_lint_hir(

View File

@@ -77,10 +77,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
if is_future { if is_future {
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap(); let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
let span = decl.output.span(); let span = decl.output.span();
let send_errors = cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
let cause = traits::ObligationCause::misc(span, hir_id); let cause = traits::ObligationCause::misc(span, hir_id);
traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait) let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait);
});
if !send_errors.is_empty() { if !send_errors.is_empty() {
span_lint_and_then( span_lint_and_then(
cx, cx,
@@ -88,9 +87,10 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
span, span,
"future cannot be sent between threads safely", "future cannot be sent between threads safely",
|db| { |db| {
cx.tcx.infer_ctxt().enter(|infcx| {
for FulfillmentError { obligation, .. } in send_errors { for FulfillmentError { obligation, .. } in send_errors {
infcx.err_ctxt().maybe_note_obligation_cause_for_async_await(db, &obligation); infcx
.err_ctxt()
.maybe_note_obligation_cause_for_async_await(db, &obligation);
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() { if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
db.note(&format!( db.note(&format!(
"`{}` doesn't implement `{}`", "`{}` doesn't implement `{}`",
@@ -99,7 +99,6 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
)); ));
} }
} }
});
}, },
); );
} }

View File

@@ -65,7 +65,7 @@ fn check_for_mutation<'tcx>(
span_low: None, span_low: None,
span_high: None, span_high: None,
}; };
cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
ExprUseVisitor::new( ExprUseVisitor::new(
&mut delegate, &mut delegate,
&infcx, &infcx,
@@ -74,7 +74,6 @@ fn check_for_mutation<'tcx>(
cx.typeck_results(), cx.typeck_results(),
) )
.walk_expr(body); .walk_expr(body);
});
delegate.mutation_span() delegate.mutation_span()
} }

View File

@@ -420,9 +420,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
if trait_predicates.any(|predicate| { if trait_predicates.any(|predicate| {
let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst); let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst);
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate); let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
!cx.tcx !cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
.infer_ctxt()
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
}) { }) {
return false; return false;
} }

View File

@@ -138,10 +138,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
.. ..
} = { } = {
let mut ctx = MovedVariablesCtxt::default(); let mut ctx = MovedVariablesCtxt::default();
cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
.consume_body(body);
});
ctx ctx
}; };

View File

@@ -123,7 +123,7 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
} }
let mut s = S(hir::HirIdSet::default()); let mut s = S(hir::HirIdSet::default());
cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new( let mut v = ExprUseVisitor::new(
&mut s, &mut s,
&infcx, &infcx,
@@ -132,7 +132,6 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
cx.typeck_results(), cx.typeck_results(),
); );
v.consume_expr(e); v.consume_expr(e);
});
s.0 s.0
} }
@@ -156,7 +155,7 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
} }
let mut s = S(hir::HirIdSet::default()); let mut s = S(hir::HirIdSet::default());
cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new( let mut v = ExprUseVisitor::new(
&mut s, &mut s,
&infcx, &infcx,
@@ -165,6 +164,5 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
cx.typeck_results(), cx.typeck_results(),
); );
v.consume_expr(e); v.consume_expr(e);
});
s.0 s.0
} }

View File

@@ -821,10 +821,9 @@ pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'
}; };
let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id); let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id);
cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results()) ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
.consume_body(closure_body); .consume_body(closure_body);
});
if !visitor.suggestion_start.is_empty() { if !visitor.suggestion_start.is_empty() {
return Some(DerefClosure { return Some(DerefClosure {

View File

@@ -172,11 +172,10 @@ pub fn implements_trait_with_env<'tcx>(
return false; return false;
} }
let ty_params = tcx.mk_substs(ty_params.iter()); let ty_params = tcx.mk_substs(ty_params.iter());
tcx.infer_ctxt().enter(|infcx| { let infcx = tcx.infer_ctxt().build();
infcx infcx
.type_implements_trait(trait_id, ty, ty_params, param_env) .type_implements_trait(trait_id, ty, ty_params, param_env)
.must_apply_modulo_regions() .must_apply_modulo_regions()
})
} }
/// Checks whether this type implements `Drop`. /// Checks whether this type implements `Drop`.
@@ -242,9 +241,9 @@ fn is_normalizable_helper<'tcx>(
} }
// prevent recursive loops, false-negative is better than endless loop leading to stack overflow // prevent recursive loops, false-negative is better than endless loop leading to stack overflow
cache.insert(ty, false); cache.insert(ty, false);
let result = cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
let cause = rustc_middle::traits::ObligationCause::dummy(); let cause = rustc_middle::traits::ObligationCause::dummy();
if infcx.at(&cause, param_env).normalize(ty).is_ok() { let result = if infcx.at(&cause, param_env).normalize(ty).is_ok() {
match ty.kind() { match ty.kind() {
ty::Adt(def, substs) => def.variants().iter().all(|variant| { ty::Adt(def, substs) => def.variants().iter().all(|variant| {
variant variant
@@ -261,8 +260,7 @@ fn is_normalizable_helper<'tcx>(
} }
} else { } else {
false false
} };
});
cache.insert(ty, result); cache.insert(ty, result);
result result
} }

View File

@@ -18,7 +18,7 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
used_mutably: HirIdSet::default(), used_mutably: HirIdSet::default(),
skip: false, skip: false,
}; };
cx.tcx.infer_ctxt().enter(|infcx| { let infcx = cx.tcx.infer_ctxt().build();
ExprUseVisitor::new( ExprUseVisitor::new(
&mut delegate, &mut delegate,
&infcx, &infcx,
@@ -27,7 +27,6 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
cx.typeck_results(), cx.typeck_results(),
) )
.walk_expr(expr); .walk_expr(expr);
});
if delegate.skip { if delegate.skip {
return None; return None;