Skip to content

Commit 319575a

Browse files
committed
Introduce EarlyBinder
1 parent ecd4495 commit 319575a

File tree

66 files changed

+340
-235
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

66 files changed

+340
-235
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use rustc_middle::mir::{
1313
FakeReadCause, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef,
1414
ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, VarBindingForm,
1515
};
16-
use rustc_middle::ty::{self, subst::Subst, suggest_constraining_type_params, PredicateKind, Ty};
16+
use rustc_middle::ty::{
17+
self, subst::Subst, suggest_constraining_type_params, EarlyBinder, PredicateKind, Ty,
18+
};
1719
use rustc_mir_dataflow::move_paths::{InitKind, MoveOutIndex, MovePathIndex};
1820
use rustc_span::symbol::sym;
1921
use rustc_span::{BytePos, Span};
@@ -336,7 +338,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
336338
let find_fn_kind_from_did = |predicates: &[(ty::Predicate<'tcx>, Span)], substs| {
337339
predicates.iter().find_map(|(pred, _)| {
338340
let pred = if let Some(substs) = substs {
339-
pred.subst(tcx, substs).kind().skip_binder()
341+
EarlyBinder(*pred).subst(tcx, substs).kind().skip_binder()
340342
} else {
341343
pred.kind().skip_binder()
342344
};

compiler/rustc_borrowck/src/universal_regions.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ use rustc_index::vec::{Idx, IndexVec};
2323
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
2424
use rustc_middle::ty::fold::TypeFoldable;
2525
use rustc_middle::ty::subst::{InternalSubsts, Subst, SubstsRef};
26-
use rustc_middle::ty::{self, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt};
26+
use rustc_middle::ty::{
27+
self, EarlyBinder, InlineConstSubsts, InlineConstSubstsParts, RegionVid, Ty, TyCtxt,
28+
};
2729
use std::iter;
2830

2931
use crate::nll::ToRegionVid;
@@ -477,8 +479,8 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
477479
.infcx
478480
.tcx
479481
.mk_region(ty::ReVar(self.infcx.next_nll_region_var(FR).to_region_vid()));
480-
let va_list_ty =
481-
self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]);
482+
let va_list_ty = EarlyBinder(self.infcx.tcx.type_of(va_list_did))
483+
.subst(self.infcx.tcx, &[region.into()]);
482484

483485
unnormalized_input_tys = self.infcx.tcx.mk_type_list(
484486
unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)),

compiler/rustc_const_eval/src/const_eval/eval_queries.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_middle::mir::pretty::display_allocation;
1313
use rustc_middle::traits::Reveal;
1414
use rustc_middle::ty::layout::LayoutOf;
1515
use rustc_middle::ty::print::with_no_trimmed_paths;
16-
use rustc_middle::ty::{self, subst::Subst, TyCtxt};
16+
use rustc_middle::ty::{self, subst::Subst, EarlyBinder, TyCtxt};
1717
use rustc_span::source_map::Span;
1818
use rustc_target::abi::{self, Abi};
1919
use std::borrow::Cow;
@@ -47,7 +47,7 @@ fn eval_body_using_ecx<'mir, 'tcx>(
4747
"Unexpected DefKind: {:?}",
4848
ecx.tcx.def_kind(cid.instance.def_id())
4949
);
50-
let layout = ecx.layout_of(body.return_ty().subst(tcx, cid.instance.substs))?;
50+
let layout = ecx.layout_of(EarlyBinder(body.return_ty()).subst(tcx, cid.instance.substs))?;
5151
assert!(!layout.is_unsized());
5252
let ret = ecx.allocate(layout, MemoryKind::Stack)?;
5353

compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use rustc_hir::lang_items::LangItem;
55
use rustc_middle::mir::TerminatorKind;
66
use rustc_middle::ty::layout::LayoutOf;
77
use rustc_middle::ty::subst::Subst;
8+
use rustc_middle::ty::EarlyBinder;
89
use rustc_span::{Span, Symbol};
910

1011
use crate::interpret::{
@@ -93,10 +94,10 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
9394
let col = if loc_details.column { Scalar::from_u32(col) } else { Scalar::from_u32(0) };
9495

9596
// Allocate memory for `CallerLocation` struct.
96-
let loc_ty = self
97-
.tcx
98-
.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None))
99-
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
97+
let loc_ty = EarlyBinder(
98+
self.tcx.type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None)),
99+
)
100+
.subst(*self.tcx, self.tcx.mk_substs([self.tcx.lifetimes.re_erased.into()].iter()));
100101
let loc_layout = self.layout_of(loc_ty).unwrap();
101102
// This can fail if rustc runs out of memory right here. Trying to emit an error would be
102103
// pointless, since that would require allocating more memory than a Location.

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ use rustc_middle::ty::{
7070
self,
7171
error::TypeError,
7272
subst::{GenericArgKind, Subst, SubstsRef},
73-
Binder, List, Region, Ty, TyCtxt, TypeFoldable,
73+
Binder, EarlyBinder, List, Region, Ty, TyCtxt, TypeFoldable,
7474
};
7575
use rustc_span::{sym, BytePos, DesugaringKind, Pos, Span};
7676
use rustc_target::spec::abi;
@@ -961,12 +961,14 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
961961
for (def_id, actual) in iter::zip(default_params, substs.iter().rev()) {
962962
match actual.unpack() {
963963
GenericArgKind::Const(c) => {
964-
if self.tcx.const_param_default(def_id).subst(self.tcx, substs) != c {
964+
if EarlyBinder(self.tcx.const_param_default(def_id)).subst(self.tcx, substs)
965+
!= c
966+
{
965967
break;
966968
}
967969
}
968970
GenericArgKind::Type(ty) => {
969-
if self.tcx.type_of(def_id).subst(self.tcx, substs) != ty {
971+
if EarlyBinder(self.tcx.type_of(def_id)).subst(self.tcx, substs) != ty {
970972
break;
971973
}
972974
}
@@ -1383,8 +1385,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13831385
}
13841386

13851387
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
1386-
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1);
1387-
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2);
1388+
let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
1389+
let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
13881390
let mut values = self.cmp_fn_sig(&sig1, &sig2);
13891391
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did1, substs1));
13901392
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did2, substs2));
@@ -1395,7 +1397,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13951397
}
13961398

13971399
(ty::FnDef(did1, substs1), ty::FnPtr(sig2)) => {
1398-
let sig1 = self.tcx.fn_sig(*did1).subst(self.tcx, substs1);
1400+
let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
13991401
let mut values = self.cmp_fn_sig(&sig1, sig2);
14001402
values.0.push_highlighted(format!(
14011403
" {{{}}}",
@@ -1405,7 +1407,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14051407
}
14061408

14071409
(ty::FnPtr(sig1), ty::FnDef(did2, substs2)) => {
1408-
let sig2 = self.tcx.fn_sig(*did2).subst(self.tcx, substs2);
1410+
let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
14091411
let mut values = self.cmp_fn_sig(sig1, &sig2);
14101412
values.1.push_normal(format!(
14111413
" {{{}}}",
@@ -1850,7 +1852,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
18501852
let bounds = self.tcx.explicit_item_bounds(*def_id);
18511853

18521854
for (predicate, _) in bounds {
1853-
let predicate = predicate.subst(self.tcx, substs);
1855+
let predicate = EarlyBinder(*predicate).subst(self.tcx, substs);
18541856
let output = predicate
18551857
.kind()
18561858
.map_bound(|kind| match kind {

compiler/rustc_infer/src/infer/opaque_types.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::traits::ObligationCause;
99
use rustc_middle::ty::fold::BottomUpFolder;
1010
use rustc_middle::ty::subst::{GenericArgKind, Subst};
1111
use rustc_middle::ty::{
12-
self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitor,
12+
self, EarlyBinder, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitor,
1313
};
1414
use rustc_span::Span;
1515

@@ -565,7 +565,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
565565

566566
for (predicate, _) in item_bounds {
567567
debug!(?predicate);
568-
let predicate = predicate.subst(tcx, substs);
568+
let predicate = EarlyBinder(*predicate).subst(tcx, substs);
569569

570570
let predicate = predicate.fold_with(&mut BottomUpFolder {
571571
tcx,

compiler/rustc_infer/src/infer/outlives/verify.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use rustc_data_structures::captures::Captures;
44
use rustc_data_structures::sso::SsoHashSet;
55
use rustc_hir::def_id::DefId;
66
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
7-
use rustc_middle::ty::{self, Ty, TyCtxt};
7+
use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt};
88

99
/// The `TypeOutlives` struct has the job of "lowering" a `T: 'a`
1010
/// obligation into a series of `'a: 'b` constraints and "verifys", as
@@ -290,7 +290,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
290290
debug!("projection_bounds(projection_ty={:?})", projection_ty);
291291
let tcx = self.tcx;
292292
self.region_bounds_declared_on_associated_item(projection_ty.item_def_id)
293-
.map(move |r| r.subst(tcx, projection_ty.substs))
293+
.map(move |r| EarlyBinder(r).subst(tcx, projection_ty.substs))
294294
}
295295

296296
/// Given the `DefId` of an associated item, returns any region

compiler/rustc_middle/src/mir/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::ty::codec::{TyDecoder, TyEncoder};
1010
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeVisitor};
1111
use crate::ty::print::{FmtPrinter, Printer};
1212
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
13-
use crate::ty::{self, List, Ty, TyCtxt};
13+
use crate::ty::{self, EarlyBinder, List, Ty, TyCtxt};
1414
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
1515

1616
use rustc_errors::ErrorGuaranteed;
@@ -2387,7 +2387,7 @@ impl<'tcx> Operand<'tcx> {
23872387
substs: SubstsRef<'tcx>,
23882388
span: Span,
23892389
) -> Self {
2390-
let ty = tcx.type_of(def_id).subst(tcx, substs);
2390+
let ty = EarlyBinder(tcx.type_of(def_id)).subst(tcx, substs);
23912391
Operand::Constant(Box::new(Constant {
23922392
span,
23932393
user_ty: None,

compiler/rustc_middle/src/mir/tcx.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
use crate::mir::*;
77
use crate::ty::subst::Subst;
8-
use crate::ty::{self, Ty, TyCtxt};
8+
use crate::ty::{self, EarlyBinder, Ty, TyCtxt};
99
use rustc_hir as hir;
1010
use rustc_target::abi::VariantIdx;
1111

@@ -202,7 +202,9 @@ impl<'tcx> Rvalue<'tcx> {
202202
Rvalue::Aggregate(ref ak, ref ops) => match **ak {
203203
AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64),
204204
AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))),
205-
AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs),
205+
AggregateKind::Adt(did, _, substs, _, _) => {
206+
EarlyBinder(tcx.type_of(did)).subst(tcx, substs)
207+
}
206208
AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs),
207209
AggregateKind::Generator(did, substs, movability) => {
208210
tcx.mk_generator(did, substs, movability)

compiler/rustc_middle/src/ty/context.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,11 @@ use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, Substs
1919
use crate::ty::TyKind::*;
2020
use crate::ty::{
2121
self, AdtDef, AdtDefData, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig,
22-
ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, ExistentialPredicate, FloatTy,
23-
FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid, List,
24-
ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy, Region,
25-
RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy,
22+
ClosureSizeProfileData, Const, ConstS, ConstVid, DefIdTree, EarlyBinder, ExistentialPredicate,
23+
FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy, IntTy, IntVar, IntVid,
24+
List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateKind, PredicateS, ProjectionTy,
25+
Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut,
26+
UintTy,
2627
};
2728
use rustc_ast as ast;
2829
use rustc_data_structures::fingerprint::Fingerprint;
@@ -1604,7 +1605,7 @@ impl<'tcx> TyCtxt<'tcx> {
16041605
pub fn caller_location_ty(self) -> Ty<'tcx> {
16051606
self.mk_imm_ref(
16061607
self.lifetimes.re_static,
1607-
self.type_of(self.require_lang_item(LangItem::PanicLocation, None))
1608+
EarlyBinder(self.type_of(self.require_lang_item(LangItem::PanicLocation, None)))
16081609
.subst(self, self.mk_substs([self.lifetimes.re_static.into()].iter())),
16091610
)
16101611
}
@@ -2333,7 +2334,7 @@ impl<'tcx> TyCtxt<'tcx> {
23332334
ty_param.into()
23342335
} else {
23352336
assert!(has_default);
2336-
self.type_of(param.def_id).subst(self, substs).into()
2337+
EarlyBinder(self.type_of(param.def_id)).subst(self, substs).into()
23372338
}
23382339
}
23392340
});

0 commit comments

Comments
 (0)