mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Fix unsafetyck disabling for custom MIR
This commit is contained in:
parent
21ee03e062
commit
c1b27eea45
@ -533,6 +533,11 @@ impl<'tcx> Body<'tcx> {
|
||||
};
|
||||
injection_phase > self.phase
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_custom_mir(&self) -> bool {
|
||||
self.injection_phase.is_some()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Debug, TyEncodable, TyDecodable, HashStable)]
|
||||
|
@ -500,7 +500,7 @@ fn unsafety_check_result<'tcx>(
|
||||
// `mir_built` force this.
|
||||
let body = &tcx.mir_built(def).borrow();
|
||||
|
||||
if body.should_skip() {
|
||||
if body.is_custom_mir() {
|
||||
return tcx.arena.alloc(UnsafetyCheckResult {
|
||||
violations: Vec::new(),
|
||||
used_unsafe_blocks: FxHashSet::default(),
|
||||
|
@ -0,0 +1,10 @@
|
||||
// MIR for `raw_pointer` after built
|
||||
|
||||
fn raw_pointer(_1: *const i32) -> *const i32 {
|
||||
let mut _0: *const i32; // return place in scope 0 at $DIR/references.rs:+0:38: +0:48
|
||||
|
||||
bb0: {
|
||||
_0 = &raw const (*_1); // scope 0 at $DIR/references.rs:+4:9: +4:27
|
||||
return; // scope 0 at $DIR/references.rs:+5:9: +5:17
|
||||
}
|
||||
}
|
@ -36,8 +36,22 @@ pub fn immut_ref(x: &i32) -> &i32 {
|
||||
)
|
||||
}
|
||||
|
||||
// EMIT_MIR references.raw_pointer.built.after.mir
|
||||
#[custom_mir(dialect = "built")]
|
||||
pub fn raw_pointer(x: *const i32) -> *const i32 {
|
||||
// Regression test for a bug in which unsafetyck was not correctly turned off for
|
||||
// `dialect = "built"`
|
||||
mir!({
|
||||
RET = addr_of!(*x);
|
||||
Return()
|
||||
})
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut x = 5;
|
||||
assert_eq!(*mut_ref(&mut x), 5);
|
||||
assert_eq!(*immut_ref(&x), 5);
|
||||
unsafe {
|
||||
assert_eq!(*raw_pointer(addr_of!(x)), 5);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user