mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 07:00:55 +00:00
Change InferCtxtBuilder from enter to build
This commit is contained in:
parent
3b328e7049
commit
6819e85501
10 changed files with 87 additions and 102 deletions
|
@ -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
|
||||
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
|
||||
.must_apply_modulo_regions()
|
||||
)
|
||||
&& 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)
|
||||
})
|
||||
};
|
||||
|
||||
|
|
|
@ -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| {
|
||||
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
|
||||
});
|
||||
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(
|
||||
|
|
|
@ -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 cause = traits::ObligationCause::misc(span, hir_id);
|
||||
traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait)
|
||||
});
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
let cause = traits::ObligationCause::misc(span, hir_id);
|
||||
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,18 +87,18 @@ 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);
|
||||
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
|
||||
db.note(&format!(
|
||||
"`{}` doesn't implement `{}`",
|
||||
trait_pred.self_ty(),
|
||||
trait_pred.trait_ref.print_only_trait_path(),
|
||||
));
|
||||
}
|
||||
for FulfillmentError { obligation, .. } in send_errors {
|
||||
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 `{}`",
|
||||
trait_pred.self_ty(),
|
||||
trait_pred.trait_ref.print_only_trait_path(),
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
|
|
@ -65,16 +65,15 @@ fn check_for_mutation<'tcx>(
|
|||
span_low: None,
|
||||
span_high: None,
|
||||
};
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
ExprUseVisitor::new(
|
||||
&mut delegate,
|
||||
&infcx,
|
||||
body.hir_id.owner.def_id,
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
)
|
||||
.walk_expr(body);
|
||||
});
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
ExprUseVisitor::new(
|
||||
&mut delegate,
|
||||
&infcx,
|
||||
body.hir_id.owner.def_id,
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
)
|
||||
.walk_expr(body);
|
||||
|
||||
delegate.mutation_span()
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
||||
|
|
|
@ -123,16 +123,15 @@ 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 mut v = ExprUseVisitor::new(
|
||||
&mut s,
|
||||
&infcx,
|
||||
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
);
|
||||
v.consume_expr(e);
|
||||
});
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
let mut v = ExprUseVisitor::new(
|
||||
&mut s,
|
||||
&infcx,
|
||||
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
);
|
||||
v.consume_expr(e);
|
||||
s.0
|
||||
}
|
||||
|
||||
|
@ -156,15 +155,14 @@ 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 mut v = ExprUseVisitor::new(
|
||||
&mut s,
|
||||
&infcx,
|
||||
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
);
|
||||
v.consume_expr(e);
|
||||
});
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
let mut v = ExprUseVisitor::new(
|
||||
&mut s,
|
||||
&infcx,
|
||||
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
);
|
||||
v.consume_expr(e);
|
||||
s.0
|
||||
}
|
||||
|
|
|
@ -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| {
|
||||
ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
|
||||
.consume_body(closure_body);
|
||||
});
|
||||
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 {
|
||||
|
|
|
@ -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| {
|
||||
infcx
|
||||
.type_implements_trait(trait_id, ty, ty_params, param_env)
|
||||
.must_apply_modulo_regions()
|
||||
})
|
||||
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,27 +241,26 @@ 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 cause = rustc_middle::traits::ObligationCause::dummy();
|
||||
if infcx.at(&cause, param_env).normalize(ty).is_ok() {
|
||||
match ty.kind() {
|
||||
ty::Adt(def, substs) => def.variants().iter().all(|variant| {
|
||||
variant
|
||||
.fields
|
||||
.iter()
|
||||
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
|
||||
}),
|
||||
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
|
||||
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
|
||||
is_normalizable_helper(cx, param_env, inner_ty, cache)
|
||||
},
|
||||
_ => true, // if inner_ty == ty, we've already checked it
|
||||
}),
|
||||
}
|
||||
} else {
|
||||
false
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
let cause = rustc_middle::traits::ObligationCause::dummy();
|
||||
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
|
||||
.fields
|
||||
.iter()
|
||||
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
|
||||
}),
|
||||
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
|
||||
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
|
||||
is_normalizable_helper(cx, param_env, inner_ty, cache)
|
||||
},
|
||||
_ => true, // if inner_ty == ty, we've already checked it
|
||||
}),
|
||||
}
|
||||
});
|
||||
} else {
|
||||
false
|
||||
};
|
||||
cache.insert(ty, result);
|
||||
result
|
||||
}
|
||||
|
|
|
@ -18,16 +18,15 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
|
|||
used_mutably: HirIdSet::default(),
|
||||
skip: false,
|
||||
};
|
||||
cx.tcx.infer_ctxt().enter(|infcx| {
|
||||
ExprUseVisitor::new(
|
||||
&mut delegate,
|
||||
&infcx,
|
||||
expr.hir_id.owner.def_id,
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
)
|
||||
.walk_expr(expr);
|
||||
});
|
||||
let infcx = cx.tcx.infer_ctxt().build();
|
||||
ExprUseVisitor::new(
|
||||
&mut delegate,
|
||||
&infcx,
|
||||
expr.hir_id.owner.def_id,
|
||||
cx.param_env,
|
||||
cx.typeck_results(),
|
||||
)
|
||||
.walk_expr(expr);
|
||||
|
||||
if delegate.skip {
|
||||
return None;
|
||||
|
|
Loading…
Reference in a new issue