Skip to content

Commit 00f17a9

Browse files
authored
rename y to _y to get the correct compile error
Without this change, the error is: ``` Compiling playground v0.0.1 (/playground) warning: unused variable: `y` --> src/main.rs:13:9 | 13 | let y: &'a i32 = &_x; | ^ help: if this is intentional, prefix it with an underscore: `_y` | = note: `#[warn(unused_variables)]` on by default error[E0597]: `_x` does not live long enough --> src/main.rs:13:22 | 9 | fn failed_borrow<'a>() { | -- lifetime `'a` defined here 10 | let _x = 12; | -- binding `_x` declared here ... 13 | let y: &'a i32 = &_x; | ------- ^^^ borrowed value does not live long enough | | | type annotation requires that `_x` is borrowed for `'a` ... 17 | } | - `_x` dropped here while still borrowed For more information about this error, try `rustc --explain E0597`. warning: `playground` (bin "playground") generated 1 warning error: could not compile `playground` (bin "playground") due to previous error; 1 warning emitted ```
1 parent 6af3f81 commit 00f17a9

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

src/scope/lifetime/explicit.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn failed_borrow<'a>() {
4040
let _x = 12;
4141
4242
// ERROR: `_x` does not live long enough
43-
let y: &'a i32 = &_x;
43+
let _y: &'a i32 = &_x;
4444
// Attempting to use the lifetime `'a` as an explicit type annotation
4545
// inside the function will fail because the lifetime of `&_x` is shorter
4646
// than that of `y`. A short lifetime cannot be coerced into a longer one.

0 commit comments

Comments
 (0)