Skip to content

Commit 707fd66

Browse files
committed
add test for super let in non-extending if blocks
1 parent 4d1e052 commit 707fd66

File tree

2 files changed

+59
-0
lines changed

2 files changed

+59
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//! Test that `super let` bindings in `if` expressions' blocks have the same scope as the result
2+
//! of the block.
3+
#![feature(super_let)]
4+
5+
fn main() {
6+
// For `super let` in an extending `if`, the binding `temp` should live in the scope of the
7+
// outer `let` statement.
8+
let x = if true {
9+
super let temp = ();
10+
&temp
11+
} else {
12+
super let temp = ();
13+
&temp
14+
};
15+
x;
16+
17+
// For `super let` in non-extending `if`, the binding `temp` should live in the temporary scope
18+
// the `if` expression is in.
19+
// TODO: make this not an error
20+
std::convert::identity(if true {
21+
super let temp = ();
22+
&temp
23+
//~^ ERROR `temp` does not live long enough
24+
} else {
25+
super let temp = ();
26+
&temp
27+
//~^ ERROR `temp` does not live long enough
28+
});
29+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
error[E0597]: `temp` does not live long enough
2+
--> $DIR/super-let-in-if-block.rs:22:9
3+
|
4+
LL | std::convert::identity(if true {
5+
| ---------------------- borrow later used by call
6+
LL | super let temp = ();
7+
| ---- binding `temp` declared here
8+
LL | &temp
9+
| ^^^^^ borrowed value does not live long enough
10+
LL |
11+
LL | } else {
12+
| - `temp` dropped here while still borrowed
13+
14+
error[E0597]: `temp` does not live long enough
15+
--> $DIR/super-let-in-if-block.rs:26:9
16+
|
17+
LL | std::convert::identity(if true {
18+
| ---------------------- borrow later used by call
19+
...
20+
LL | super let temp = ();
21+
| ---- binding `temp` declared here
22+
LL | &temp
23+
| ^^^^^ borrowed value does not live long enough
24+
LL |
25+
LL | });
26+
| - `temp` dropped here while still borrowed
27+
28+
error: aborting due to 2 previous errors
29+
30+
For more information about this error, try `rustc --explain E0597`.

0 commit comments

Comments
 (0)