Skip to content

Commit 198c70d

Browse files
committed
Auto merge of rust-lang#96883 - jackh726:early-binder-2, r=oli-obk
Add EarlyBinder Chalk has no concept of `Param` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L579) or `ReEarlyBound` (https://github.com/rust-lang/chalk/blob/e0ade19d139bc784384acc6736cd960c91dd55a1/chalk-ir/src/lib.rs#L1308). Everything is just "bound" - the equivalent of rustc's late-bound. It's not completely clear yet whether to move everything to the same time of binder in rustc or add `Param` and `ReEarlyBound` in Chalk. Either way, tracking when we have or haven't already substituted out these in rustc can be helpful. As a first step, I'm just adding a `EarlyBinder` newtype that is required to call `subst`. I also add a couple "transparent" `bound_*` wrappers around a couple query that are often immediately substituted. r? `@nikomatsakis`
2 parents 7161a70 + 6dab55c commit 198c70d

File tree

6 files changed

+8
-8
lines changed

6 files changed

+8
-8
lines changed

clippy_lints/src/eta_reduction.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ impl<'tcx> LateLintPass<'tcx> for EtaReduction {
150150
if check_inputs(cx, body.params, args);
151151
let method_def_id = cx.typeck_results().type_dependent_def_id(body.value.hir_id).unwrap();
152152
let substs = cx.typeck_results().node_substs(body.value.hir_id);
153-
let call_ty = cx.tcx.type_of(method_def_id).subst(cx.tcx, substs);
153+
let call_ty = cx.tcx.bound_type_of(method_def_id).subst(cx.tcx, substs);
154154
if check_sig(cx, closure_ty, call_ty);
155155
then {
156156
span_lint_and_then(cx, REDUNDANT_CLOSURE_FOR_METHOD_CALLS, expr.span, "redundant closure", |diag| {

clippy_lints/src/future_not_send.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use rustc_hir::{Body, FnDecl, HirId};
55
use rustc_infer::infer::TyCtxtInferExt;
66
use rustc_lint::{LateContext, LateLintPass};
77
use rustc_middle::ty::subst::Subst;
8-
use rustc_middle::ty::{Opaque, PredicateKind::Trait};
8+
use rustc_middle::ty::{EarlyBinder, Opaque, PredicateKind::Trait};
99
use rustc_session::{declare_lint_pass, declare_tool_lint};
1010
use rustc_span::{sym, Span};
1111
use rustc_trait_selection::traits::error_reporting::suggestions::InferCtxtExt;
@@ -67,7 +67,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
6767
let preds = cx.tcx.explicit_item_bounds(id);
6868
let mut is_future = false;
6969
for &(p, _span) in preds {
70-
let p = p.subst(cx.tcx, subst);
70+
let p = EarlyBinder(p).subst(cx.tcx, subst);
7171
if let Some(trait_pred) = p.to_opt_poly_trait_pred() {
7272
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
7373
is_future = true;

clippy_lints/src/mut_reference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
4848
ExprKind::MethodCall(path, arguments, _) => {
4949
let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap();
5050
let substs = cx.typeck_results().node_substs(e.hir_id);
51-
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
51+
let method_type = cx.tcx.bound_type_of(def_id).subst(cx.tcx, substs);
5252
check_arguments(cx, arguments, method_type, path.ident.as_str(), "method");
5353
},
5454
_ => (),

clippy_lints/src/transmute/transmute_undefined_repr.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ fn reduce_ty<'tcx>(cx: &LateContext<'tcx>, mut ty: Ty<'tcx>) -> ReducedTy<'tcx>
307307
.non_enum_variant()
308308
.fields
309309
.iter()
310-
.map(|f| cx.tcx.type_of(f.did).subst(cx.tcx, substs));
310+
.map(|f| cx.tcx.bound_type_of(f.did).subst(cx.tcx, substs));
311311
let Some(sized_ty) = iter.find(|&ty| !is_zero_sized_ty(cx, ty)) else {
312312
return ReducedTy::TypeErasure;
313313
};

clippy_utils/src/consts.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, Item, ItemKind,
99
use rustc_lint::LateContext;
1010
use rustc_middle::mir::interpret::Scalar;
1111
use rustc_middle::ty::subst::{Subst, SubstsRef};
12-
use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt};
12+
use rustc_middle::ty::{self, EarlyBinder, FloatTy, ScalarInt, Ty, TyCtxt};
1313
use rustc_middle::{bug, span_bug};
1414
use rustc_span::symbol::Symbol;
1515
use std::cmp::Ordering::{self, Equal};
@@ -420,7 +420,7 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
420420
let substs = if self.substs.is_empty() {
421421
substs
422422
} else {
423-
substs.subst(self.lcx.tcx, self.substs)
423+
EarlyBinder(substs).subst(self.lcx.tcx, self.substs)
424424
};
425425

426426
let result = self

clippy_utils/src/ty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<ExprFnS
520520
let ty = cx.typeck_results().expr_ty_adjusted(expr).peel_refs();
521521
match *ty.kind() {
522522
ty::Closure(_, subs) => Some(ExprFnSig::Closure(subs.as_closure().sig())),
523-
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.fn_sig(id).subst(cx.tcx, subs))),
523+
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs))),
524524
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig)),
525525
ty::Dynamic(bounds, _) => {
526526
let lang_items = cx.tcx.lang_items();

0 commit comments

Comments
 (0)