-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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
Code
struct S<T: >(&'static T);
Current output
error[E0310]: the parameter type `T` may not live long enough
--> src/lib.rs:1:15
|
1 | struct S<T: >(&'static T);
| ^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the reference type `&'static T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
1 | struct S<T: 'static: >(&'static T);
| +++++++++
Desired output
error[E0310]: the parameter type `T` may not live long enough
--> src/lib.rs:1:15
|
1 | struct S<T: >(&'static T);
| ^^^^^^^^^^
| |
| the parameter type `T` must be valid for the static lifetime...
| ...so that the reference type `&'static T` does not outlive the data it points at
|
help: consider adding an explicit lifetime bound
|
1 | struct S<T: 'static>(&'static T);
| +++++++
Rationale and extra context
No response
Other cases
unfulfilled trait bounds are less problematic:
struct S<T: >(C<T>);
struct C<T: Copy>(T);
gives
error[E0277]: the trait bound `T: Copy` is not satisfied
--> src/lib.rs:1:15
|
1 | struct S<T: >(C<T>);
| ^^^^ the trait `Copy` is not implemented for `T`
|
note: required by a bound in `C`
--> src/lib.rs:2:13
|
2 | struct C<T: Copy>(T);
| ^^^^ required by this bound in `C`
help: consider restricting type parameter `T` with trait `Copy`
|
1 | struct S<T: std::marker::Copy >(C<T>);
| +++++++++++++++++
which has an extra space but is correct syntax.
Rust Version
1.90.0-nightly
(2025-07-19 0d9592026226f5a667a0)
Anything else?
No response
Metadata
Metadata
Assignees
Labels
A-diagnosticsArea: Messages for errors, warnings, and lintsArea: Messages for errors, warnings, and lintsA-suggestion-diagnosticsArea: Suggestions generated by the compiler applied by `cargo fix`Area: Suggestions generated by the compiler applied by `cargo fix`D-invalid-suggestionDiagnostics: A structured suggestion resulting in incorrect code.Diagnostics: A structured suggestion resulting in incorrect code.D-papercutDiagnostics: An error or lint that needs small tweaks.Diagnostics: An error or lint that needs small tweaks.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.