Code
struct Concrete(u32);
impl Concrete {
fn m(self: &std::boxed::Box<Self>) -> &u32 {
&self.0
}
}
Current output
error[E0106]: missing lifetime specifier
--> src/lib.rs:4:43
|
4 | fn m(self: &std::boxed::Box<Self>) -> &u32 {
| ---------------------- ^ expected named lifetime parameter
|
= help: this function's return type contains a borrowed value, but the signature does not say which `self` it is borrowed from
help: consider introducing a named lifetime parameter
|
4 | fn m<'a>(self: &'a std::boxed::Box<Self>) -> &'a u32 {
| ++++ ++ ++
For more information about this error, try `rustc --explain E0106`.
error: could not compile `playground` (lib) due to previous error
Desired output
Ideally, rustc recognizes the elided lifetime in the `self` parameter and uses that.
Alternatively, "the signature does not say which `self` it is borrowed from" is reworded to more accurately describe the error.
Rationale and extra context
No response
Other cases
No response
Anything else?
fn n(self: &std::boxed::Box<Self>, _other: &u32) -> &u32 {
&self.0
}
results in an error where rustc assumes we're returning the _other parameter, which presumably results from the same failure to spot a lifetime attached to self.
This issue was identified during discussion about a new Rust RFC, here.
I suspect this is caused by something within find_lifetime_for_self which isn't aware of the need to support things like Box as a self type: I haven't spotted the bug yet, I thought it was more important to get it reported properly first.
Code
Current output
Desired output
Rationale and extra context
No response
Other cases
No response
Anything else?
results in an error where rustc assumes we're returning the
_otherparameter, which presumably results from the same failure to spot a lifetime attached toself.This issue was identified during discussion about a new Rust RFC, here.
I suspect this is caused by something within
find_lifetime_for_selfwhich isn't aware of the need to support things likeBoxas aselftype: I haven't spotted the bug yet, I thought it was more important to get it reported properly first.