Skip to content

Commit 6819e85

Browse files
committed
Change InferCtxtBuilder from enter to build
1 parent 3b328e7 commit 6819e85

File tree

10 files changed

+87
-102
lines changed

10 files changed

+87
-102
lines changed

clippy_lints/src/dereference.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -831,11 +831,10 @@ fn walk_parents<'tcx>(
831831
// Trait methods taking `self`
832832
arg_ty
833833
} && impl_ty.is_ref()
834-
&& cx.tcx.infer_ctxt().enter(|infcx|
835-
infcx
836-
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
837-
.must_apply_modulo_regions()
838-
)
834+
&& let infcx = cx.tcx.infer_ctxt().build()
835+
&& infcx
836+
.type_implements_trait(trait_id, impl_ty, subs, cx.param_env)
837+
.must_apply_modulo_regions()
839838
{
840839
return Some(Position::MethodReceiverRefImpl)
841840
}
@@ -1119,9 +1118,8 @@ fn needless_borrow_impl_arg_position<'tcx>(
11191118

11201119
let predicate = EarlyBinder(predicate).subst(cx.tcx, &substs_with_referent_ty);
11211120
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
1122-
cx.tcx
1123-
.infer_ctxt()
1124-
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
1121+
let infcx = cx.tcx.infer_ctxt().build();
1122+
infcx.predicate_must_hold_modulo_regions(&obligation)
11251123
})
11261124
};
11271125

clippy_lints/src/escape.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,8 @@ impl<'tcx> LateLintPass<'tcx> for BoxedLocal {
106106
};
107107

108108
let fn_def_id = cx.tcx.hir().local_def_id(hir_id);
109-
cx.tcx.infer_ctxt().enter(|infcx| {
110-
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
111-
});
109+
let infcx = cx.tcx.infer_ctxt().build();
110+
ExprUseVisitor::new(&mut v, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
112111

113112
for node in v.set {
114113
span_lint_hir(

clippy_lints/src/future_not_send.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -77,29 +77,28 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
7777
if is_future {
7878
let send_trait = cx.tcx.get_diagnostic_item(sym::Send).unwrap();
7979
let span = decl.output.span();
80-
let send_errors = cx.tcx.infer_ctxt().enter(|infcx| {
81-
let cause = traits::ObligationCause::misc(span, hir_id);
82-
traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait)
83-
});
80+
let infcx = cx.tcx.infer_ctxt().build();
81+
let cause = traits::ObligationCause::misc(span, hir_id);
82+
let send_errors = traits::fully_solve_bound(&infcx, cause, cx.param_env, ret_ty, send_trait);
8483
if !send_errors.is_empty() {
8584
span_lint_and_then(
8685
cx,
8786
FUTURE_NOT_SEND,
8887
span,
8988
"future cannot be sent between threads safely",
9089
|db| {
91-
cx.tcx.infer_ctxt().enter(|infcx| {
92-
for FulfillmentError { obligation, .. } in send_errors {
93-
infcx.err_ctxt().maybe_note_obligation_cause_for_async_await(db, &obligation);
94-
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
95-
db.note(&format!(
96-
"`{}` doesn't implement `{}`",
97-
trait_pred.self_ty(),
98-
trait_pred.trait_ref.print_only_trait_path(),
99-
));
100-
}
90+
for FulfillmentError { obligation, .. } in send_errors {
91+
infcx
92+
.err_ctxt()
93+
.maybe_note_obligation_cause_for_async_await(db, &obligation);
94+
if let Trait(trait_pred) = obligation.predicate.kind().skip_binder() {
95+
db.note(&format!(
96+
"`{}` doesn't implement `{}`",
97+
trait_pred.self_ty(),
98+
trait_pred.trait_ref.print_only_trait_path(),
99+
));
101100
}
102-
});
101+
}
103102
},
104103
);
105104
}

clippy_lints/src/loops/mut_range_bound.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,15 @@ fn check_for_mutation<'tcx>(
6565
span_low: None,
6666
span_high: None,
6767
};
68-
cx.tcx.infer_ctxt().enter(|infcx| {
69-
ExprUseVisitor::new(
70-
&mut delegate,
71-
&infcx,
72-
body.hir_id.owner.def_id,
73-
cx.param_env,
74-
cx.typeck_results(),
75-
)
76-
.walk_expr(body);
77-
});
68+
let infcx = cx.tcx.infer_ctxt().build();
69+
ExprUseVisitor::new(
70+
&mut delegate,
71+
&infcx,
72+
body.hir_id.owner.def_id,
73+
cx.param_env,
74+
cx.typeck_results(),
75+
)
76+
.walk_expr(body);
7877

7978
delegate.mutation_span()
8079
}

clippy_lints/src/methods/unnecessary_to_owned.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -420,9 +420,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty<
420420
if trait_predicates.any(|predicate| {
421421
let predicate = EarlyBinder(predicate).subst(cx.tcx, new_subst);
422422
let obligation = Obligation::new(ObligationCause::dummy(), cx.param_env, predicate);
423-
!cx.tcx
424-
.infer_ctxt()
425-
.enter(|infcx| infcx.predicate_must_hold_modulo_regions(&obligation))
423+
!cx.tcx.infer_ctxt().build().predicate_must_hold_modulo_regions(&obligation)
426424
}) {
427425
return false;
428426
}

clippy_lints/src/needless_pass_by_value.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ impl<'tcx> LateLintPass<'tcx> for NeedlessPassByValue {
138138
..
139139
} = {
140140
let mut ctx = MovedVariablesCtxt::default();
141-
cx.tcx.infer_ctxt().enter(|infcx| {
142-
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
143-
.consume_body(body);
144-
});
141+
let infcx = cx.tcx.infer_ctxt().build();
142+
euv::ExprUseVisitor::new(&mut ctx, &infcx, fn_def_id, cx.param_env, cx.typeck_results()).consume_body(body);
145143
ctx
146144
};
147145

clippy_lints/src/operators/assign_op_pattern.rs

+18-20
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,15 @@ fn imm_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
123123
}
124124

125125
let mut s = S(hir::HirIdSet::default());
126-
cx.tcx.infer_ctxt().enter(|infcx| {
127-
let mut v = ExprUseVisitor::new(
128-
&mut s,
129-
&infcx,
130-
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
131-
cx.param_env,
132-
cx.typeck_results(),
133-
);
134-
v.consume_expr(e);
135-
});
126+
let infcx = cx.tcx.infer_ctxt().build();
127+
let mut v = ExprUseVisitor::new(
128+
&mut s,
129+
&infcx,
130+
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
131+
cx.param_env,
132+
cx.typeck_results(),
133+
);
134+
v.consume_expr(e);
136135
s.0
137136
}
138137

@@ -156,15 +155,14 @@ fn mut_borrows_in_expr(cx: &LateContext<'_>, e: &hir::Expr<'_>) -> hir::HirIdSet
156155
}
157156

158157
let mut s = S(hir::HirIdSet::default());
159-
cx.tcx.infer_ctxt().enter(|infcx| {
160-
let mut v = ExprUseVisitor::new(
161-
&mut s,
162-
&infcx,
163-
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
164-
cx.param_env,
165-
cx.typeck_results(),
166-
);
167-
v.consume_expr(e);
168-
});
158+
let infcx = cx.tcx.infer_ctxt().build();
159+
let mut v = ExprUseVisitor::new(
160+
&mut s,
161+
&infcx,
162+
cx.tcx.hir().body_owner_def_id(cx.enclosing_body.unwrap()),
163+
cx.param_env,
164+
cx.typeck_results(),
165+
);
166+
v.consume_expr(e);
169167
s.0
170168
}

clippy_utils/src/sugg.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -821,10 +821,9 @@ pub fn deref_closure_args<'tcx>(cx: &LateContext<'_>, closure: &'tcx hir::Expr<'
821821
};
822822

823823
let fn_def_id = cx.tcx.hir().local_def_id(closure.hir_id);
824-
cx.tcx.infer_ctxt().enter(|infcx| {
825-
ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
826-
.consume_body(closure_body);
827-
});
824+
let infcx = cx.tcx.infer_ctxt().build();
825+
ExprUseVisitor::new(&mut visitor, &infcx, fn_def_id, cx.param_env, cx.typeck_results())
826+
.consume_body(closure_body);
828827

829828
if !visitor.suggestion_start.is_empty() {
830829
return Some(DerefClosure {

clippy_utils/src/ty.rs

+23-25
Original file line numberDiff line numberDiff line change
@@ -172,11 +172,10 @@ pub fn implements_trait_with_env<'tcx>(
172172
return false;
173173
}
174174
let ty_params = tcx.mk_substs(ty_params.iter());
175-
tcx.infer_ctxt().enter(|infcx| {
176-
infcx
177-
.type_implements_trait(trait_id, ty, ty_params, param_env)
178-
.must_apply_modulo_regions()
179-
})
175+
let infcx = tcx.infer_ctxt().build();
176+
infcx
177+
.type_implements_trait(trait_id, ty, ty_params, param_env)
178+
.must_apply_modulo_regions()
180179
}
181180

182181
/// Checks whether this type implements `Drop`.
@@ -242,27 +241,26 @@ fn is_normalizable_helper<'tcx>(
242241
}
243242
// prevent recursive loops, false-negative is better than endless loop leading to stack overflow
244243
cache.insert(ty, false);
245-
let result = cx.tcx.infer_ctxt().enter(|infcx| {
246-
let cause = rustc_middle::traits::ObligationCause::dummy();
247-
if infcx.at(&cause, param_env).normalize(ty).is_ok() {
248-
match ty.kind() {
249-
ty::Adt(def, substs) => def.variants().iter().all(|variant| {
250-
variant
251-
.fields
252-
.iter()
253-
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
254-
}),
255-
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
256-
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
257-
is_normalizable_helper(cx, param_env, inner_ty, cache)
258-
},
259-
_ => true, // if inner_ty == ty, we've already checked it
260-
}),
261-
}
262-
} else {
263-
false
244+
let infcx = cx.tcx.infer_ctxt().build();
245+
let cause = rustc_middle::traits::ObligationCause::dummy();
246+
let result = if infcx.at(&cause, param_env).normalize(ty).is_ok() {
247+
match ty.kind() {
248+
ty::Adt(def, substs) => def.variants().iter().all(|variant| {
249+
variant
250+
.fields
251+
.iter()
252+
.all(|field| is_normalizable_helper(cx, param_env, field.ty(cx.tcx, substs), cache))
253+
}),
254+
_ => ty.walk().all(|generic_arg| match generic_arg.unpack() {
255+
GenericArgKind::Type(inner_ty) if inner_ty != ty => {
256+
is_normalizable_helper(cx, param_env, inner_ty, cache)
257+
},
258+
_ => true, // if inner_ty == ty, we've already checked it
259+
}),
264260
}
265-
});
261+
} else {
262+
false
263+
};
266264
cache.insert(ty, result);
267265
result
268266
}

clippy_utils/src/usage.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,15 @@ pub fn mutated_variables<'tcx>(expr: &'tcx Expr<'_>, cx: &LateContext<'tcx>) ->
1818
used_mutably: HirIdSet::default(),
1919
skip: false,
2020
};
21-
cx.tcx.infer_ctxt().enter(|infcx| {
22-
ExprUseVisitor::new(
23-
&mut delegate,
24-
&infcx,
25-
expr.hir_id.owner.def_id,
26-
cx.param_env,
27-
cx.typeck_results(),
28-
)
29-
.walk_expr(expr);
30-
});
21+
let infcx = cx.tcx.infer_ctxt().build();
22+
ExprUseVisitor::new(
23+
&mut delegate,
24+
&infcx,
25+
expr.hir_id.owner.def_id,
26+
cx.param_env,
27+
cx.typeck_results(),
28+
)
29+
.walk_expr(expr);
3130

3231
if delegate.skip {
3332
return None;

0 commit comments

Comments
 (0)