-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 #88650 - sapessi:issue-77175-fix, r=estebank
Skip single use lifetime lint for generated opaque types Fix: #77175 The opaque type generated by the desugaring process of an async function uses the lifetimes defined by the originating function. The DefId for the lifetimes in the opaque type are different from the ones in the originating async function - as they should be, as far as I understand, and could therefore be considered a single use lifetimes, this causes the single_use_lifetimes lint to fail compilation if explicitly denied. This fix skips the lint for lifetimes used only once in generated opaque types for an async function that are declared in the parent async function definition. More info in the comments on the original issue: 1 and 2
- Loading branch information
Showing
2 changed files
with
41 additions
and
1 deletion.
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,19 @@ | ||
#[deny(single_use_lifetimes)] | ||
// edition:2018 | ||
// check-pass | ||
|
||
// Prior to the fix, the compiler complained that the 'a lifetime was only used | ||
// once. This was obviously wrong since the lifetime is used twice: For the s3 | ||
// parameter and the return type. The issue was caused by the compiler | ||
// desugaring the async function into a generator that uses only a single | ||
// lifetime, which then the validator complained about becauase of the | ||
// single_use_lifetimes constraints. | ||
async fn bar<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str { | ||
s3 | ||
} | ||
|
||
fn foo<'a>(s1: String, s2: &'_ str, s3: &'a str) -> &'a str { | ||
s3 | ||
} | ||
|
||
fn main() {} |