Skip to content

Commit 2cff30b

Browse files
committed
Auto merge of #90536 - crlf0710:fix_vtable_hrtb, r=jackh726
Erase regions within `vtable_trait_first_method_offset` Fixes #90177 . r? `@jackh726`
2 parents 4961b10 + 8841204 commit 2cff30b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,9 @@ fn vtable_trait_first_method_offset<'tcx>(
748748
) -> usize {
749749
let (trait_to_be_found, trait_owning_vtable) = key;
750750

751+
// #90177
752+
let trait_to_be_found_erased = tcx.erase_regions(trait_to_be_found);
753+
751754
let vtable_segment_callback = {
752755
let mut vtable_base = 0;
753756

@@ -757,7 +760,7 @@ fn vtable_trait_first_method_offset<'tcx>(
757760
vtable_base += COMMON_VTABLE_ENTRIES.len();
758761
}
759762
VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
760-
if trait_ref == trait_to_be_found {
763+
if tcx.erase_regions(trait_ref) == trait_to_be_found_erased {
761764
return ControlFlow::Break(vtable_base);
762765
}
763766
vtable_base += util::count_own_vtable_entries(tcx, trait_ref);

src/test/ui/hrtb/issue-90177.rs

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// check-pass
2+
3+
trait Base<'f> {
4+
type Assoc;
5+
6+
fn do_something(&self);
7+
}
8+
9+
trait ForAnyLifetime: for<'f> Base<'f> {}
10+
11+
impl<T> ForAnyLifetime for T where T: for<'f> Base<'f> {}
12+
13+
trait CanBeDynamic: ForAnyLifetime + for<'f> Base<'f, Assoc = ()> {}
14+
15+
fn foo(a: &dyn CanBeDynamic) {
16+
a.do_something();
17+
}
18+
19+
struct S;
20+
21+
impl<'a> Base<'a> for S {
22+
type Assoc = ();
23+
24+
fn do_something(&self) {}
25+
}
26+
27+
impl CanBeDynamic for S {}
28+
29+
fn main() {
30+
let s = S;
31+
foo(&s);
32+
}

0 commit comments

Comments
 (0)