about summary refs log tree commit diff
path: root/src/test/ui
diff options
context:
space:
mode:
authorEduard-Mihai Burtescu <edy.burt@gmail.com>2016-11-12 10:38:37 +0200
committerGitHub <noreply@github.com>2016-11-12 10:38:37 +0200
commit7894d2aad68be19a7e97194e3df4ec835ca524b6 (patch)
treecf5f3a5d4208804ca365ce362eada9d94a2299c6 /src/test/ui
parent66da9a291152feeedc9bb53f23f4577478b377e1 (diff)
parent87b6d386541c6f7a409775296da1cda2da469c36 (diff)
Rollup merge of #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: #37363.
Diffstat (limited to 'src/test/ui')
-rw-r--r--src/test/ui/lifetimes/consider-using-explicit-lifetime.rs28
-rw-r--r--src/test/ui/lifetimes/consider-using-explicit-lifetime.stderr22
2 files changed, 50 insertions, 0 deletions
diff --git a/src/test/ui/lifetimes/consider-using-explicit-lifetime.rs b/src/test/ui/lifetimes/consider-using-explicit-lifetime.rs
new file mode 100644
index 00000000000..603f55af465
--- /dev/null
+++ b/src/test/ui/lifetimes/consider-using-explicit-lifetime.rs
@@ -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 })
+    }
+}
diff --git a/src/test/ui/lifetimes/consider-using-explicit-lifetime.stderr b/src/test/ui/lifetimes/consider-using-explicit-lifetime.stderr
new file mode 100644
index 00000000000..353e251369a
--- /dev/null
+++ b/src/test/ui/lifetimes/consider-using-explicit-lifetime.stderr
@@ -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
+