-
-
Notifications
You must be signed in to change notification settings - Fork 14.4k
Closed
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type systemD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Description
Tracking:
Given this code:
trait AnyL<'x> {}
fn f<'long: 'short, 'short>(
x: *const dyn AnyL<'long>,
) -> *const dyn AnyL<'short> {
x as *const dyn AnyL<'short>
}Our diagnostic, after #136776, reports:
error: lifetime may not live long enough
--> src/main.rs:7:5
|
4 | fn f<'long: 'short, 'short>(
| ----- ------ lifetime `'short` defined here
| |
| lifetime `'long` defined here
...
7 | x as *const dyn AnyL<'short>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ cast requires that `'short` must outlive `'long`
|
= help: consider adding the following bound: `'short: 'long`
note: raw pointer casts of trait objects cannot extend lifetimes
--> src/main.rs:7:5
|
7 | x as *const dyn AnyL<'short>
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: this was previously accepted by the compiler but was changed recently
= help: see <https://github.com/rust-lang/rust/issues/141402> for more information
It says this was previously accepted, but as far as I know, it never was. I tested it in Rust 1.0, Rust 1.85, and in various other version. It was rejected in the versions I tested.
Related:
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-lifetimesArea: Lifetimes / regionsArea: Lifetimes / regionsA-type-systemArea: Type systemArea: Type systemD-incorrectDiagnostics: A diagnostic that is giving misleading or incorrect information.Diagnostics: A diagnostic that is giving misleading or incorrect information.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.T-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.