- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Closed
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionC-bugCategory: This is a bug.Category: This is a bug.D-editionDiagnostics: An error or lint that should account for edition differences.Diagnostics: An error or lint that should account for edition differences.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.
Description
Sorry, I'm not certain how to describe this scenario or why it doesn't seem to work. This could also probably be minimized more.
I tried this code:
#![warn(rust_2024_compatibility)]
use std::pin::Pin;
pub struct AttachContainerResults {
    pub input: Pin<Box<dyn AsyncWrite + Send>>,
}
pub trait AsyncWrite {}
struct S;
impl AsyncWrite for S {}
pub async fn attach_container(this: &i32) -> AttachContainerResults {
    let write = process_upgraded(this).await;
    AttachContainerResults {
        input: Box::pin(write),
    }
}
async fn process_upgraded(_this: &i32) -> impl AsyncWrite {
    S
}I expected to see this happen: Should generate a warning about it not working in 2024. At least, I cannot correlate the error with the scenarios described in the migration docs that describe scenarios that are not supported.
Instead, this happened: This does not generate any warnings about it not working in 2024. After migrating to 2024, you get an error:
error: lifetime may not live long enough
  --> src/main.rs:16:16
   |
12 | pub async fn attach_container(this: &i32) -> AttachContainerResults {
   |                                     - let's call the lifetime of this reference `'1`
...
16 |         input: Box::pin(write),
   |                ^^^^^^^^^^^^^^^ coercion requires that `'1` must outlive `'static`
I believe the solution here is to add:
     }
 }
 
-async fn process_upgraded(_this: &i32) -> impl AsyncWrite {
+async fn process_upgraded(_this: &i32) -> impl AsyncWrite + use<> {
     S
 }From messing around, it seems like the async part of process_upgraded is the key factor that is preventing the impl_trait_overcaptures lint from firing.
Meta
rustc --version --verbose:
rustc 1.84.0-nightly (b91a3a056 2024-11-07)
binary: rustc
commit-hash: b91a3a05609a46f73d23e0995ae7ebb4a4f429a5
commit-date: 2024-11-07
host: aarch64-apple-darwin
release: 1.84.0-nightly
LLVM version: 19.1.3
Metadata
Metadata
Assignees
Labels
A-edition-2024Area: The 2024 editionArea: The 2024 editionC-bugCategory: This is a bug.Category: This is a bug.D-editionDiagnostics: An error or lint that should account for edition differences.Diagnostics: An error or lint that should account for edition differences.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.