Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 4955d75

Browse files
committed
Some rebinds and dummys
1 parent a5029ac commit 4955d75

File tree

9 files changed

+29
-20
lines changed

9 files changed

+29
-20
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ impl<'a, 'tcx> CombineFields<'a, 'tcx> {
5050

5151
debug!("higher_ranked_sub: OK result={:?}", result);
5252

53-
Ok(ty::Binder::bind(result))
53+
// We related `a_prime` and `b_prime`, which just had any bound vars
54+
// replaced with placeholders or infer vars, respectively. Relating
55+
// them should not introduce new bound vars.
56+
Ok(ty::Binder::dummy(result))
5457
})
5558
}
5659
}

compiler/rustc_middle/src/ty/relate.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -619,10 +619,9 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List<ty::Binder<ty::ExistentialPredicate<'
619619
let v = iter::zip(a_v, b_v).map(|(ep_a, ep_b)| {
620620
use crate::ty::ExistentialPredicate::*;
621621
match (ep_a.skip_binder(), ep_b.skip_binder()) {
622-
(Trait(a), Trait(b)) => Ok(ty::Binder::bind(Trait(
623-
relation.relate(ep_a.rebind(a), ep_b.rebind(b))?.skip_binder(),
624-
))),
625-
(Projection(a), Projection(b)) => Ok(ty::Binder::bind(Projection(
622+
(Trait(a), Trait(b)) => Ok(ep_a
623+
.rebind(Trait(relation.relate(ep_a.rebind(a), ep_b.rebind(b))?.skip_binder()))),
624+
(Projection(a), Projection(b)) => Ok(ep_a.rebind(Projection(
626625
relation.relate(ep_a.rebind(a), ep_b.rebind(b))?.skip_binder(),
627626
))),
628627
(AutoTrait(a), AutoTrait(b)) if a == b => Ok(ep_a.rebind(AutoTrait(a))),

compiler/rustc_mir/src/borrow_check/type_check/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2028,7 +2028,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20282028
traits::ObligationCauseCode::RepeatVec(is_const_fn),
20292029
),
20302030
self.param_env,
2031-
ty::Binder::bind(ty::TraitRef::new(
2031+
ty::Binder::dummy(ty::TraitRef::new(
20322032
self.tcx().require_lang_item(
20332033
LangItem::Copy,
20342034
Some(self.last_span),

compiler/rustc_mir/src/monomorphize/mod.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
use rustc_middle::traits;
22
use rustc_middle::ty::adjustment::CustomCoerceUnsized;
3-
use rustc_middle::ty::{self, Ty, TyCtxt};
3+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
44

55
use rustc_hir::lang_items::LangItem;
66

77
pub mod collector;
88
pub mod partitioning;
99
pub mod polymorphize;
1010

11-
pub fn custom_coerce_unsize_info<'tcx>(
11+
fn custom_coerce_unsize_info<'tcx>(
1212
tcx: TyCtxt<'tcx>,
1313
source_ty: Ty<'tcx>,
1414
target_ty: Ty<'tcx>,
1515
) -> CustomCoerceUnsized {
1616
let def_id = tcx.require_lang_item(LangItem::CoerceUnsized, None);
1717

18-
let trait_ref = ty::Binder::bind(ty::TraitRef {
18+
debug_assert!(!source_ty.has_escaping_bound_vars());
19+
debug_assert!(!target_ty.has_escaping_bound_vars());
20+
let trait_ref = ty::Binder::dummy(ty::TraitRef {
1921
def_id,
2022
substs: tcx.mk_substs_trait(source_ty, &[target_ty.into()]),
2123
});

compiler/rustc_trait_selection/src/traits/auto_trait.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,10 @@ impl<'tcx> AutoTraitFinder<'tcx> {
8282
) -> AutoTraitResult<A> {
8383
let tcx = self.tcx;
8484

85+
debug_assert!(!ty.has_escaping_bound_vars());
8586
let trait_ref = ty::TraitRef { def_id: trait_did, substs: tcx.mk_substs_trait(ty, &[]) };
8687

87-
let trait_pred = ty::Binder::bind(trait_ref);
88+
let trait_pred = ty::Binder::dummy(trait_ref);
8889

8990
let bail_out = tcx.infer_ctxt().enter(|infcx| {
9091
let mut selcx = SelectionContext::with_negative(&infcx, true);
@@ -280,7 +281,7 @@ impl AutoTraitFinder<'tcx> {
280281

281282
let mut already_visited = FxHashSet::default();
282283
let mut predicates = VecDeque::new();
283-
predicates.push_back(ty::Binder::bind(ty::TraitPredicate {
284+
predicates.push_back(ty::Binder::dummy(ty::TraitPredicate {
284285
trait_ref: ty::TraitRef {
285286
def_id: trait_did,
286287
substs: infcx.tcx.mk_substs_trait(ty, &[]),

compiler/rustc_trait_selection/src/traits/object_safety.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -757,7 +757,7 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
757757
struct IllegalSelfTypeVisitor<'tcx> {
758758
tcx: TyCtxt<'tcx>,
759759
trait_def_id: DefId,
760-
supertraits: Option<Vec<ty::PolyTraitRef<'tcx>>>,
760+
supertraits: Option<Vec<DefId>>,
761761
}
762762

763763
impl<'tcx> TypeVisitor<'tcx> for IllegalSelfTypeVisitor<'tcx> {
@@ -778,8 +778,10 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
778778
// Compute supertraits of current trait lazily.
779779
if self.supertraits.is_none() {
780780
let trait_ref =
781-
ty::Binder::bind(ty::TraitRef::identity(self.tcx, self.trait_def_id));
782-
self.supertraits = Some(traits::supertraits(self.tcx, trait_ref).collect());
781+
ty::Binder::dummy(ty::TraitRef::identity(self.tcx, self.trait_def_id));
782+
self.supertraits = Some(
783+
traits::supertraits(self.tcx, trait_ref).map(|t| t.def_id()).collect(),
784+
);
783785
}
784786

785787
// Determine whether the trait reference `Foo as
@@ -790,9 +792,11 @@ fn contains_illegal_self_type_reference<'tcx, T: TypeFoldable<'tcx>>(
790792
// direct equality here because all of these types
791793
// are part of the formal parameter listing, and
792794
// hence there should be no inference variables.
793-
let projection_trait_ref = ty::Binder::bind(data.trait_ref(self.tcx));
794-
let is_supertrait_of_current_trait =
795-
self.supertraits.as_ref().unwrap().contains(&projection_trait_ref);
795+
let is_supertrait_of_current_trait = self
796+
.supertraits
797+
.as_ref()
798+
.unwrap()
799+
.contains(&data.trait_ref(self.tcx).def_id);
796800

797801
if is_supertrait_of_current_trait {
798802
ControlFlow::CONTINUE // do not walk contained types, do not report error, do collect $200

compiler/rustc_trait_selection/src/traits/select/confirmation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
748748
cause,
749749
obligation.recursion_depth + 1,
750750
obligation.param_env,
751-
ty::Binder::bind(outlives).to_predicate(tcx),
751+
obligation.predicate.rebind(outlives).to_predicate(tcx),
752752
));
753753
}
754754

compiler/rustc_typeck/src/astconv/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1090,7 +1090,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
10901090
let late_bound_in_trait_ref =
10911091
tcx.collect_constrained_late_bound_regions(&projection_ty);
10921092
let late_bound_in_ty =
1093-
tcx.collect_referenced_late_bound_regions(&ty::Binder::bind(ty));
1093+
tcx.collect_referenced_late_bound_regions(&trait_ref.rebind(ty));
10941094
debug!("late_bound_in_trait_ref = {:?}", late_bound_in_trait_ref);
10951095
debug!("late_bound_in_ty = {:?}", late_bound_in_ty);
10961096

compiler/rustc_typeck/src/bounds.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> Bounds<'tcx> {
5757
// If it could be sized, and is, add the `Sized` predicate.
5858
let sized_predicate = self.implicitly_sized.and_then(|span| {
5959
tcx.lang_items().sized_trait().map(|sized| {
60-
let trait_ref = ty::Binder::bind(ty::TraitRef {
60+
let trait_ref = ty::Binder::dummy(ty::TraitRef {
6161
def_id: sized,
6262
substs: tcx.mk_substs_trait(param_ty, &[]),
6363
});

0 commit comments

Comments
 (0)