Skip to content

Commit 72fbb54

Browse files
Don't remap early-bound RPITIT regions that originate from impl
1 parent ab5a2bc commit 72fbb54

File tree

3 files changed

+39
-1
lines changed

3 files changed

+39
-1
lines changed

compiler/rustc_hir_analysis/src/check/compare_method.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,13 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
590590
let num_trait_substs = trait_to_impl_substs.len();
591591
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
592592
let ty = tcx.fold_regions(ty, |region, _| {
593-
let (ty::ReFree(_) | ty::ReEarlyBound(_)) = region.kind() else { return region; };
593+
match region.kind() {
594+
// Remap all free regions, which correspond to late-bound regions in the function.
595+
ty::ReFree(_) => {}
596+
// Remap early-bound regions as long as they don't come from the `impl` itself.
597+
ty::ReEarlyBound(ebr) if tcx.parent(ebr.def_id) != impl_m.container_id(tcx) => {}
598+
_ => return region,
599+
}
594600
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
595601
else {
596602
tcx
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// check-pass
2+
// edition:2021
3+
4+
#![feature(async_fn_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
pub trait Foo {
8+
async fn foo(&mut self);
9+
}
10+
11+
struct MyFoo<'a>(&'a mut ());
12+
13+
impl<'a> Foo for MyFoo<'a> {
14+
async fn foo(&mut self) {}
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// check-pass
2+
// edition:2021
3+
4+
#![feature(async_fn_in_trait)]
5+
#![allow(incomplete_features)]
6+
7+
pub trait Foo {
8+
async fn foo(&mut self);
9+
}
10+
11+
impl<T: Foo> Foo for &mut T {
12+
async fn foo(&mut self) {}
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)