Fix impl_trait_ty_to_ty substs

This commit is contained in:
Santiago Pastorino 2023-03-17 12:37:27 -03:00
parent 03b01c5bec
commit 9139ed076d
No known key found for this signature in database
GPG Key ID: 8131A24E0C79EFAF
7 changed files with 47 additions and 5 deletions

View File

@ -3141,8 +3141,12 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
debug!("impl_trait_ty_to_ty: generics={:?}", generics);
let substs = InternalSubsts::for_item(tcx, def_id, |param, _| {
if let Some(i) = (param.index as usize).checked_sub(generics.parent_count) {
// Our own parameters are the resolved lifetimes.
// We use `generics.count() - lifetimes.len()` here instead of `generics.parent_count`
// since return-position impl trait in trait squashes all of the generics from its source fn
// into its own generics, so the opaque's "own" params isn't always just lifetimes.
if let Some(i) = (param.index as usize).checked_sub(generics.count() - lifetimes.len())
{
// Resolve our own lifetime parameters.
let GenericParamDefKind::Lifetime { .. } = param.kind else { bug!() };
let hir::GenericArg::Lifetime(lifetime) = &lifetimes[i] else { bug!() };
self.ast_region_to_region(lifetime, None).into()

View File

@ -1,5 +1,5 @@
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/lifetime-mismatch.rs:3:12
--> $DIR/lifetime-mismatch.rs:5:12
|
LL | #![feature(async_fn_in_trait)]
| ^^^^^^^^^^^^^^^^^
@ -8,7 +8,7 @@ LL | #![feature(async_fn_in_trait)]
= note: `#[warn(incomplete_features)]` on by default
error[E0195]: lifetime parameters or bounds on method `foo` do not match the trait declaration
--> $DIR/lifetime-mismatch.rs:12:17
--> $DIR/lifetime-mismatch.rs:14:17
|
LL | async fn foo<'a>(&self);
| ---- lifetimes in impl do not match this method in trait

View File

@ -0,0 +1,21 @@
warning: the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes
--> $DIR/lifetime-mismatch.rs:5:12
|
LL | #![feature(async_fn_in_trait)]
| ^^^^^^^^^^^^^^^^^
|
= note: see issue #91611 <https://github.com/rust-lang/rust/issues/91611> for more information
= note: `#[warn(incomplete_features)]` on by default
error[E0195]: lifetime parameters or bounds on method `foo` do not match the trait declaration
--> $DIR/lifetime-mismatch.rs:14:17
|
LL | async fn foo<'a>(&self);
| ---- lifetimes in impl do not match this method in trait
...
LL | async fn foo(&self) {}
| ^ lifetimes do not match method in trait
error: aborting due to previous error; 1 warning emitted
For more information about this error, try `rustc --explain E0195`.

View File

@ -1,4 +1,6 @@
// edition:2021
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next
#![feature(async_fn_in_trait)]
//~^ WARN the feature `async_fn_in_trait` is incomplete and may not be safe to use and/or cause compiler crashes

View File

@ -1,5 +1,5 @@
error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter
--> $DIR/trait-more-generics-than-impl.rs:11:11
--> $DIR/trait-more-generics-than-impl.rs:14:11
|
LL | fn bar<T>() -> impl Sized;
| - expected 1 type parameter

View File

@ -0,0 +1,12 @@
error[E0049]: method `bar` has 0 type parameters but its trait declaration has 1 type parameter
--> $DIR/trait-more-generics-than-impl.rs:14:11
|
LL | fn bar<T>() -> impl Sized;
| - expected 1 type parameter
...
LL | fn bar() -> impl Sized {}
| ^ found 0 type parameters
error: aborting due to previous error
For more information about this error, try `rustc --explain E0049`.

View File

@ -1,3 +1,6 @@
// [next] compile-flags: -Zlower-impl-trait-in-trait-to-assoc-ty
// revisions: current next
#![feature(return_position_impl_trait_in_trait)]
#![allow(incomplete_features)]