about summary refs log tree commit diff
path: root/src/test
diff options
context:
space:
mode:
authorEsteban Küber <esteban@kuber.com.ar>2020-06-28 15:26:12 -0700
committerEsteban Küber <esteban@kuber.com.ar>2020-07-22 12:25:54 -0700
commit4e08bab87dbddea55247013bab9735fa2148ec84 (patch)
tree968799d399f34371f60995ff790a10607ca16dfa /src/test
parent6513148c146c36b0d1649cdb65a3a4737599252f (diff)
downloadrust-4e08bab87dbddea55247013bab9735fa2148ec84.tar.gz
rust-4e08bab87dbddea55247013bab9735fa2148ec84.zip
Increase accuracy of lifetime bound on trait object impl suggestion
Diffstat (limited to 'src/test')
-rw-r--r--src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.rs14
-rw-r--r--src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.stderr18
-rw-r--r--src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.fixed36
-rw-r--r--src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr22
-rw-r--r--src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.rs36
-rw-r--r--src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.stderr32
6 files changed, 123 insertions, 35 deletions
diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.rs b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.rs
deleted file mode 100644
index dd53ee06ff5..00000000000
--- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.rs
+++ /dev/null
@@ -1,14 +0,0 @@
-trait OtherTrait<'a> {}
-impl<'a> OtherTrait<'a> for &'a () {}
-
-trait ObjectTrait {}
-
-impl dyn ObjectTrait {
-    fn use_self(&self) -> &() { panic!() }
-}
-
-fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
-    val.use_self() //~ ERROR mismatched types
-}
-
-fn main() {}
diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.stderr
deleted file mode 100644
index 4618b540c70..00000000000
--- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.stderr
+++ /dev/null
@@ -1,18 +0,0 @@
-error[E0308]: mismatched types
-  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.rs:11:9
-   |
-LL |     val.use_self()
-   |         ^^^^^^^^ lifetime mismatch
-   |
-   = note: expected reference `&(dyn ObjectTrait + 'static)`
-              found reference `&(dyn ObjectTrait + 'a)`
-note: the lifetime `'a` as defined on the function body at 10:11...
-  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound-without-suggestion.rs:10:11
-   |
-LL | fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
-   |           ^^
-   = note: ...does not necessarily outlive the static lifetime
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0308`.
diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.fixed b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.fixed
index dfe475d3c06..62cf9b989bb 100644
--- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.fixed
+++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.fixed
@@ -9,10 +9,12 @@ mod foo {
     trait MyTrait {
         fn use_self(&self) -> &();
     }
+    trait Irrelevant {}
 
     impl MyTrait for dyn ObjectTrait + '_ {
         fn use_self(&self) -> &() { panic!() }
     }
+    impl Irrelevant for dyn ObjectTrait {}
 
     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
         val.use_self() //~ ERROR cannot infer an appropriate lifetime
@@ -24,14 +26,48 @@ mod bar {
     trait MyTrait {
         fn use_self(&self) -> &();
     }
+    trait Irrelevant {}
 
     impl MyTrait for dyn ObjectTrait + '_ {
         fn use_self(&self) -> &() { panic!() }
     }
+    impl Irrelevant for dyn ObjectTrait {}
 
     fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
         val.use_self() //~ ERROR cannot infer an appropriate lifetime
     }
 }
 
+mod baz {
+    trait ObjectTrait {}
+    trait MyTrait {
+        fn use_self(&self) -> &();
+    }
+    trait Irrelevant {}
+
+    impl MyTrait for Box<dyn ObjectTrait + '_> {
+        fn use_self(&self) -> &() { panic!() }
+    }
+    impl Irrelevant for Box<dyn ObjectTrait> {}
+
+    fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
+        val.use_self() //~ ERROR cannot infer an appropriate lifetime
+    }
+}
+
+mod bat {
+    trait OtherTrait<'a> {}
+    impl<'a> OtherTrait<'a> for &'a () {}
+
+    trait ObjectTrait {}
+
+    impl dyn ObjectTrait + '_ {
+        fn use_self(&self) -> &() { panic!() }
+    }
+
+    fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+        val.use_self() //~ ERROR cannot infer an appropriate lifetime
+    }
+}
+
 fn main() {}
diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr
new file mode 100644
index 00000000000..00f65a23489
--- /dev/null
+++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.nll.stderr
@@ -0,0 +1,22 @@
+error[E0521]: borrowed data escapes outside of function
+  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:20:9
+   |
+LL |     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+   |                   --- `val` is a reference that is only valid in the function body
+LL |         val.use_self()
+   |         ^^^^^^^^^^^^^^ `val` escapes the function body here
+   |
+   = help: consider replacing `'a` with `'static`
+
+error[E0521]: borrowed data escapes outside of function
+  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:69:9
+   |
+LL |     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+   |                   --- `val` is a reference that is only valid in the function body
+LL |         val.use_self()
+   |         ^^^^^^^^^^^^^^ `val` escapes the function body here
+   |
+   = help: consider replacing `'a` with `'static`
+
+error: aborting due to 2 previous errors
+
diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.rs b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.rs
index 85e6c2993b9..28a599d12bf 100644
--- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.rs
+++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.rs
@@ -9,10 +9,12 @@ mod foo {
     trait MyTrait {
         fn use_self(&self) -> &();
     }
+    trait Irrelevant {}
 
     impl MyTrait for dyn ObjectTrait {
         fn use_self(&self) -> &() { panic!() }
     }
+    impl Irrelevant for dyn ObjectTrait {}
 
     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
         val.use_self() //~ ERROR cannot infer an appropriate lifetime
@@ -24,14 +26,48 @@ mod bar {
     trait MyTrait {
         fn use_self(&self) -> &();
     }
+    trait Irrelevant {}
 
     impl MyTrait for dyn ObjectTrait {
         fn use_self(&self) -> &() { panic!() }
     }
+    impl Irrelevant for dyn ObjectTrait {}
 
     fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
         val.use_self() //~ ERROR cannot infer an appropriate lifetime
     }
 }
 
+mod baz {
+    trait ObjectTrait {}
+    trait MyTrait {
+        fn use_self(&self) -> &();
+    }
+    trait Irrelevant {}
+
+    impl MyTrait for Box<dyn ObjectTrait> {
+        fn use_self(&self) -> &() { panic!() }
+    }
+    impl Irrelevant for Box<dyn ObjectTrait> {}
+
+    fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
+        val.use_self() //~ ERROR cannot infer an appropriate lifetime
+    }
+}
+
+mod bat {
+    trait OtherTrait<'a> {}
+    impl<'a> OtherTrait<'a> for &'a () {}
+
+    trait ObjectTrait {}
+
+    impl dyn ObjectTrait {
+        fn use_self(&self) -> &() { panic!() }
+    }
+
+    fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+        val.use_self() //~ ERROR cannot infer an appropriate lifetime
+    }
+}
+
 fn main() {}
diff --git a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.stderr b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.stderr
index 6780459adbe..1a03590febe 100644
--- a/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.stderr
+++ b/src/test/ui/suggestions/impl-on-dyn-trait-with-implicit-static-bound.stderr
@@ -1,5 +1,5 @@
 error[E0759]: cannot infer an appropriate lifetime
-  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:18:13
+  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:20:13
    |
 LL |     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
    |                        ------------------- this data with lifetime `'a`...
@@ -12,7 +12,20 @@ LL |     impl MyTrait for dyn ObjectTrait + '_ {
    |                                      ^^^^
 
 error[E0759]: cannot infer an appropriate lifetime
-  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:33:13
+  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:69:13
+   |
+LL |     fn use_it<'a>(val: &'a dyn ObjectTrait) -> impl OtherTrait<'a> + 'a {
+   |                        ------------------- this data with lifetime `'a`...
+LL |         val.use_self()
+   |             ^^^^^^^^ ...is captured and required to live as long as `'static` here
+   |
+help: this `impl` introduces an implicit `'static` requirement, consider changing it
+   |
+LL |     impl dyn ObjectTrait + '_ {
+   |                          ^^^^
+
+error[E0759]: cannot infer an appropriate lifetime
+  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:37:13
    |
 LL |     fn use_it<'a>(val: &'a dyn ObjectTrait) -> &'a () {
    |                        ------------------- this data with lifetime `'a`...
@@ -24,6 +37,19 @@ help: this `impl` introduces an implicit `'static` requirement, consider changin
 LL |     impl MyTrait for dyn ObjectTrait + '_ {
    |                                      ^^^^
 
-error: aborting due to 2 previous errors
+error[E0759]: cannot infer an appropriate lifetime
+  --> $DIR/impl-on-dyn-trait-with-implicit-static-bound.rs:54:13
+   |
+LL |     fn use_it<'a>(val: &'a Box<dyn ObjectTrait + 'a>) -> &'a () {
+   |                        ----------------------------- this data with lifetime `'a`...
+LL |         val.use_self()
+   |             ^^^^^^^^ ...is captured and required to live as long as `'static` here
+   |
+help: this `impl` introduces an implicit `'static` requirement, consider changing it
+   |
+LL |     impl MyTrait for Box<dyn ObjectTrait + '_> {
+   |                                          ^^^^
+
+error: aborting due to 4 previous errors
 
 For more information about this error, try `rustc --explain E0759`.