Skip to content

Commit afb1e19

Browse files
committed
Rollup merge of rust-lang#47368 - chrisvittal:nll-tests, r=nikomatsakis
Add NLL tests for rust-lang#46557 and rust-lang#38899 This adapts the sample code from the two issues into test code. Closes rust-lang#46557 Closes rust-lang#38899 r? @nikomatsakis
2 parents 6966f33 + e14720b commit afb1e19

4 files changed

+75
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright 2018 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+
// Regression test for issue #38899
12+
13+
#![feature(nll)]
14+
#![allow(dead_code)]
15+
16+
pub struct Block<'a> {
17+
current: &'a u8,
18+
unrelated: &'a u8,
19+
}
20+
21+
fn bump<'a>(mut block: &mut Block<'a>) {
22+
let x = &mut block;
23+
println!("{}", x.current);
24+
let p: &'a u8 = &*block.current;
25+
//~^ ERROR cannot borrow `*block.current` as immutable because it is also borrowed as mutable
26+
drop(x);
27+
drop(p);
28+
}
29+
30+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0502]: cannot borrow `*block.current` as immutable because it is also borrowed as mutable
2+
--> $DIR/borrowed-referent-issue-38899.rs:24:21
3+
|
4+
22 | let x = &mut block;
5+
| ---------- mutable borrow occurs here
6+
23 | println!("{}", x.current);
7+
24 | let p: &'a u8 = &*block.current;
8+
| ^^^^^^^^^^^^^^^ immutable borrow occurs here
9+
10+
error: aborting due to previous error
11+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2018 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+
// Regression test for issue #46557
12+
13+
#![feature(nll)]
14+
#![allow(dead_code)]
15+
16+
fn gimme_static_mut() -> &'static mut u32 {
17+
let ref mut x = 1234543; //~ ERROR borrowed value does not live long enough [E0597]
18+
x
19+
}
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
error[E0597]: borrowed value does not live long enough
2+
--> $DIR/return-ref-mut-issue-46557.rs:17:21
3+
|
4+
17 | let ref mut x = 1234543; //~ ERROR borrowed value does not live long enough [E0597]
5+
| ^^^^^^^ temporary value does not live long enough
6+
18 | x
7+
19 | }
8+
| - temporary value only lives until here
9+
|
10+
= note: borrowed value must be valid for lifetime '_#2r...
11+
12+
error: aborting due to previous error
13+

0 commit comments

Comments
 (0)