File tree Expand file tree Collapse file tree 3 files changed +47
-2
lines changed
compiler/rustc_hir_analysis/src/check
src/test/ui/impl-trait/in-trait Expand file tree Collapse file tree 3 files changed +47
-2
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff line change 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 ( ) { }
Original file line number Diff line number Diff line change 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+
You can’t perform that action at this time.
0 commit comments