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`
arg_ty
} && impl_ty.is_ref()
&& cx.tcx.infer_ctxt().enter(|infcx|
infcx
&& let infcx = cx.tcx.infer_ctxt().build()
&& infcx
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
.must_apply_modulo_regions()
)
{
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 obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
cx.tcx
.infer_ctxt()
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
let infcx = cx.tcx.infer_ctxt().build();
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);
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);
});
for node in v.set {
span_lint_hir(

View file

@ -77,10 +77,9 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
if is_future {
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
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);
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() {
span_lint_and_then(
cx,
@ -88,9 +87,10 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
span,
"future cannot be sent between threads safely",
|db| {
cx.tcx.infer_ctxt().enter(|infcx| {
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() {
db.note(&format!(
"`{}` 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_high: None,
};
cx.tcx.infer_ctxt().enter(|infcx| {
let infcx = cx.tcx.infer_ctxt().build();
ExprUseVisitor::new(
&mut delegate,
&infcx,
@ -74,7 +74,6 @@ fn check_for_mutation<'tcx>(
cx.typeck_results(),
)
.walk_expr(body);
});
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| {
let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst);
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
!cx.tcx
.infer_ctxt()
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
!cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
}) {
return false;
}

View file

@ -138,10 +138,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
..
} = {
let mut ctx = MovedVariablesCtxt::default();
cx.tcx.infer_ctxt().enter(|infcx| {
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
.consume_body(body);
});
let infcx = cx.tcx.infer_ctxt().build();
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
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());
cx.tcx.infer_ctxt().enter(|infcx| {
let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new(
&mut s,
&infcx,
@ -132,7 +132,6 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
cx.typeck_results(),
);
v.consume_expr(e);
});
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());
cx.tcx.infer_ctxt().enter(|infcx| {
let infcx = cx.tcx.infer_ctxt().build();
let mut v = ExprUseVisitor::new(
&mut s,
&infcx,
@ -165,6 +164,5 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
cx.typeck_results(),
);
v.consume_expr(e);
});
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);
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())
.consume_body(closure_body);
});
if !visitor.suggestion_start.is_empty() {
return Some(DerefClosure {

View file

@ -172,11 +172,10 @@ pub fn implements_trait_with_env<'tcx>(
return false;
}
let ty_params = tcx.mk_substs(ty_params.iter());
tcx.infer_ctxt().enter(|infcx| {
let infcx = tcx.infer_ctxt().build();
infcx
.type_implements_trait(trait_id, ty, ty_params, param_env)
.must_apply_modulo_regions()
})
}
/// 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
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();
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() {
ty::Adt(def, substs) => def.variants().iter().all(|variant| {
variant
@ -261,8 +260,7 @@ fn is_normalizable_helper<'tcx>(
}
} else {
false
}
});
};
cache.insert(ty, result);
result
}

View file

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