Skip to content

Commit 12babb6

Browse files
author
Yuki Okushi
authored
Rollup merge of rust-lang#103409 - compiler-errors:rpitit-signature-mismatch, r=lcnr
Delay span bug when we can't map lifetimes back in `collect_trait_impl_trait_tys` When a lifetime is late-bound in a trait signature, but early-bound in an impl signature, we already emit an error -- however, we also ICE in `collect_trait_impl_trait_tys`, so just delay a bug here. Fixes rust-lang#103407
2 parents 6383540 + fa5cf90 commit 12babb6

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

Diff for: compiler/rustc_hir_analysis/src/check/compare_method.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -598,8 +598,16 @@ pub fn collect_trait_impl_trait_tys<'tcx>(
598598
let num_impl_substs = tcx.generics_of(impl_m.container_id(tcx)).params.len();
599599
let ty = tcx.fold_regions(ty, |region, _| {
600600
let ty::ReFree(_) = region.kind() else { return region; };
601-
let ty::ReEarlyBound(e) = map[&region.into()].expect_region().kind()
602-
else { bug!("expected ReFree to map to ReEarlyBound"); };
601+
let Some(ty::ReEarlyBound(e)) = map.get(&region.into()).map(|r| r.expect_region().kind())
602+
else {
603+
tcx
604+
.sess
605+
.delay_span_bug(
606+
return_span,
607+
"expected ReFree to map to ReEarlyBound"
608+
);
609+
return tcx.lifetimes.re_static;
610+
};
603611
tcx.mk_region(ty::ReEarlyBound(ty::EarlyBoundRegion {
604612
def_id: e.def_id,
605613
name: e.name,
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// edition:2021
2+
3+
#![feature(return_position_impl_trait_in_trait)]
4+
#![allow(incomplete_features)]
5+
6+
use std::future::Future;
7+
8+
pub trait AsyncTrait {
9+
fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
10+
}
11+
12+
pub struct Struct;
13+
14+
impl AsyncTrait for Struct {
15+
fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
16+
//~^ ERROR `impl` item signature doesn't match `trait` item signature
17+
async move { buff.to_vec() }
18+
}
19+
}
20+
21+
fn main() {}
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error: `impl` item signature doesn't match `trait` item signature
2+
--> $DIR/signature-mismatch.rs:15:5
3+
|
4+
LL | fn async_fn(&self, buff: &[u8]) -> impl Future<Output = Vec<u8>>;
5+
| ----------------------------------------------------------------- expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
6+
...
7+
LL | fn async_fn<'a>(&self, buff: &'a [u8]) -> impl Future<Output = Vec<u8>> + 'a {
8+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
9+
|
10+
= note: expected `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + 'static`
11+
found `fn(&'1 Struct, &'2 [u8]) -> impl Future<Output = Vec<u8>> + '2`
12+
= help: the lifetime requirements from the `impl` do not correspond to the requirements in the `trait`
13+
= help: verify the lifetime relationships in the `trait` and `impl` between the `self` argument, the other inputs and its output
14+
15+
error: aborting due to previous error
16+

0 commit comments

Comments
 (0)