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 5698a58

Browse files
committedNov 24, 2023
Auto merge of rust-lang#118247 - spastorino:type-equality-subtyping, r=<try>
Fix for TypeId exposes equality-by-subtyping vs normal-form-syntactic-equality unsoundness Fixes rust-lang#97156 This PR revives rust-lang#97427 idea, it sits on top of rust-lang#118118 because the idea uncovered some problems with IATs. r? `@lcnr` This is ICEing yet for `tests/ui/traits/new-solver/escaping-bound-vars-in-writeback-normalization.rs` using the new trait solver. After rust-lang#118118 and this ICE is fixed, we would need a rebase and a crater run. Opening as a WIP for now.
2 parents 42ae1a7 + 3679fde commit 5698a58

File tree

63 files changed

+373
-387
lines changed

Some content is hidden

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

63 files changed

+373
-387
lines changed
 

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

+7-3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
138138
let name_str = intrinsic_name.as_str();
139139

140140
let bound_vars = tcx.mk_bound_variable_kinds(&[
141+
ty::BoundVariableKind::Region(ty::BrAnon),
141142
ty::BoundVariableKind::Region(ty::BrAnon),
142143
ty::BoundVariableKind::Region(ty::BrEnv),
143144
]);
@@ -151,7 +152,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
151152
let env_region = ty::Region::new_bound(
152153
tcx,
153154
ty::INNERMOST,
154-
ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrEnv },
155+
ty::BoundRegion { var: ty::BoundVar::from_u32(2), kind: ty::BrEnv },
155156
);
156157
let va_list_ty = tcx.type_of(did).instantiate(tcx, &[region.into()]);
157158
(Ty::new_ref(tcx, env_region, ty::TypeAndMut { ty: va_list_ty, mutbl }), va_list_ty)
@@ -446,9 +447,12 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
446447

447448
sym::raw_eq => {
448449
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon };
449-
let param_ty =
450+
let param_ty_lhs =
451+
Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0));
452+
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(1), kind: ty::BrAnon };
453+
let param_ty_rhs =
450454
Ty::new_imm_ref(tcx, ty::Region::new_bound(tcx, ty::INNERMOST, br), param(0));
451-
(1, vec![param_ty; 2], tcx.types.bool)
455+
(1, vec![param_ty_lhs, param_ty_rhs], tcx.types.bool)
452456
}
453457

454458
sym::black_box => (1, vec![param(0)], param(0)),

‎compiler/rustc_infer/src/infer/equate.rs

+12-7
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@ use crate::traits::PredicateObligations;
44
use super::combine::{CombineFields, ObligationEmittingRelation};
55
use super::Subtype;
66

7+
use rustc_middle::ty::error::TypeError;
78
use rustc_middle::ty::relate::{self, Relate, RelateResult, TypeRelation};
89
use rustc_middle::ty::GenericArgsRef;
910
use rustc_middle::ty::TyVar;
10-
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt};
11+
use rustc_middle::ty::{self, Ty, TyCtxt};
1112

1213
use rustc_hir::def_id::DefId;
1314

@@ -164,14 +165,18 @@ impl<'tcx> TypeRelation<'tcx> for Equate<'_, '_, 'tcx> {
164165
return Ok(a);
165166
}
166167

167-
if a.skip_binder().has_escaping_bound_vars() || b.skip_binder().has_escaping_bound_vars() {
168-
self.fields.higher_ranked_sub(a, b, self.a_is_expected)?;
169-
self.fields.higher_ranked_sub(b, a, self.a_is_expected)?;
168+
let a = self.tcx().anonymize_bound_vars(a);
169+
let b = self.tcx().anonymize_bound_vars(b);
170+
171+
if a.bound_vars() == b.bound_vars() {
172+
let (a, b) = self
173+
.fields
174+
.infcx
175+
.instantiate_binder_with_placeholders(a.map_bound(|a| (a, b.skip_binder())));
176+
Ok(ty::Binder::dummy(self.relate(a, b)?))
170177
} else {
171-
// Fast path for the common case.
172-
self.relate(a.skip_binder(), b.skip_binder())?;
178+
Err(TypeError::Mismatch)
173179
}
174-
Ok(a)
175180
}
176181
}
177182

0 commit comments

Comments
 (0)
Please sign in to comment.