Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix ICE when a borrow is used after drop
ht @nickfrostatx for the first initial patch
- Loading branch information
1 parent
4b9b70c
commit 2e87dbb
Showing
3 changed files
with
67 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![allow(warnings)] | ||
#![feature(nll)] | ||
|
||
use std::collections::BinaryHeap; | ||
|
||
fn main() { | ||
let mut heap: BinaryHeap<i32> = BinaryHeap::new(); | ||
let borrow = heap.peek_mut(); | ||
|
||
match (borrow, ()) { | ||
(Some(_), ()) => { | ||
println!("{:?}", heap); //~ ERROR cannot borrow `heap` as immutable | ||
} | ||
_ => {} | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
error[E0502]: cannot borrow `heap` as immutable because it is also borrowed as mutable | ||
--> $DIR/issue-47646.rs:22:30 | ||
| | ||
LL | let borrow = heap.peek_mut(); | ||
| ---- mutable borrow occurs here | ||
LL | | ||
LL | match (borrow, ()) { | ||
| ------------ borrow may end up in a temporary, created here | ||
LL | (Some(_), ()) => { | ||
LL | println!("{:?}", heap); //~ ERROR cannot borrow `heap` as immutable | ||
| ^^^^ immutable borrow occurs here | ||
... | ||
LL | }; | ||
| - temporary later dropped here, potentially using the reference | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0502`. |