about summary refs log tree commit diff
path: root/src/librustc/error_codes.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2019-10-08 17:31:35 +0000
committerbors <bors@rust-lang.org>2019-10-08 17:31:35 +0000
commit2748a9fd93dd1a00a4521f4f16de5befbf77f6cd (patch)
treed889f76e88e1ab000a0b64d9337868d8deeeccb3 /src/librustc/error_codes.rs
parent3fa9554d77960627cb2c983470bceacfeeb486b0 (diff)
parent3246ab2427494abb59ecf3718f4dec83a0de406e (diff)
Auto merge of #65209 - Centril:rollup-tzc0j87, r=Centril
Rollup of 8 pull requests

Successful merges:

 - #64404 (Add long error explanation for E0495)
 - #64918 (Add long error explanation for E0551)
 - #65102 (Disable stack probe when thread sanitizer is enabled)
 - #65120 (Correctly estimate the required space for string in `StyledBuffer::prepend`)
 - #65145 (When suggesting assoc function with type params, include turbofish)
 - #65162 (Remove loaded_from_cache map from DepGraph)
 - #65176 (Remove query-related macros)
 - #65179 (Add long error explanation for E0567)

Failed merges:

r? @ghost
Diffstat (limited to 'src/librustc/error_codes.rs')
-rw-r--r--src/librustc/error_codes.rs43
1 files changed, 41 insertions, 2 deletions
diff --git a/src/librustc/error_codes.rs b/src/librustc/error_codes.rs
index 502172db91c..4cee132ecae 100644
--- a/src/librustc/error_codes.rs
+++ b/src/librustc/error_codes.rs
@@ -1520,6 +1520,47 @@ where
 ```
 "##,
 
+E0495: r##"
+A lifetime cannot be determined in the given situation.
+
+Erroneous code example:
+
+```compile_fail,E0495
+fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
+    match (&t,) { // error!
+        ((u,),) => u,
+    }
+}
+
+let y = Box::new((42,));
+let x = transmute_lifetime(&y);
+```
+
+In this code, you have two ways to solve this issue:
+ 1. Enforce that `'a` lives at least as long as `'b`.
+ 2. Use the same lifetime requirement for both input and output values.
+
+So for the first solution, you can do it by replacing `'a` with `'a: 'b`:
+
+```
+fn transmute_lifetime<'a: 'b, 'b, T>(t: &'a (T,)) -> &'b T {
+    match (&t,) { // ok!
+        ((u,),) => u,
+    }
+}
+```
+
+In the second you can do it by simply removing `'b` so they both use `'a`:
+
+```
+fn transmute_lifetime<'a, T>(t: &'a (T,)) -> &'a T {
+    match (&t,) { // ok!
+        ((u,),) => u,
+    }
+}
+```
+"##,
+
 E0496: r##"
 A lifetime name is shadowing another lifetime name. Erroneous code example:
 
@@ -2116,8 +2157,6 @@ rejected in your own crates.
     E0488, // lifetime of variable does not enclose its declaration
     E0489, // type/lifetime parameter not in scope here
     E0490, // a value of type `..` is borrowed for too long
-    E0495, // cannot infer an appropriate lifetime due to conflicting
-           // requirements
     E0623, // lifetime mismatch where both parameters are anonymous regions
     E0628, // generators cannot have explicit parameters
     E0631, // type mismatch in closure arguments