Skip to content

Commit 2b225ba

Browse files
authored
Rollup merge of rust-lang#65011 - estebank:ice-o-matic, r=zackmdavis
Do not ICE when dereferencing non-Copy raw pointer CC rust-lang#52262. Confirmed to remove the unnecessary ICE, but without a repro case.
2 parents c7d7e37 + e8796ca commit 2b225ba

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

src/librustc_mir/borrow_check/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1944,14 +1944,16 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
19441944
self.is_mutable(place.as_ref(), is_local_mutation_allowed),
19451945
self.errors_buffer.is_empty()
19461946
) {
1947-
// rust-lang/rust#46908: In pure NLL mode this code path should
1948-
// be unreachable (and thus we signal an ICE in the else branch here).
1949-
span_bug!(
1950-
span,
1947+
// rust-lang/rust#46908: In pure NLL mode this code path should be
1948+
// unreachable, but we use `delay_span_bug` because we can hit this when
1949+
// dereferencing a non-Copy raw pointer *and* have `-Ztreat-err-as-bug`
1950+
// enabled. We don't want to ICE for that case, as other errors will have
1951+
// been emitted (#52262).
1952+
self.infcx.tcx.sess.delay_span_bug(span, &format!(
19511953
"Accessing `{:?}` with the kind `{:?}` shouldn't be possible",
19521954
place,
19531955
kind,
1954-
);
1956+
));
19551957
}
19561958
return false;
19571959
}

src/test/ui/issues/issue-52262.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// compile-flags:-Ztreat-err-as-bug=5
2+
#[derive(Debug)]
3+
enum MyError {
4+
NotFound { key: Vec<u8> },
5+
Err41,
6+
}
7+
8+
impl std::error::Error for MyError {}
9+
10+
impl std::fmt::Display for MyError {
11+
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
12+
match self {
13+
MyError::NotFound { key } => write!(
14+
f,
15+
"unknown error with code {}.",
16+
String::from_utf8(*key).unwrap()
17+
//~^ ERROR cannot move out of `*key` which is behind a shared reference
18+
),
19+
MyError::Err41 => write!(f, "Sit by a lake"),
20+
}
21+
}
22+
}
23+
fn main() {
24+
println!("Hello, world!");
25+
}

src/test/ui/issues/issue-52262.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0507]: cannot move out of `*key` which is behind a shared reference
2+
--> $DIR/issue-52262.rs:16:35
3+
|
4+
LL | String::from_utf8(*key).unwrap()
5+
| ^^^^ move occurs because `*key` has type `std::vec::Vec<u8>`, which does not implement the `Copy` trait
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0507`.

0 commit comments

Comments
 (0)