about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCameron Steffen <cam.steffen94@gmail.com>2022-09-19 22:03:59 -0500
committerCameron Steffen <cam.steffen94@gmail.com>2022-10-07 07:10:40 -0500
commit6819e85501348c6fab3c5d40d0e31d5c7d00bb6a (patch)
treec0252f097458ae5f6b84b9cbdf830b3f271c399e
parent3b328e704953e34de401166cd76ca062e21d83d8 (diff)
downloadrust-6819e85501348c6fab3c5d40d0e31d5c7d00bb6a.tar.gz
rust-6819e85501348c6fab3c5d40d0e31d5c7d00bb6a.zip
Change InferCtxtBuilder from enter to build
-rw-r--r--clippy_lints/src/dereference.rs14
-rw-r--r--clippy_lints/src/escape.rs5
-rw-r--r--clippy_lints/src/future_not_send.rs29
-rw-r--r--clippy_lints/src/loops/mut_range_bound.rs19
-rw-r--r--clippy_lints/src/methods/unnecessary_to_owned.rs4
-rw-r--r--clippy_lints/src/needless_pass_by_value.rs6
-rw-r--r--clippy_lints/src/operators/assign_op_pattern.rs38
-rw-r--r--clippy_utils/src/sugg.rs7
-rw-r--r--clippy_utils/src/ty.rs48
-rw-r--r--clippy_utils/src/usage.rs19
10 files changed, 87 insertions, 102 deletions
diff --git a/clippy_lints/src/dereference.rs b/clippy_lints/src/dereference.rs
index 3cd8f236e7a..02a16f765b7 100644
--- a/clippy_lints/src/dereference.rs
+++ b/clippy_lints/src/dereference.rs
@@ -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)
         })
     };
 
diff --git a/clippy_lints/src/escape.rs b/clippy_lints/src/escape.rs
index 2e608fe527f..eb0455ae404 100644
--- a/clippy_lints/src/escape.rs
+++ b/clippy_lints/src/escape.rs
@@ -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(
diff --git a/clippy_lints/src/future_not_send.rs b/clippy_lints/src/future_not_send.rs
index 406c842a6d0..0519f9ac246 100644
--- a/clippy_lints/src/future_not_send.rs
+++ b/clippy_lints/src/future_not_send.rs
@@ -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(),
+                                    ));
                                 }
-                            });
+                            }
                         },
                     );
                 }
diff --git a/clippy_lints/src/loops/mut_range_bound.rs b/clippy_lints/src/loops/mut_range_bound.rs
index 0ee42b61c9a..db73ab55b37 100644
--- a/clippy_lints/src/loops/mut_range_bound.rs
+++ b/clippy_lints/src/loops/mut_range_bound.rs
@@ -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()
 }
diff --git a/clippy_lints/src/methods/unnecessary_to_owned.rs b/clippy_lints/src/methods/unnecessary_to_owned.rs
index 9ab0d614114..6017941452c 100644
--- a/clippy_lints/src/methods/unnecessary_to_owned.rs
+++ b/clippy_lints/src/methods/unnecessary_to_owned.rs
@@ -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;
                         }
diff --git a/clippy_lints/src/needless_pass_by_value.rs b/clippy_lints/src/needless_pass_by_value.rs
index 178c973981b..7f881e27dd2 100644
--- a/clippy_lints/src/needless_pass_by_value.rs
+++ b/clippy_lints/src/needless_pass_by_value.rs
@@ -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
         };
 
diff --git a/clippy_lints/src/operators/assign_op_pattern.rs b/clippy_lints/src/operators/assign_op_pattern.rs
index 26bca7c306a..c7e964cf23e 100644
--- a/clippy_lints/src/operators/assign_op_pattern.rs
+++ b/clippy_lints/src/operators/assign_op_pattern.rs
@@ -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
 }
diff --git a/clippy_utils/src/sugg.rs b/clippy_utils/src/sugg.rs
index ef836e84829..3c5dd92b9cd 100644
--- a/clippy_utils/src/sugg.rs
+++ b/clippy_utils/src/sugg.rs
@@ -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 {
diff --git a/clippy_utils/src/ty.rs b/clippy_utils/src/ty.rs
index 934470bd135..a15daec7c3c 100644
--- a/clippy_utils/src/ty.rs
+++ b/clippy_utils/src/ty.rs
@@ -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
 }
diff --git a/clippy_utils/src/usage.rs b/clippy_utils/src/usage.rs
index b5ec3fef3e0..e32bae6ed1f 100644
--- a/clippy_utils/src/usage.rs
+++ b/clippy_utils/src/usage.rs
@@ -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;