Code
// edition: 2021
trait Trait {}
fn fun() -> &Trait {
todo!()
}
fn main() {}
Current output
error[E0106]: missing lifetime specifier
--> <source>:5:13
|
5 | fn fun() -> &Trait {
| ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
|
5 | fn fun() -> &'static Trait {
| +++++++
error[E0782]: trait objects must include the `dyn` keyword
--> <source>:5:14
|
5 | fn fun() -> &Trait {
| ^^^^^
|
help: add `dyn` keyword before this trait
|
5 | fn fun() -> &dyn Trait {
| +++
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0106, E0782.
For more information about an error, try `rustc --explain E0106`.
Desired output
error[E0782]: trait objects must include the `dyn` keyword
--> <source>:5:14
|
5 | fn fun() -> &Trait {
| ^^^^^
|
help: add `dyn` keyword before this trait
|
5 | fn fun() -> &dyn Trait {
| +++
error: aborting due to 2 previous errors
Some errors have detailed explanations: E0106, E0782.
For more information about an error, try `rustc --explain E0106`.
Rationale and extra context
The error E0106 suggests to add a static lifetime but this is incorrect. If and when #127692 is merged, the error E0782 can provide accurate and helpful messages and the former should be suppressed in favor of E0782.
But this can be tricky as E0106 is emitted at rustc_resolve which doesn't have any context about type of values.
Rust Version
Anything else?
No response
Code
Current output
Desired output
Rationale and extra context
The error E0106 suggests to add a static lifetime but this is incorrect. If and when #127692 is merged, the error E0782 can provide accurate and helpful messages and the former should be suppressed in favor of E0782.
But this can be tricky as E0106 is emitted at
rustc_resolvewhich doesn't have any context about type of values.Rust Version
Anything else?
No response