-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #62849 - davidtwco:prohibit-inheriting-lifetimes, r=<try>
typeck: Prohibit RPIT types that inherit lifetimes Part of #61949. This PR prohibits return position `impl Trait` types that "inherit lifetimes" from the parent scope. The intent is to forbid cases that are challenging until they can be addressed properly. cc @nikomatsakis
- Loading branch information
Showing
5 changed files
with
130 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// ignore-tidy-linelength | ||
// edition:2018 | ||
#![feature(async_await)] | ||
|
||
// This test checks that `Self` is prohibited as a return type. See #61949 for context. | ||
|
||
pub struct Foo<'a> { | ||
pub bar: &'a i32, | ||
} | ||
|
||
impl<'a> Foo<'a> { | ||
pub async fn new(_bar: &'a i32) -> Self { | ||
//~^ ERROR `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope | ||
Foo { | ||
bar: &22 | ||
} | ||
} | ||
} | ||
|
||
async fn foo() { | ||
let x = { | ||
let bar = 22; | ||
Foo::new(&bar).await | ||
}; | ||
drop(x); | ||
} | ||
|
||
fn main() { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: `async fn` return type cannot contain a projection or `Self` that references lifetimes from a parent scope | ||
--> $DIR/issue-61949-self-return-type.rs:12:40 | ||
| | ||
LL | pub async fn new(_bar: &'a i32) -> Self { | ||
| ^^^^ | ||
|
||
error: aborting due to previous error | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters