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#37481 - estebank:lifetime-help-removal-for-…
…impl, r=eddyb Don't provide hint to add lifetime on impl items ``` rust use std::str::FromStr; pub struct Foo<'a> { field: &'a str, } impl<'a> FromStr for Foo<'a> { type Err = (); fn from_str(path: &str) -> Result<Self, ()> { Ok(Foo { field: path }) } } ``` would give the following hint: ``` nocode help: consider using an explicit lifetime parameter as shown: fn from_str(path: &'a str) -> Result<Self, ()> --> <anon>:9:5 | 9 | fn from_str(path: &str) -> Result<Self, ()> { | ^ ``` which is never correct, since then there will be a lifetime mismatch between the `impl` and the trait. Remove this hint for all `impl` items. Re: rust-lang#37363.
- Loading branch information
Showing
4 changed files
with
71 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Copyright 2016 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. | ||
|
||
use std::str::FromStr; | ||
|
||
pub struct Foo<'a> { | ||
field: &'a str, | ||
} | ||
|
||
impl<'a> Foo<'a> { | ||
fn bar(path: &str) -> Result<Self, ()> { | ||
Ok(Foo { field: path }) | ||
} | ||
} | ||
|
||
impl<'a> FromStr for Foo<'a> { | ||
type Err = (); | ||
fn from_str(path: &str) -> Result<Self, ()> { | ||
Ok(Foo { field: path }) | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/test/ui/lifetimes/consider-using-explicit-lifetime.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,22 @@ | ||
error: main function not found | ||
|
||
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements | ||
--> $DIR/consider-using-explicit-lifetime.rs:19:12 | ||
| | ||
19 | Ok(Foo { field: path }) | ||
| ^^^ | ||
|
||
error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements | ||
--> $DIR/consider-using-explicit-lifetime.rs:26:12 | ||
| | ||
26 | Ok(Foo { field: path }) | ||
| ^^^ | ||
| | ||
help: consider using an explicit lifetime parameter as shown: fn from_str(path: &'a str) -> Result<Self, ()> | ||
--> $DIR/consider-using-explicit-lifetime.rs:25:5 | ||
| | ||
25 | fn from_str(path: &str) -> Result<Self, ()> { | ||
| ^ | ||
|
||
error: aborting due to 2 previous errors | ||
|