Skip to content

Commit 96fc9f1

Browse files
Rollup merge of rust-lang#100359 - b-naber:valtrees-pretty-print-ice, r=lcnr
Special-case references to leafs in valtree pretty-printing Fixes rust-lang#100313
2 parents efa182f + 4bf350d commit 96fc9f1

File tree

3 files changed

+40
-0
lines changed

3 files changed

+40
-0
lines changed

compiler/rustc_middle/src/ty/print/pretty.rs

+4
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,10 @@ pub trait PrettyPrinter<'tcx>:
15131513
}
15141514
return Ok(self);
15151515
}
1516+
(ty::ValTree::Leaf(leaf), ty::Ref(_, inner_ty, _)) => {
1517+
p!(write("&"));
1518+
return self.pretty_print_const_scalar_int(leaf, *inner_ty, print_ty);
1519+
}
15161520
(ty::ValTree::Leaf(leaf), _) => {
15171521
return self.pretty_print_const_scalar_int(leaf, ty, print_ty);
15181522
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#![allow(incomplete_features)]
2+
#![feature(const_mut_refs)]
3+
#![feature(adt_const_params)]
4+
5+
struct T<const B: &'static bool>;
6+
7+
impl <const B: &'static bool> T<B> {
8+
const fn set_false(&self) {
9+
unsafe {
10+
*(B as *const bool as *mut bool) = false;
11+
//~^ ERROR evaluation of constant value failed [E0080]
12+
}
13+
}
14+
}
15+
16+
const _: () = {
17+
let x = T::<{&true}>;
18+
x.set_false();
19+
};
20+
21+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0080]: evaluation of constant value failed
2+
--> $DIR/issue-100313.rs:10:13
3+
|
4+
LL | *(B as *const bool as *mut bool) = false;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
| |
7+
| writing to alloc7 which is read-only
8+
| inside `T::<&true>::set_false` at $DIR/issue-100313.rs:10:13
9+
...
10+
LL | x.set_false();
11+
| ------------- inside `_` at $DIR/issue-100313.rs:18:5
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0080`.

0 commit comments

Comments
 (0)