forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#45751 - estebank:issue-44684, r=nikomatsakis
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.
- Loading branch information
Showing
9 changed files
with
95 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
src/test/ui/lifetime-errors/ex1-return-one-existing-name-early-bound-in-struct.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#[derive(Clone)] | ||
enum Foo<'a> { | ||
Bar(&'a str), | ||
} | ||
|
||
impl<'a> Foo<'a> { | ||
fn bar(&self, other: Foo) -> Foo<'a> { | ||
match *self { | ||
Foo::Bar(s) => { | ||
if s == "test" { | ||
other | ||
} else { | ||
self.clone() | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
fn main() { } |
11 changes: 11 additions & 0 deletions
11
src/test/ui/lifetime-errors/ex1-return-one-existing-name-early-bound-in-struct.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0621]: explicit lifetime required in the type of `other` | ||
--> $DIR/ex1-return-one-existing-name-early-bound-in-struct.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 | ||
|
||
error: aborting due to previous error | ||
|
File renamed without changes.
11 changes: 11 additions & 0 deletions
11
src/test/ui/lifetime-errors/ex2a-push-one-existing-name-early-bound.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
error[E0621]: explicit lifetime required in the type of `y` | ||
--> $DIR/ex2a-push-one-existing-name-early-bound.rs:17:12 | ||
| | ||
13 | fn baz<'a, 'b, T>(x: &mut Vec<&'a T>, y: &T) | ||
| - consider changing the type of `y` to `&'a T` | ||
... | ||
17 | x.push(y); | ||
| ^ lifetime `'a` required | ||
|
||
error: aborting due to previous error | ||
|
11 changes: 0 additions & 11 deletions
11
src/test/ui/lifetime-errors/ex3-both-anon-regions-earlybound-regions.stderr
This file was deleted.
Oops, something went wrong.