Skip to content

Commit d5d8eee

Browse files
authored
Rollup merge of rust-lang#103852 - compiler-errors:rpitit-early-from-impl, r=lcnr
Don't remap early-bound regions for return-position `impl Trait` in trait originating from `impl` long title 😓 We don't want to remap early-bound regions that originate from the `impl`s themselves, since they have no corresponding region in the trait. Not sure if there's a better condition than checking if the EBR's def-id's parent is the impl -- maybe we should be checking if the region comes from the method or RPITIT... 🤷 r? types Fixes rust-lang#103850
2 parents b6097f2 + 72fbb54 commit d5d8eee

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
@@ -521,7 +521,13 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
521521
let num_trait_substs = trait_to_impl_substs.len();
522522
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
523523
let ty = tcx.fold_regions(ty, |region, _| {
524-
let (ty::ReFree(_) | ty::ReEarlyBound(_)) = region.kind() else { return region; };
524+
match region.kind() {
525+
// Remap all free regions, which correspond to late-bound regions in the function.
526+
ty::ReFree(_) => {}
527+
// Remap early-bound regions as long as they don't come from the `impl` itself.
528+
ty::ReEarlyBound(ebr) if tcx.parent(ebr.def_id) != impl_m.container_id(tcx) => {}
529+
_ => return region,
530+
}
525531
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
526532
else {
527533
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)