-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Suggest using anonymous lifetime in impl Trait
return
#58919
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,20 @@ | ||
error[E0621]: explicit lifetime required in the type of `x` | ||
--> $DIR/must_outlive_least_region_or_bound.rs:3:23 | ||
error: cannot infer an appropriate lifetime | ||
--> $DIR/must_outlive_least_region_or_bound.rs:3:35 | ||
| | ||
LL | fn elided(x: &i32) -> impl Copy { x } | ||
| ---- ^^^^^^^^^ lifetime `'static` required | ||
| | | ||
| help: add explicit lifetime `'static` to the type of `x`: `&'static i32` | ||
| --------- ^ ...but this borrow... | ||
| | | ||
| this return type evaluates to the `'static` lifetime... | ||
| | ||
note: ...can't outlive the anonymous lifetime #1 defined on the function body at 3:1 | ||
--> $DIR/must_outlive_least_region_or_bound.rs:3:1 | ||
| | ||
LL | fn elided(x: &i32) -> impl Copy { x } | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: you can add a constraint to the return type to make it last less than `'static` and match the anonymous lifetime #1 defined on the function body at 3:1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Btw... "constraint" here is odd; we typically use "bound" for things in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been using that wording for 6 months, but I agree we could improve on the wording on these errors. |
||
| | ||
LL | fn elided(x: &i32) -> impl Copy + '_ { x } | ||
| ^^^^^^^^^^^^^^ | ||
|
||
error: cannot infer an appropriate lifetime | ||
--> $DIR/must_outlive_least_region_or_bound.rs:6:44 | ||
|
@@ -67,5 +77,5 @@ LL | fn ty_param_wont_outlive_static<T:Debug>(x: T) -> impl Debug + 'static { | |
|
||
error: aborting due to 5 previous errors | ||
|
||
Some errors occurred: E0310, E0621, E0623. | ||
Some errors occurred: E0310, E0623. | ||
For more information about an error, try `rustc --explain E0310`. |
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"evaluates de need of 'static" ?
What is this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A partial rewording of the prior comment 😬
I believe something along the lines of "that evaluates to a need of static".