Skip to content

Commit 6e969ea

Browse files
committed
fix various subst_identity vs skip_binder
1 parent f29a334 commit 6e969ea

File tree

13 files changed

+29
-25
lines changed

13 files changed

+29
-25
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2066,7 +2066,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
20662066
};
20672067

20682068
self.one_bound_for_assoc_type(
2069-
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.skip_binder())),
2069+
|| traits::supertraits(tcx, ty::Binder::dummy(trait_ref.subst_identity())),
20702070
|| "Self".to_string(),
20712071
assoc_ident,
20722072
span,

compiler/rustc_hir_analysis/src/check/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
540540
tcx,
541541
it.span,
542542
it.owner_id.def_id,
543-
impl_trait_ref.skip_binder(),
543+
impl_trait_ref.subst_identity(),
544544
&impl_.items,
545545
);
546546
check_on_unimplemented(tcx, it);

compiler/rustc_hir_analysis/src/coherence/orphan.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ pub(crate) fn orphan_check_impl(
2121
tcx: TyCtxt<'_>,
2222
impl_def_id: LocalDefId,
2323
) -> Result<(), ErrorGuaranteed> {
24-
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
24+
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
2525
trait_ref.error_reported()?;
2626

2727
let ret = do_orphan_check_impl(tcx, trait_ref, impl_def_id);

compiler/rustc_hir_analysis/src/coherence/unsafety.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ pub(super) fn check_item(tcx: TyCtxt<'_>, def_id: LocalDefId) {
1313
let item = tcx.hir().expect_item(def_id);
1414
let hir::ItemKind::Impl(ref impl_) = item.kind else { bug!() };
1515

16-
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id).map(|t| t.subst_identity()) {
16+
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
17+
let trait_ref = trait_ref.subst_identity();
1718
let trait_def = tcx.trait_def(trait_ref.def_id);
1819
let unsafe_attr =
1920
impl_.generics.params.iter().find(|p| p.pure_wrt_drop).map(|_| "may_dangle");

compiler/rustc_metadata/src/rmeta/encoder.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1898,9 +1898,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
18981898

18991899
for id in tcx.hir().items() {
19001900
if matches!(tcx.def_kind(id.owner_id), DefKind::Impl) {
1901-
if let Some(trait_ref) =
1902-
tcx.impl_trait_ref(id.owner_id).map(ty::EarlyBinder::subst_identity)
1903-
{
1901+
if let Some(trait_ref) = tcx.impl_trait_ref(id.owner_id) {
1902+
let trait_ref = trait_ref.subst_identity();
1903+
19041904
let simplified_self_ty = fast_reject::simplify_type(
19051905
self.tcx,
19061906
trait_ref.self_ty(),

compiler/rustc_middle/src/ty/mod.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -2187,8 +2187,10 @@ impl<'tcx> TyCtxt<'tcx> {
21872187
) -> Option<ImplOverlapKind> {
21882188
// If either trait impl references an error, they're allowed to overlap,
21892189
// as one of them essentially doesn't exist.
2190-
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.skip_binder().references_error())
2191-
|| self.impl_trait_ref(def_id2).map_or(false, |tr| tr.skip_binder().references_error())
2190+
if self.impl_trait_ref(def_id1).map_or(false, |tr| tr.subst_identity().references_error())
2191+
|| self
2192+
.impl_trait_ref(def_id2)
2193+
.map_or(false, |tr| tr.subst_identity().references_error())
21922194
{
21932195
return Some(ImplOverlapKind::Permitted { marker: false });
21942196
}

compiler/rustc_monomorphize/src/collector.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1351,9 +1351,9 @@ fn create_mono_items_for_default_impls<'tcx>(
13511351
tcx.def_path_str(item.owner_id.to_def_id())
13521352
);
13531353

1354-
if let Some(trait_ref) =
1355-
tcx.impl_trait_ref(item.owner_id).map(ty::EarlyBinder::subst_identity)
1356-
{
1354+
if let Some(trait_ref) = tcx.impl_trait_ref(item.owner_id) {
1355+
let trait_ref = trait_ref.subst_identity();
1356+
13571357
let param_env = ty::ParamEnv::reveal_all();
13581358
let trait_ref = tcx.normalize_erasing_regions(param_env, trait_ref);
13591359
let overridden_methods = tcx.impl_item_implementor_ids(item.owner_id);

compiler/rustc_trait_selection/src/traits/coherence.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ pub fn overlapping_impls(
7777
// a quick check via fast_reject to tell if the impl headers could possibly
7878
// unify.
7979
let drcx = DeepRejectCtxt { treat_obligation_params: TreatParams::AsInfer };
80-
let impl1_ref = tcx.impl_trait_ref(impl1_def_id).map(ty::EarlyBinder::subst_identity);
81-
let impl2_ref = tcx.impl_trait_ref(impl2_def_id).map(ty::EarlyBinder::subst_identity);
80+
let impl1_ref = tcx.impl_trait_ref(impl1_def_id);
81+
let impl2_ref = tcx.impl_trait_ref(impl2_def_id);
8282
let may_overlap = match (impl1_ref, impl2_ref) {
83-
(Some(a), Some(b)) => iter::zip(a.substs, b.substs)
83+
(Some(a), Some(b)) => iter::zip(a.skip_binder().substs, b.skip_binder().substs)
8484
.all(|(arg1, arg2)| drcx.generic_args_may_unify(arg1, arg2)),
8585
(None, None) => {
8686
let self_ty1 = tcx.type_of(impl1_def_id);
@@ -461,7 +461,7 @@ pub fn orphan_check(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Result<(), OrphanChe
461461

462462
// We only except this routine to be invoked on implementations
463463
// of a trait, not inherent implementations.
464-
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
464+
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
465465
debug!("orphan_check: trait_ref={:?}", trait_ref);
466466

467467
// If the *trait* is local to the crate, ok.

compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ impl<'tcx> InferCtxtPrivExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
19401940
return None;
19411941
}
19421942

1943-
let imp = self.tcx.impl_trait_ref(def_id).unwrap().subst_identity();
1943+
let imp = self.tcx.impl_trait_ref(def_id).unwrap().skip_binder();
19441944

19451945
self.fuzzy_match_tys(trait_pred.skip_binder().self_ty(), imp.self_ty(), false)
19461946
.map(|similarity| ImplCandidate { trait_ref: imp, similarity })

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ fn report_conflicting_impls<'tcx>(
431431
pub(crate) fn to_pretty_impl_header(tcx: TyCtxt<'_>, impl_def_id: DefId) -> Option<String> {
432432
use std::fmt::Write;
433433

434-
let trait_ref = tcx.impl_trait_ref(impl_def_id)?.skip_binder();
434+
let trait_ref = tcx.impl_trait_ref(impl_def_id)?.subst_identity();
435435
let mut w = "impl".to_owned();
436436

437437
let substs = InternalSubsts::identity_for_item(tcx, impl_def_id);

compiler/rustc_trait_selection/src/traits/specialize/specialization_graph.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ trait ChildrenExt<'tcx> {
4848
impl<'tcx> ChildrenExt<'tcx> for Children {
4949
/// Insert an impl into this set of children without comparing to any existing impls.
5050
fn insert_blindly(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
51-
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
51+
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
5252
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
5353
{
5454
debug!("insert_blindly: impl_def_id={:?} st={:?}", impl_def_id, st);
@@ -63,7 +63,7 @@ impl<'tcx> ChildrenExt<'tcx> for Children {
6363
/// an impl with a parent. The impl must be present in the list of
6464
/// children already.
6565
fn remove_existing(&mut self, tcx: TyCtxt<'tcx>, impl_def_id: DefId) {
66-
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
66+
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
6767
let vec: &mut Vec<DefId>;
6868
if let Some(st) = fast_reject::simplify_type(tcx, trait_ref.self_ty(), TreatParams::AsInfer)
6969
{
@@ -275,7 +275,8 @@ impl<'tcx> GraphExt<'tcx> for Graph {
275275
) -> Result<Option<FutureCompatOverlapError<'tcx>>, OverlapError<'tcx>> {
276276
assert!(impl_def_id.is_local());
277277

278-
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().subst_identity();
278+
// FIXME: use `EarlyBinder` in `self.children`
279+
let trait_ref = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder();
279280
let trait_def_id = trait_ref.def_id;
280281

281282
debug!(
@@ -388,7 +389,7 @@ pub(crate) fn assoc_def(
388389
impl_def_id: DefId,
389390
assoc_def_id: DefId,
390391
) -> Result<LeafDef, ErrorGuaranteed> {
391-
let trait_def_id = tcx.impl_trait_ref(impl_def_id).unwrap().skip_binder().def_id;
392+
let trait_def_id = tcx.trait_id_of_impl(impl_def_id).unwrap();
392393
let trait_def = tcx.trait_def(trait_def_id);
393394

394395
// This function may be called while we are still building the

compiler/rustc_ty_utils/src/implied_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
2222
tcx.intern_type_list(&assumed_wf_types)
2323
}
2424
DefKind::Impl => {
25-
match tcx.impl_trait_ref(def_id).map(ty::EarlyBinder::subst_identity) {
25+
match tcx.impl_trait_ref(def_id) {
2626
Some(trait_ref) => {
27-
let types: Vec<_> = trait_ref.substs.types().collect();
27+
let types: Vec<_> = trait_ref.skip_binder().substs.types().collect();
2828
tcx.intern_type_list(&types)
2929
}
3030
// Only the impl self type

src/librustdoc/passes/collect_intra_doc_links.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -786,7 +786,7 @@ fn trait_impls_for<'a>(
786786
tcx.find_map_relevant_impl(trait_, ty, |impl_| {
787787
let trait_ref = tcx.impl_trait_ref(impl_).expect("this is not an inherent impl");
788788
// Check if these are the same type.
789-
let impl_type = trait_ref.subst_identity().self_ty();
789+
let impl_type = trait_ref.skip_binder().self_ty();
790790
trace!(
791791
"comparing type {} with kind {:?} against type {:?}",
792792
impl_type,

0 commit comments

Comments
 (0)