Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9669934

Browse files
committedMar 7, 2024
Apply EarlyBinder only to TraitRef in ImplTraitHeader
1 parent 8c9a75b commit 9669934

File tree

22 files changed

+74
-82
lines changed

22 files changed

+74
-82
lines changed
 

‎compiler/rustc_hir_analysis/src/astconv/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1612,10 +1612,11 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16121612
.any(|impl_def_id| {
16131613
let impl_header = tcx.impl_trait_header(impl_def_id);
16141614
impl_header.is_some_and(|header| {
1615-
let header = header.instantiate(
1615+
let trait_ref = header.trait_ref.instantiate(
16161616
tcx,
16171617
infcx.fresh_args_for_item(DUMMY_SP, impl_def_id),
16181618
);
1619+
16191620
let value = tcx.fold_regions(qself_ty, |_, _| tcx.lifetimes.re_erased);
16201621
// FIXME: Don't bother dealing with non-lifetime binders here...
16211622
if value.has_escaping_bound_vars() {
@@ -1624,7 +1625,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16241625
infcx
16251626
.can_eq(
16261627
ty::ParamEnv::empty(),
1627-
header.trait_ref.self_ty(),
1628+
trait_ref.self_ty(),
16281629
value,
16291630
) && header.polarity != ty::ImplPolarity::Negative
16301631
})
@@ -1677,9 +1678,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
16771678
.filter(|header| {
16781679
// Consider only accessible traits
16791680
tcx.visibility(trait_def_id).is_accessible_from(self.item_def_id(), tcx)
1680-
&& header.skip_binder().polarity != ty::ImplPolarity::Negative
1681+
&& header.polarity != ty::ImplPolarity::Negative
16811682
})
1682-
.map(|header| header.instantiate_identity().trait_ref.self_ty())
1683+
.map(|header| header.trait_ref.instantiate_identity().self_ty())
16831684
// We don't care about blanket impls.
16841685
.filter(|self_ty| !self_ty.has_non_region_param())
16851686
.map(|self_ty| tcx.erase_regions(self_ty).to_string())

‎compiler/rustc_hir_analysis/src/check/check.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -530,11 +530,7 @@ pub(crate) fn check_item_type(tcx: TyCtxt<'_>, def_id: LocalDefId) {
530530
}
531531
DefKind::Impl { of_trait } => {
532532
if of_trait && let Some(impl_trait_header) = tcx.impl_trait_header(def_id) {
533-
check_impl_items_against_trait(
534-
tcx,
535-
def_id,
536-
impl_trait_header.instantiate_identity(),
537-
);
533+
check_impl_items_against_trait(tcx, def_id, impl_trait_header);
538534
check_on_unimplemented(tcx, def_id);
539535
}
540536
}
@@ -725,10 +721,11 @@ fn check_impl_items_against_trait<'tcx>(
725721
impl_id: LocalDefId,
726722
impl_trait_header: ty::ImplTraitHeader<'tcx>,
727723
) {
724+
let trait_ref = impl_trait_header.trait_ref.instantiate_identity();
728725
// If the trait reference itself is erroneous (so the compilation is going
729726
// to fail), skip checking the items here -- the `impl_item` table in `tcx`
730727
// isn't populated for such impls.
731-
if impl_trait_header.references_error() {
728+
if trait_ref.references_error() {
732729
return;
733730
}
734731

@@ -752,7 +749,7 @@ fn check_impl_items_against_trait<'tcx>(
752749
}
753750
}
754751

755-
let trait_def = tcx.trait_def(impl_trait_header.trait_ref.def_id);
752+
let trait_def = tcx.trait_def(trait_ref.def_id);
756753

757754
for &impl_item in impl_item_refs {
758755
let ty_impl_item = tcx.associated_item(impl_item);
@@ -771,10 +768,10 @@ fn check_impl_items_against_trait<'tcx>(
771768
));
772769
}
773770
ty::AssocKind::Fn => {
774-
compare_impl_method(tcx, ty_impl_item, ty_trait_item, impl_trait_header.trait_ref);
771+
compare_impl_method(tcx, ty_impl_item, ty_trait_item, trait_ref);
775772
}
776773
ty::AssocKind::Type => {
777-
compare_impl_ty(tcx, ty_impl_item, ty_trait_item, impl_trait_header.trait_ref);
774+
compare_impl_ty(tcx, ty_impl_item, ty_trait_item, trait_ref);
778775
}
779776
}
780777

@@ -794,7 +791,7 @@ fn check_impl_items_against_trait<'tcx>(
794791
let mut must_implement_one_of: Option<&[Ident]> =
795792
trait_def.must_implement_one_of.as_deref();
796793

797-
for &trait_item_id in tcx.associated_item_def_ids(impl_trait_header.trait_ref.def_id) {
794+
for &trait_item_id in tcx.associated_item_def_ids(trait_ref.def_id) {
798795
let leaf_def = ancestors.leaf_def(tcx, trait_item_id);
799796

800797
let is_implemented = leaf_def
@@ -872,7 +869,7 @@ fn check_impl_items_against_trait<'tcx>(
872869

873870
if let Some(missing_items) = must_implement_one_of {
874871
let attr_span = tcx
875-
.get_attr(impl_trait_header.trait_ref.def_id, sym::rustc_must_implement_one_of)
872+
.get_attr(trait_ref.def_id, sym::rustc_must_implement_one_of)
876873
.map(|attr| attr.span);
877874

878875
missing_items_must_implement_one_of_err(

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
247247
hir::ItemKind::Impl(impl_) => {
248248
let header = tcx.impl_trait_header(def_id);
249249
let is_auto = header
250-
.is_some_and(|header| tcx.trait_is_auto(header.skip_binder().trait_ref.def_id));
250+
.is_some_and(|header| tcx.trait_is_auto(header.trait_ref.skip_binder().def_id));
251251

252252
crate::impl_wf_check::check_impl_wf(tcx, def_id)?;
253253
let mut res = Ok(());
@@ -261,7 +261,7 @@ fn check_item<'tcx>(tcx: TyCtxt<'tcx>, item: &'tcx hir::Item<'tcx>) -> Result<()
261261
.emit());
262262
}
263263
// We match on both `ty::ImplPolarity` and `ast::ImplPolarity` just to get the `!` span.
264-
match header.map(|h| h.skip_binder().polarity) {
264+
match header.map(|h| h.polarity) {
265265
// `None` means this is an inherent impl
266266
Some(ty::ImplPolarity::Positive) | None => {
267267
res = res.and(check_impl(tcx, item, impl_.self_ty, &impl_.of_trait));

‎compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_trait_selection::traits::ObligationCtxt;
2525
use rustc_trait_selection::traits::{self, ObligationCause};
2626
use std::collections::BTreeMap;
2727

28-
pub fn check_trait<'tcx>(
28+
pub(super) fn check_trait<'tcx>(
2929
tcx: TyCtxt<'tcx>,
3030
trait_def_id: DefId,
3131
impl_def_id: LocalDefId,
@@ -66,10 +66,9 @@ impl<'tcx> Checker<'tcx> {
6666

6767
fn visit_implementation_of_drop(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
6868
let tcx = checker.tcx;
69-
let header = checker.impl_header;
7069
let impl_did = checker.impl_def_id;
7170
// Destructors only work on local ADT types.
72-
match header.trait_ref.self_ty().kind() {
71+
match checker.impl_header.trait_ref.instantiate_identity().self_ty().kind() {
7372
ty::Adt(def, _) if def.did().is_local() => return Ok(()),
7473
ty::Error(_) => return Ok(()),
7574
_ => {}
@@ -86,7 +85,7 @@ fn visit_implementation_of_copy(checker: &Checker<'_>) -> Result<(), ErrorGuaran
8685
let impl_did = checker.impl_def_id;
8786
debug!("visit_implementation_of_copy: impl_did={:?}", impl_did);
8887

89-
let self_type = impl_header.trait_ref.self_ty();
88+
let self_type = impl_header.trait_ref.instantiate_identity().self_ty();
9089
debug!("visit_implementation_of_copy: self_type={:?} (bound)", self_type);
9190

9291
let param_env = tcx.param_env(impl_did);
@@ -120,7 +119,7 @@ fn visit_implementation_of_const_param_ty(checker: &Checker<'_>) -> Result<(), E
120119
let tcx = checker.tcx;
121120
let header = checker.impl_header;
122121
let impl_did = checker.impl_def_id;
123-
let self_type = header.trait_ref.self_ty();
122+
let self_type = header.trait_ref.instantiate_identity().self_ty();
124123
assert!(!self_type.has_escaping_bound_vars());
125124

126125
let param_env = tcx.param_env(impl_did);
@@ -157,9 +156,8 @@ fn visit_implementation_of_coerce_unsized(checker: &Checker<'_>) -> Result<(), E
157156

158157
fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<(), ErrorGuaranteed> {
159158
let tcx = checker.tcx;
160-
let header = checker.impl_header;
161159
let impl_did = checker.impl_def_id;
162-
let trait_ref = header.trait_ref;
160+
let trait_ref = checker.impl_header.trait_ref.instantiate_identity();
163161
debug!("visit_implementation_of_dispatch_from_dyn: impl_did={:?}", impl_did);
164162

165163
let span = tcx.def_span(impl_did);

‎compiler/rustc_hir_analysis/src/coherence/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,12 @@ fn coherent_trait(tcx: TyCtxt<'_>, def_id: DefId) -> Result<(), ErrorGuaranteed>
134134
let mut res = tcx.ensure().specialization_graph_of(def_id);
135135

136136
for &impl_def_id in impls {
137-
let trait_header = tcx.impl_trait_header(impl_def_id).unwrap().instantiate_identity();
138-
let trait_def = tcx.trait_def(trait_header.trait_ref.def_id);
137+
let trait_header = tcx.impl_trait_header(impl_def_id).unwrap();
138+
let trait_ref = trait_header.trait_ref.instantiate_identity();
139+
let trait_def = tcx.trait_def(trait_ref.def_id);
139140

140-
res = res.and(check_impl(tcx, impl_def_id, trait_header.trait_ref, trait_def));
141-
res = res.and(check_object_overlap(tcx, impl_def_id, trait_header.trait_ref));
141+
res = res.and(check_impl(tcx, impl_def_id, trait_ref, trait_def));
142+
res = res.and(check_object_overlap(tcx, impl_def_id, trait_ref));
142143

143144
res = res.and(unsafety::check_item(tcx, impl_def_id, trait_header, trait_def));
144145
res = res.and(tcx.ensure().orphan_check_impl(impl_def_id));

‎compiler/rustc_hir_analysis/src/coherence/unsafety.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ pub(super) fn check_item(
1313
trait_header: ImplTraitHeader<'_>,
1414
trait_def: &TraitDef,
1515
) -> Result<(), ErrorGuaranteed> {
16-
let trait_ref = trait_header.trait_ref;
1716
let unsafe_attr =
1817
tcx.generics_of(def_id).params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");
18+
let trait_ref = trait_header.trait_ref.instantiate_identity();
19+
1920
match (trait_def.unsafety, unsafe_attr, trait_header.unsafety, trait_header.polarity) {
2021
(Unsafety::Normal, None, Unsafety::Unsafe, Positive | Reservation) => {
2122
let span = tcx.def_span(def_id);

‎compiler/rustc_hir_analysis/src/collect.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1519,10 +1519,7 @@ fn suggest_impl_trait<'tcx>(
15191519
None
15201520
}
15211521

1522-
fn impl_trait_header(
1523-
tcx: TyCtxt<'_>,
1524-
def_id: LocalDefId,
1525-
) -> Option<ty::EarlyBinder<ty::ImplTraitHeader<'_>>> {
1522+
fn impl_trait_header(tcx: TyCtxt<'_>, def_id: LocalDefId) -> Option<ty::ImplTraitHeader<'_>> {
15261523
let icx = ItemCtxt::new(tcx, def_id);
15271524
let item = tcx.hir().expect_item(def_id);
15281525
let impl_ = item.expect_impl();
@@ -1558,11 +1555,11 @@ fn impl_trait_header(
15581555
} else {
15591556
icx.astconv().instantiate_mono_trait_ref(ast_trait_ref, selfty)
15601557
};
1561-
ty::EarlyBinder::bind(ty::ImplTraitHeader {
1562-
trait_ref,
1558+
ty::ImplTraitHeader {
1559+
trait_ref: ty::EarlyBinder::bind(trait_ref),
15631560
unsafety: impl_.unsafety,
15641561
polarity: polarity_of_impl(tcx, def_id, impl_, item.span)
1565-
})
1562+
}
15661563
})
15671564
}
15681565

‎compiler/rustc_hir_typeck/src/method/suggest.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3368,11 +3368,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
33683368
"inherent impls can't be candidates, only trait impls can be",
33693369
)
33703370
})
3371-
.filter(|header| {
3372-
header.skip_binder().polarity == ty::ImplPolarity::Negative
3373-
})
3371+
.filter(|header| header.polarity == ty::ImplPolarity::Negative)
33743372
.any(|header| {
3375-
let imp = header.instantiate_identity().trait_ref;
3373+
let imp = header.trait_ref.instantiate_identity();
33763374
let imp_simp =
33773375
simplify_type(self.tcx, imp.self_ty(), TreatParams::ForLookup);
33783376
imp_simp.is_some_and(|s| s == simp_rcvr_ty)

‎compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1993,9 +1993,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
19931993

19941994
if of_trait && let Some(header) = tcx.impl_trait_header(def_id) {
19951995
record!(self.tables.impl_trait_header[def_id] <- header);
1996-
let trait_ref = header.map_bound(|h| h.trait_ref);
19971996

1998-
let trait_ref = trait_ref.instantiate_identity();
1997+
let trait_ref = header.trait_ref.instantiate_identity();
19991998
let simplified_self_ty = fast_reject::simplify_type(
20001999
self.tcx,
20012000
trait_ref.self_ty(),

‎compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ define_tables! {
423423
variances_of: Table<DefIndex, LazyArray<ty::Variance>>,
424424
fn_sig: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::PolyFnSig<'static>>>>,
425425
codegen_fn_attrs: Table<DefIndex, LazyValue<CodegenFnAttrs>>,
426-
impl_trait_header: Table<DefIndex, LazyValue<ty::EarlyBinder<ty::ImplTraitHeader<'static>>>>,
426+
impl_trait_header: Table<DefIndex, LazyValue<ty::ImplTraitHeader<'static>>>,
427427
const_param_default: Table<DefIndex, LazyValue<ty::EarlyBinder<rustc_middle::ty::Const<'static>>>>,
428428
object_lifetime_default: Table<DefIndex, LazyValue<ObjectLifetimeDefault>>,
429429
optimized_mir: Table<DefIndex, LazyValue<mir::Body<'static>>>,

‎compiler/rustc_middle/src/query/erase.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,8 +177,8 @@ impl EraseType for Option<mir::DestructuredConstant<'_>> {
177177
type Result = [u8; size_of::<Option<mir::DestructuredConstant<'static>>>()];
178178
}
179179

180-
impl EraseType for Option<ty::EarlyBinder<ty::ImplTraitHeader<'_>>> {
181-
type Result = [u8; size_of::<Option<ty::EarlyBinder<ty::ImplTraitHeader<'static>>>>()];
180+
impl EraseType for Option<ty::ImplTraitHeader<'_>> {
181+
type Result = [u8; size_of::<Option<ty::ImplTraitHeader<'static>>>()];
182182
}
183183

184184
impl EraseType for Option<ty::EarlyBinder<Ty<'_>>> {

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ rustc_queries! {
840840

841841
/// Given an `impl_id`, return the trait it implements along with some header information.
842842
/// Return `None` if this is an inherent impl.
843-
query impl_trait_header(impl_id: DefId) -> Option<ty::EarlyBinder<ty::ImplTraitHeader<'tcx>>> {
843+
query impl_trait_header(impl_id: DefId) -> Option<ty::ImplTraitHeader<'tcx>> {
844844
desc { |tcx| "computing trait implemented by `{}`", tcx.def_path_str(impl_id) }
845845
cache_on_disk_if { impl_id.is_local() }
846846
separate_provide_extern

‎compiler/rustc_middle/src/ty/context.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2310,12 +2310,11 @@ impl<'tcx> TyCtxt<'tcx> {
23102310
self,
23112311
def_id: impl IntoQueryParam<DefId>,
23122312
) -> Option<ty::EarlyBinder<ty::TraitRef<'tcx>>> {
2313-
Some(self.impl_trait_header(def_id)?.map_bound(|h| h.trait_ref))
2313+
Some(self.impl_trait_header(def_id)?.trait_ref)
23142314
}
23152315

23162316
pub fn impl_polarity(self, def_id: impl IntoQueryParam<DefId>) -> ty::ImplPolarity {
2317-
self.impl_trait_header(def_id)
2318-
.map_or(ty::ImplPolarity::Positive, |h| h.skip_binder().polarity)
2317+
self.impl_trait_header(def_id).map_or(ty::ImplPolarity::Positive, |h| h.polarity)
23192318
}
23202319
}
23212320

‎compiler/rustc_middle/src/ty/mod.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -250,9 +250,9 @@ pub struct ImplHeader<'tcx> {
250250
pub predicates: Vec<Predicate<'tcx>>,
251251
}
252252

253-
#[derive(Copy, Clone, Debug, TypeFoldable, TypeVisitable, TyEncodable, TyDecodable, HashStable)]
253+
#[derive(Copy, Clone, Debug, TyEncodable, TyDecodable, HashStable)]
254254
pub struct ImplTraitHeader<'tcx> {
255-
pub trait_ref: ty::TraitRef<'tcx>,
255+
pub trait_ref: ty::EarlyBinder<ty::TraitRef<'tcx>>,
256256
pub polarity: ImplPolarity,
257257
pub unsafety: hir::Unsafety,
258258
}
@@ -1624,12 +1624,15 @@ impl<'tcx> TyCtxt<'tcx> {
16241624
def_id1: DefId,
16251625
def_id2: DefId,
16261626
) -> Option<ImplOverlapKind> {
1627-
let impl1 = self.impl_trait_header(def_id1).unwrap().instantiate_identity();
1628-
let impl2 = self.impl_trait_header(def_id2).unwrap().instantiate_identity();
1627+
let impl1 = self.impl_trait_header(def_id1).unwrap();
1628+
let impl2 = self.impl_trait_header(def_id2).unwrap();
1629+
1630+
let trait_ref1 = impl1.trait_ref.skip_binder();
1631+
let trait_ref2 = impl2.trait_ref.skip_binder();
16291632

16301633
// If either trait impl references an error, they're allowed to overlap,
16311634
// as one of them essentially doesn't exist.
1632-
if impl1.references_error() || impl2.references_error() {
1635+
if trait_ref1.references_error() || trait_ref2.references_error() {
16331636
return Some(ImplOverlapKind::Permitted { marker: false });
16341637
}
16351638

@@ -1650,7 +1653,7 @@ impl<'tcx> TyCtxt<'tcx> {
16501653
let is_marker_overlap = {
16511654
let is_marker_impl =
16521655
|trait_ref: TraitRef<'_>| -> bool { self.trait_def(trait_ref.def_id).is_marker };
1653-
is_marker_impl(impl1.trait_ref) && is_marker_impl(impl2.trait_ref)
1656+
is_marker_impl(trait_ref1) && is_marker_impl(trait_ref2)
16541657
};
16551658

16561659
if is_marker_overlap {

‎compiler/rustc_monomorphize/src/collector.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1361,7 +1361,7 @@ fn create_mono_items_for_default_impls<'tcx>(
13611361
return;
13621362
};
13631363

1364-
if matches!(impl_.skip_binder().polarity, ty::ImplPolarity::Negative) {
1364+
if matches!(impl_.polarity, ty::ImplPolarity::Negative) {
13651365
return;
13661366
}
13671367

@@ -1385,7 +1385,7 @@ fn create_mono_items_for_default_impls<'tcx>(
13851385
}
13861386
};
13871387
let impl_args = GenericArgs::for_item(tcx, item.owner_id.to_def_id(), only_region_params);
1388-
let trait_ref = impl_.instantiate(tcx, impl_args).trait_ref;
1388+
let trait_ref = impl_.trait_ref.instantiate(tcx, impl_args);
13891389

13901390
// Unlike 'lazy' monomorphization that begins by collecting items transitively
13911391
// called by `main` or other global items, when eagerly monomorphizing impl

‎compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
166166
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
167167
if !drcx.args_may_unify(
168168
goal.predicate.trait_ref(tcx).args,
169-
impl_trait_header.skip_binder().trait_ref.args,
169+
impl_trait_header.trait_ref.skip_binder().args,
170170
) {
171171
return Err(NoSolution);
172172
}
173173

174174
// We have to ignore negative impls when projecting.
175-
let impl_polarity = impl_trait_header.skip_binder().polarity;
175+
let impl_polarity = impl_trait_header.polarity;
176176
match impl_polarity {
177177
ty::ImplPolarity::Negative => return Err(NoSolution),
178178
ty::ImplPolarity::Reservation => {
@@ -183,7 +183,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for NormalizesTo<'tcx> {
183183

184184
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
185185
let impl_args = ecx.fresh_args_for_item(impl_def_id);
186-
let impl_trait_ref = impl_trait_header.instantiate(tcx, impl_args).trait_ref;
186+
let impl_trait_ref = impl_trait_header.trait_ref.instantiate(tcx, impl_args);
187187

188188
ecx.eq(goal.param_env, goal_trait_ref, impl_trait_ref)?;
189189

‎compiler/rustc_trait_selection/src/solve/trait_goals.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
4747
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::ForLookup };
4848
if !drcx.args_may_unify(
4949
goal.predicate.trait_ref.args,
50-
impl_trait_header.skip_binder().trait_ref.args,
50+
impl_trait_header.trait_ref.skip_binder().args,
5151
) {
5252
return Err(NoSolution);
5353
}
5454

5555
// An upper bound of the certainty of this goal, used to lower the certainty
5656
// of reservation impl to ambiguous during coherence.
57-
let impl_polarity = impl_trait_header.skip_binder().polarity;
57+
let impl_polarity = impl_trait_header.polarity;
5858
let maximal_certainty = match impl_polarity {
5959
ty::ImplPolarity::Positive | ty::ImplPolarity::Negative => {
6060
match impl_polarity == goal.predicate.polarity {
@@ -70,7 +70,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> {
7070

7171
ecx.probe_trait_candidate(CandidateSource::Impl(impl_def_id)).enter(|ecx| {
7272
let impl_args = ecx.fresh_args_for_item(impl_def_id);
73-
let impl_trait_ref = impl_trait_header.instantiate(tcx, impl_args).trait_ref;
73+
let impl_trait_ref = impl_trait_header.trait_ref.instantiate(tcx, impl_args);
7474

7575
ecx.eq(goal.param_env, goal.predicate.trait_ref, impl_trait_ref)?;
7676
let where_clause_bounds = tcx

‎compiler/rustc_trait_selection/src/traits/error_reporting/type_err_ctxt_ext.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,13 +1888,13 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
18881888
.tcx
18891889
.all_impls(trait_pred.def_id())
18901890
.filter_map(|def_id| {
1891-
let imp = self.tcx.impl_trait_header(def_id).unwrap().skip_binder();
1891+
let imp = self.tcx.impl_trait_header(def_id).unwrap();
18921892
if imp.polarity == ty::ImplPolarity::Negative
18931893
|| !self.tcx.is_user_visible_dep(def_id.krate)
18941894
{
18951895
return None;
18961896
}
1897-
let imp = imp.trait_ref;
1897+
let imp = imp.trait_ref.skip_binder();
18981898

18991899
self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false).map(
19001900
|similarity| ImplCandidate { trait_ref: imp, similarity, impl_def_id: def_id },
@@ -2078,12 +2078,11 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
20782078
.all_impls(def_id)
20792079
// Ignore automatically derived impls and `!Trait` impls.
20802080
.filter_map(|def_id| self.tcx.impl_trait_header(def_id))
2081-
.map(ty::EarlyBinder::instantiate_identity)
2082-
.filter(|header| {
2083-
header.polarity != ty::ImplPolarity::Negative
2084-
|| self.tcx.is_automatically_derived(def_id)
2081+
.filter_map(|header| {
2082+
(header.polarity != ty::ImplPolarity::Negative
2083+
|| self.tcx.is_automatically_derived(def_id))
2084+
.then(|| header.trait_ref.instantiate_identity())
20852085
})
2086-
.map(|header| header.trait_ref)
20872086
.filter(|trait_ref| {
20882087
let self_ty = trait_ref.self_ty();
20892088
// Avoid mentioning type parameters.

‎compiler/rustc_trait_selection/src/traits/select/candidate_assembly.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
562562
// and so forth that we need to.
563563
let impl_trait_header = self.tcx().impl_trait_header(impl_def_id).unwrap();
564564
if !drcx
565-
.args_may_unify(obligation_args, impl_trait_header.skip_binder().trait_ref.args)
565+
.args_may_unify(obligation_args, impl_trait_header.trait_ref.skip_binder().args)
566566
{
567567
return;
568568
}
@@ -577,7 +577,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
577577
if self.reject_fn_ptr_impls(
578578
impl_def_id,
579579
obligation,
580-
impl_trait_header.skip_binder().trait_ref.self_ty(),
580+
impl_trait_header.trait_ref.skip_binder().self_ty(),
581581
) {
582582
return;
583583
}

‎compiler/rustc_trait_selection/src/traits/select/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ use rustc_middle::ty::_match::MatchAgainstFreshVars;
4242
use rustc_middle::ty::abstract_const::NotConstEvaluatable;
4343
use rustc_middle::ty::relate::TypeRelation;
4444
use rustc_middle::ty::GenericArgsRef;
45-
use rustc_middle::ty::{self, EarlyBinder, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
45+
use rustc_middle::ty::{self, PolyProjectionPredicate, ToPolyTraitRef, ToPredicate};
4646
use rustc_middle::ty::{Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
4747
use rustc_span::symbol::sym;
4848
use rustc_span::Symbol;
@@ -2441,7 +2441,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
24412441
fn match_impl(
24422442
&mut self,
24432443
impl_def_id: DefId,
2444-
impl_trait_header: EarlyBinder<ty::ImplTraitHeader<'tcx>>,
2444+
impl_trait_header: ty::ImplTraitHeader<'tcx>,
24452445
obligation: &PolyTraitObligation<'tcx>,
24462446
) -> Result<Normalized<'tcx, GenericArgsRef<'tcx>>, ()> {
24472447
let placeholder_obligation =
@@ -2450,8 +2450,8 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
24502450

24512451
let impl_args = self.infcx.fresh_args_for_item(obligation.cause.span, impl_def_id);
24522452

2453-
let impl_trait_header = impl_trait_header.instantiate(self.tcx(), impl_args);
2454-
if impl_trait_header.references_error() {
2453+
let trait_ref = impl_trait_header.trait_ref.instantiate(self.tcx(), impl_args);
2454+
if trait_ref.references_error() {
24552455
return Err(());
24562456
}
24572457

@@ -2464,7 +2464,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
24642464
obligation.param_env,
24652465
obligation.cause.clone(),
24662466
obligation.recursion_depth + 1,
2467-
impl_trait_header.trait_ref,
2467+
trait_ref,
24682468
)
24692469
});
24702470

‎compiler/rustc_trait_selection/src/traits/specialize/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
169169
}
170170
}
171171

172-
let impl1_trait_header = tcx.impl_trait_header(impl1_def_id).unwrap().instantiate_identity();
172+
let impl1_trait_header = tcx.impl_trait_header(impl1_def_id).unwrap();
173173

174174
// We determine whether there's a subset relationship by:
175175
//
@@ -198,7 +198,7 @@ pub(super) fn specializes(tcx: TyCtxt<'_>, (impl1_def_id, impl2_def_id): (DefId,
198198
fulfill_implication(
199199
&infcx,
200200
penv,
201-
impl1_trait_header.trait_ref,
201+
impl1_trait_header.trait_ref.instantiate_identity(),
202202
impl1_def_id,
203203
impl2_def_id,
204204
|_, _| ObligationCause::dummy(),

‎compiler/rustc_ty_utils/src/ty.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -255,10 +255,9 @@ fn issue33140_self_ty(tcx: TyCtxt<'_>, def_id: DefId) -> Option<EarlyBinder<Ty<'
255255

256256
let impl_ = tcx
257257
.impl_trait_header(def_id)
258-
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id))
259-
.skip_binder();
258+
.unwrap_or_else(|| bug!("issue33140_self_ty called on inherent impl {:?}", def_id));
260259

261-
let trait_ref = impl_.trait_ref;
260+
let trait_ref = impl_.trait_ref.skip_binder();
262261
debug!("issue33140_self_ty({:?}), trait-ref={:?}", def_id, trait_ref);
263262

264263
let is_marker_like = impl_.polarity == ty::ImplPolarity::Positive

0 commit comments

Comments
 (0)
Please sign in to comment.