Skip to content

Commit 4651d1e

Browse files
committed
Added test for #46471
1 parent ddbb27a commit 4651d1e

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/test/ui/issue-46471.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-flags: -Z emit-end-regions -Z borrowck=compare
12+
13+
fn foo() -> &'static u32 {
14+
let x = 0;
15+
&x
16+
//~^ ERROR `x` does not live long enough (Ast) [E0597]
17+
//~| ERROR `x` does not live long enough (Mir) [E0597]
18+
}
19+
20+
fn main() { }

src/test/ui/issue-46471.stderr

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
error[E0597]: `x` does not live long enough (Ast)
2+
--> $DIR/issue-46471.rs:15:6
3+
|
4+
15 | &x
5+
| ^ does not live long enough
6+
...
7+
18 | }
8+
| - borrowed value only lives until here
9+
|
10+
= note: borrowed value must be valid for the static lifetime...
11+
12+
error[E0597]: `x` does not live long enough (Mir)
13+
--> $DIR/issue-46471.rs:15:5
14+
|
15+
15 | &x
16+
| ^^ does not live long enough
17+
...
18+
18 | }
19+
| - borrowed value only lives until here
20+
|
21+
= note: borrowed value must be valid for the static lifetime...
22+
23+
error: aborting due to 2 previous errors
24+

0 commit comments

Comments
 (0)