Skip to content

Special-case references to leafs in valtree pretty-printing #100359

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,10 @@ pub trait PrettyPrinter<'tcx>:
}
return Ok(self);
}
(ty::ValTree::Leaf(leaf), ty::Ref(_, inner_ty, _)) => {
p!(write("&"));
return self.pretty_print_const_scalar_int(leaf, *inner_ty, print_ty);
}
(ty::ValTree::Leaf(leaf), _) => {
return self.pretty_print_const_scalar_int(leaf, ty, print_ty);
}
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/const-generics/issues/issue-100313.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#![allow(incomplete_features)]
#![feature(const_mut_refs)]
#![feature(adt_const_params)]

struct T<const B: &'static bool>;

impl <const B: &'static bool> T<B> {
const fn set_false(&self) {
unsafe {
*(B as *const bool as *mut bool) = false;
//~^ ERROR evaluation of constant value failed [E0080]
}
}
}

const _: () = {
let x = T::<{&true}>;
x.set_false();
};

fn main() {}
15 changes: 15 additions & 0 deletions src/test/ui/const-generics/issues/issue-100313.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0080]: evaluation of constant value failed
--> $DIR/issue-100313.rs:10:13
|
LL | *(B as *const bool as *mut bool) = false;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| writing to alloc7 which is read-only
| inside `T::<&true>::set_false` at $DIR/issue-100313.rs:10:13
...
LL | x.set_false();
| ------------- inside `_` at $DIR/issue-100313.rs:18:5

error: aborting due to previous error

For more information about this error, try `rustc --explain E0080`.