Handle anon lifetime arg being returned with named lifetime return type#45751
Handle anon lifetime arg being returned with named lifetime return type#45751bors merged 2 commits intorust-lang:masterfrom
Conversation
|
r? @eddyb (rust_highfive has picked a reviewer for you, use r? to override) |
cfc9c2f to
d3edb01
Compare
When there's a lifetime mismatch between an argument with an anonymous
lifetime being returned in a method with a return type that has a named
lifetime, show specialized lifetime error pointing at argument with a
hint to give it an explicit lifetime matching the return type.
```
error[E0621]: explicit lifetime required in the type of `other`
--> file2.rs:21:21
|
17 | fn bar(&self, other: Foo) -> Foo<'a> {
| ----- consider changing the type of `other` to `Foo<'a>`
...
21 | other
| ^^^^^ lifetime `'a` required
```
Follow up to rust-lang#44124 and rust-lang#42669.
nikomatsakis
left a comment
There was a problem hiding this comment.
Lookin' good. I left a few comments regarding the names of the tests but r=me otherwise.
| /// It has been extended for the case of structs too. | ||
| /// | ||
| /// Consider the example | ||
| /// |
| // the function arguments consist of a named region and an anonymous | ||
| // region and corresponds to `ConcreteFailure(..)` | ||
| /// Generate an error message for when the function arguments consist of a named region and | ||
| /// an anonymous region and corresponds to `ConcreteFailure(..)` |
There was a problem hiding this comment.
Improved, but could be better still =)
| | | ||
| 13 | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T) | ||
| | ----- -- these two types are declared with different lifetimes... | ||
| | - consider changing the type of `y` to `&'a T` |
There was a problem hiding this comment.
It seems to me that this test is misnamed. It is called "both-anon-regions", but, in fact, one of the regions is not anomymous. Maybe rename to something like ex2a-push-one-existing-name-early-bound.rs? (To be honest, the exN- naming scheme is not doing it for me, since it's not clear what list of tests these numbers derive from.)
| } | ||
|
|
||
| impl<'a> Foo<'a> { | ||
| fn bar(&self, other: Foo) -> Foo<'a> { |
There was a problem hiding this comment.
maybe rename to ex1-return-one-existing-name-early-bound-in-struct or something?
|
@nikomatsakis updated @bors r=nikomatsakis rollup |
|
📌 Commit 805333b has been approved by |
Handle anon lifetime arg being returned with named lifetime return type
When there's a lifetime mismatch between an argument with an anonymous
lifetime being returned in a method with a return type that has a named
lifetime, show specialized lifetime error pointing at argument with a
hint to give it an explicit lifetime matching the return type.
```
error[E0621]: explicit lifetime required in the type of `other`
--> file2.rs:21:21
|
17 | fn bar(&self, other: Foo) -> Foo<'a> {
| ----- consider changing the type of `other` to `Foo<'a>`
...
21 | other
| ^^^^^ lifetime `'a` required
```
Follow up to rust-lang#44124 and rust-lang#42669. Fix rust-lang#44684.
When there's a lifetime mismatch between an argument with an anonymous
lifetime being returned in a method with a return type that has a named
lifetime, show specialized lifetime error pointing at argument with a
hint to give it an explicit lifetime matching the return type.
Follow up to #44124 and #42669. Fix #44684.