Skip to content

Commit

Permalink
Erase regions within vtable_trait_first_method_offset.
Browse files Browse the repository at this point in the history
  • Loading branch information
crlf0710 committed Nov 3, 2021
1 parent 473eaa4 commit 8841204
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
5 changes: 4 additions & 1 deletion compiler/rustc_trait_selection/src/traits/mod.rs
Expand Up @@ -748,6 +748,9 @@ fn vtable_trait_first_method_offset<'tcx>(
) -> usize {
let (trait_to_be_found, trait_owning_vtable) = key;

// #90177
let trait_to_be_found_erased = tcx.erase_regions(trait_to_be_found);

let vtable_segment_callback = {
let mut vtable_base = 0;

Expand All @@ -757,7 +760,7 @@ fn vtable_trait_first_method_offset<'tcx>(
vtable_base += COMMON_VTABLE_ENTRIES.len();
}
VtblSegment::TraitOwnEntries { trait_ref, emit_vptr } => {
if trait_ref == trait_to_be_found {
if tcx.erase_regions(trait_ref) == trait_to_be_found_erased {
return ControlFlow::Break(vtable_base);
}
vtable_base += util::count_own_vtable_entries(tcx, trait_ref);
Expand Down
32 changes: 32 additions & 0 deletions src/test/ui/hrtb/issue-90177.rs
@@ -0,0 +1,32 @@
// check-pass

trait Base<'f> {
type Assoc;

fn do_something(&self);
}

trait ForAnyLifetime: for<'f> Base<'f> {}

impl<T> ForAnyLifetime for T where T: for<'f> Base<'f> {}

trait CanBeDynamic: ForAnyLifetime + for<'f> Base<'f, Assoc = ()> {}

fn foo(a: &dyn CanBeDynamic) {
a.do_something();
}

struct S;

impl<'a> Base<'a> for S {
type Assoc = ();

fn do_something(&self) {}
}

impl CanBeDynamic for S {}

fn main() {
let s = S;
foo(&s);
}

0 comments on commit 8841204

Please sign in to comment.