Skip to content

Commit d9e0637

Browse files
committed
Fix drop ref and stack
1 parent 909882b commit d9e0637

4 files changed

Lines changed: 37 additions & 1 deletion

File tree

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extern crate ref_mut_stack;
2+
3+
use ref_mut_stack::{ParkableRefMut, RefMutStack};
4+
5+
fn main() {
6+
struct Root;
7+
8+
let mut root = Root;
9+
10+
struct Type<'a>(ParkableRefMut<'a, Root, Self>);
11+
12+
let mut stack = RefMutStack::<Root, Type>::new(&mut root);
13+
drop(root);
14+
//~^ ERROR 13:10: 13:14: cannot move out of `root` because it is borrowed [E0505]
15+
stack.borrow_mut();
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
extern crate ref_mut_stack;
2+
3+
use ref_mut_stack::{ParkableRefMut, RefMutStack};
4+
5+
fn main() {
6+
struct Root;
7+
8+
let mut root = Root;
9+
10+
struct Type<'a>(ParkableRefMut<'a, Root, Self>);
11+
12+
let mut stack = RefMutStack::<Root, Type>::new(&mut root);
13+
let r = stack.borrow_mut();
14+
drop(stack);
15+
//~^ ERROR 14:10: 14:15: cannot move out of `stack` because it is borrowed [E0505]
16+
}

justfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ watch_clippy:
1717
test *args:
1818
cargo test --all-features {{args}}
1919

20+
[working-directory: 'compile-tests']
21+
compile-test *args:
22+
cargo test --all-features {{args}}
23+
2024
miri:
2125
cargo miri test --all-features
2226

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct RefMutStack<'a, R, T> {
1010
}
1111

1212
impl<'a, R, T> RefMutStack<'a, R, T> {
13-
pub fn new(r: &mut R) -> Self {
13+
pub fn new(r: &'a mut R) -> Self {
1414
Self {
1515
root_ref: NonNull::from_mut(r),
1616
stack: Vec::new(),

0 commit comments

Comments
 (0)