summaryrefslogtreecommitdiffstats
path: root/tests/ui/suggestions/lifetimes
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/suggestions/lifetimes')
-rw-r--r--tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr2
-rw-r--r--tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr2
-rw-r--r--tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.fixed11
-rw-r--r--tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.rs11
-rw-r--r--tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.stderr15
5 files changed, 39 insertions, 2 deletions
diff --git a/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr b/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr
index 6c63e1ada..2677b7943 100644
--- a/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr
+++ b/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-2.stderr
@@ -14,6 +14,6 @@ help: consider adding an explicit lifetime bound
LL | fn func<'a, T: Test + 'a>(_dummy: &Foo, foo: &Foo<'a>, t: T) {
| +++ ++++ ++++
-error: aborting due to previous error
+error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0311`.
diff --git a/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr b/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr
index 7b126c90e..00bc43d5e 100644
--- a/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr
+++ b/tests/ui/suggestions/lifetimes/missing-lifetimes-in-signature-before-const.stderr
@@ -10,6 +10,6 @@ help: consider introducing a named lifetime parameter
LL | fn buggy_const<'a, const N: usize>(_a: &'a Option<[u8; N]>, _f: &'a str) -> &'a str {
| +++ ++ ++ ++
-error: aborting due to previous error
+error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0106`.
diff --git a/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.fixed b/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.fixed
new file mode 100644
index 000000000..84315ad91
--- /dev/null
+++ b/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.fixed
@@ -0,0 +1,11 @@
+// run-rustfix
+use std::any::Any;
+
+fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
+ Box::new(value) as Box<dyn Any>
+ //~^ ERROR lifetime may not live long enough
+}
+
+fn main() {
+ let _ = foo(&5);
+}
diff --git a/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.rs b/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.rs
new file mode 100644
index 000000000..fa7e72ff2
--- /dev/null
+++ b/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.rs
@@ -0,0 +1,11 @@
+// run-rustfix
+use std::any::Any;
+
+fn foo<T: Any>(value: &T) -> Box<dyn Any> {
+ Box::new(value) as Box<dyn Any>
+ //~^ ERROR lifetime may not live long enough
+}
+
+fn main() {
+ let _ = foo(&5);
+}
diff --git a/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.stderr b/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.stderr
new file mode 100644
index 000000000..73fa5ddb1
--- /dev/null
+++ b/tests/ui/suggestions/lifetimes/suggest-using-tick-underscore-lifetime-in-return-trait-object.stderr
@@ -0,0 +1,15 @@
+error: lifetime may not live long enough
+ --> $DIR/suggest-using-tick-underscore-lifetime-in-return-trait-object.rs:5:5
+ |
+LL | fn foo<T: Any>(value: &T) -> Box<dyn Any> {
+ | - let's call the lifetime of this reference `'1`
+LL | Box::new(value) as Box<dyn Any>
+ | ^^^^^^^^^^^^^^^ cast requires that `'1` must outlive `'static`
+ |
+help: to declare that the trait object captures data from argument `value`, you can add an explicit `'_` lifetime bound
+ |
+LL | fn foo<T: Any>(value: &T) -> Box<dyn Any + '_> {
+ | ++++
+
+error: aborting due to 1 previous error
+