mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
test improvements
This commit is contained in:
parent
61f23e0003
commit
b95852b93c
@ -2048,7 +2048,11 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
||||
}
|
||||
UnaryOp(ref op, ref a) => write!(fmt, "{:?}({:?})", op, a),
|
||||
Discriminant(ref place) => write!(fmt, "discriminant({:?})", place),
|
||||
NullaryOp(ref op, ref t) => write!(fmt, "{:?}({:?})", op, t),
|
||||
NullaryOp(ref op, ref t) => match op {
|
||||
NullOp::SizeOf => write!(fmt, "SizeOf({:?})", t),
|
||||
NullOp::AlignOf => write!(fmt, "AlignOf({:?})", t),
|
||||
NullOp::OffsetOf(fields) => write!(fmt, "OffsetOf({:?}, {:?})", t, fields),
|
||||
},
|
||||
ThreadLocalRef(did) => ty::tls::with(|tcx| {
|
||||
let muta = tcx.static_mutability(did).unwrap().prefix_str();
|
||||
write!(fmt, "&/*tls*/ {}{}", muta, tcx.def_path_str(did))
|
||||
|
@ -438,3 +438,24 @@ fn offset_of_dst() {
|
||||
assert_eq!(offset_of!(Foo, x), 0);
|
||||
assert_eq!(offset_of!(Foo, y), 2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[cfg(not(bootstrap))]
|
||||
fn offset_of_addr() {
|
||||
#[repr(C)]
|
||||
struct Foo {
|
||||
x: u8,
|
||||
y: u16,
|
||||
z: Bar,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Bar(u8, u8);
|
||||
|
||||
let base = Foo { x: 0, y: 0, z: Bar(0, 0) };
|
||||
|
||||
assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, x), ptr::addr_of!(base.x).addr());
|
||||
assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, y), ptr::addr_of!(base.y).addr());
|
||||
assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, z.0), ptr::addr_of!(base.z.0).addr());
|
||||
assert_eq!(ptr::addr_of!(base).addr() + offset_of!(Foo, z.1), ptr::addr_of!(base.z.1).addr());
|
||||
}
|
||||
|
@ -1,8 +1,8 @@
|
||||
- // MIR for `main` before ConstProp
|
||||
+ // MIR for `main` after ConstProp
|
||||
- // MIR for `concrete` before ConstProp
|
||||
+ // MIR for `concrete` after ConstProp
|
||||
|
||||
fn main() -> () {
|
||||
let mut _0: (); // return place in scope 0 at $DIR/offset_of.rs:+0:11: +0:11
|
||||
fn concrete() -> () {
|
||||
let mut _0: (); // return place in scope 0 at $DIR/offset_of.rs:+0:15: +0:15
|
||||
let _1: usize; // in scope 0 at $DIR/offset_of.rs:+1:9: +1:10
|
||||
scope 1 {
|
||||
debug x => _1; // in scope 1 at $DIR/offset_of.rs:+1:9: +1:10
|
||||
@ -22,17 +22,17 @@
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1); // scope 0 at $DIR/offset_of.rs:+1:9: +1:10
|
||||
- _1 = OffsetOf([0])(Foo); // scope 0 at $DIR/offset_of.rs:+1:13: +1:31
|
||||
+ _1 = const 0_usize; // scope 0 at $DIR/offset_of.rs:+1:13: +1:31
|
||||
- _1 = OffsetOf(Alpha, [0]); // scope 0 at $DIR/offset_of.rs:+1:13: +1:33
|
||||
+ _1 = const 4_usize; // scope 0 at $DIR/offset_of.rs:+1:13: +1:33
|
||||
StorageLive(_2); // scope 1 at $DIR/offset_of.rs:+2:9: +2:10
|
||||
- _2 = OffsetOf([1])(Foo); // scope 1 at $DIR/offset_of.rs:+2:13: +2:31
|
||||
+ _2 = const 2_usize; // scope 1 at $DIR/offset_of.rs:+2:13: +2:31
|
||||
- _2 = OffsetOf(Alpha, [1]); // scope 1 at $DIR/offset_of.rs:+2:13: +2:33
|
||||
+ _2 = const 0_usize; // scope 1 at $DIR/offset_of.rs:+2:13: +2:33
|
||||
StorageLive(_3); // scope 2 at $DIR/offset_of.rs:+3:9: +3:11
|
||||
- _3 = OffsetOf([2, 0])(Foo); // scope 2 at $DIR/offset_of.rs:+3:14: +3:34
|
||||
+ _3 = const 4_usize; // scope 2 at $DIR/offset_of.rs:+3:14: +3:34
|
||||
- _3 = OffsetOf(Alpha, [2, 0]); // scope 2 at $DIR/offset_of.rs:+3:14: +3:36
|
||||
+ _3 = const 2_usize; // scope 2 at $DIR/offset_of.rs:+3:14: +3:36
|
||||
StorageLive(_4); // scope 3 at $DIR/offset_of.rs:+4:9: +4:11
|
||||
- _4 = OffsetOf([2, 1])(Foo); // scope 3 at $DIR/offset_of.rs:+4:14: +4:34
|
||||
+ _4 = const 5_usize; // scope 3 at $DIR/offset_of.rs:+4:14: +4:34
|
||||
- _4 = OffsetOf(Alpha, [2, 1]); // scope 3 at $DIR/offset_of.rs:+4:14: +4:36
|
||||
+ _4 = const 3_usize; // scope 3 at $DIR/offset_of.rs:+4:14: +4:36
|
||||
StorageDead(_4); // scope 3 at $DIR/offset_of.rs:+5:1: +5:2
|
||||
StorageDead(_3); // scope 2 at $DIR/offset_of.rs:+5:1: +5:2
|
||||
StorageDead(_2); // scope 1 at $DIR/offset_of.rs:+5:1: +5:2
|
39
tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff
Normal file
39
tests/mir-opt/const_prop/offset_of.generic.ConstProp.diff
Normal file
@ -0,0 +1,39 @@
|
||||
- // MIR for `generic` before ConstProp
|
||||
+ // MIR for `generic` after ConstProp
|
||||
|
||||
fn generic() -> () {
|
||||
let mut _0: (); // return place in scope 0 at $DIR/offset_of.rs:+0:17: +0:17
|
||||
let _1: usize; // in scope 0 at $DIR/offset_of.rs:+1:9: +1:11
|
||||
scope 1 {
|
||||
debug gx => _1; // in scope 1 at $DIR/offset_of.rs:+1:9: +1:11
|
||||
let _2: usize; // in scope 1 at $DIR/offset_of.rs:+2:9: +2:11
|
||||
scope 2 {
|
||||
debug gy => _2; // in scope 2 at $DIR/offset_of.rs:+2:9: +2:11
|
||||
let _3: usize; // in scope 2 at $DIR/offset_of.rs:+3:9: +3:11
|
||||
scope 3 {
|
||||
debug dx => _3; // in scope 3 at $DIR/offset_of.rs:+3:9: +3:11
|
||||
let _4: usize; // in scope 3 at $DIR/offset_of.rs:+4:9: +4:11
|
||||
scope 4 {
|
||||
debug dy => _4; // in scope 4 at $DIR/offset_of.rs:+4:9: +4:11
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bb0: {
|
||||
StorageLive(_1); // scope 0 at $DIR/offset_of.rs:+1:9: +1:11
|
||||
_1 = OffsetOf(Gamma<T>, [0]); // scope 0 at $DIR/offset_of.rs:+1:14: +1:37
|
||||
StorageLive(_2); // scope 1 at $DIR/offset_of.rs:+2:9: +2:11
|
||||
_2 = OffsetOf(Gamma<T>, [1]); // scope 1 at $DIR/offset_of.rs:+2:14: +2:37
|
||||
StorageLive(_3); // scope 2 at $DIR/offset_of.rs:+3:9: +3:11
|
||||
_3 = OffsetOf(Delta<T>, [1]); // scope 2 at $DIR/offset_of.rs:+3:14: +3:37
|
||||
StorageLive(_4); // scope 3 at $DIR/offset_of.rs:+4:9: +4:11
|
||||
_4 = OffsetOf(Delta<T>, [2]); // scope 3 at $DIR/offset_of.rs:+4:14: +4:37
|
||||
StorageDead(_4); // scope 3 at $DIR/offset_of.rs:+5:1: +5:2
|
||||
StorageDead(_3); // scope 2 at $DIR/offset_of.rs:+5:1: +5:2
|
||||
StorageDead(_2); // scope 1 at $DIR/offset_of.rs:+5:1: +5:2
|
||||
StorageDead(_1); // scope 0 at $DIR/offset_of.rs:+5:1: +5:2
|
||||
return; // scope 0 at $DIR/offset_of.rs:+5:2: +5:2
|
||||
}
|
||||
}
|
||||
|
@ -1,25 +1,49 @@
|
||||
// unit-test
|
||||
// compile-flags: -O
|
||||
|
||||
// EMIT_MIR offset_of.main.ConstProp.diff
|
||||
|
||||
#![feature(offset_of)]
|
||||
|
||||
use std::marker::PhantomData;
|
||||
use std::mem::offset_of;
|
||||
|
||||
#[repr(C)]
|
||||
struct Foo {
|
||||
struct Alpha {
|
||||
x: u8,
|
||||
y: u16,
|
||||
z: Bar,
|
||||
z: Beta,
|
||||
}
|
||||
|
||||
struct Beta(u8, u8);
|
||||
|
||||
struct Gamma<T> {
|
||||
x: u8,
|
||||
y: u16,
|
||||
_t: T,
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
struct Bar(u8, u8);
|
||||
struct Delta<T> {
|
||||
_phantom: PhantomData<T>,
|
||||
x: u8,
|
||||
y: u16,
|
||||
}
|
||||
|
||||
// EMIT_MIR offset_of.concrete.ConstProp.diff
|
||||
fn concrete() {
|
||||
let x = offset_of!(Alpha, x);
|
||||
let y = offset_of!(Alpha, y);
|
||||
let z0 = offset_of!(Alpha, z.0);
|
||||
let z1 = offset_of!(Alpha, z.1);
|
||||
}
|
||||
|
||||
// EMIT_MIR offset_of.generic.ConstProp.diff
|
||||
fn generic<T>() {
|
||||
let gx = offset_of!(Gamma<T>, x);
|
||||
let gy = offset_of!(Gamma<T>, y);
|
||||
let dx = offset_of!(Delta<T>, x);
|
||||
let dy = offset_of!(Delta<T>, y);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let x = offset_of!(Foo, x);
|
||||
let y = offset_of!(Foo, y);
|
||||
let z0 = offset_of!(Foo, z.0);
|
||||
let z1 = offset_of!(Foo, z.1);
|
||||
concrete();
|
||||
generic::<()>();
|
||||
}
|
||||
|
@ -19,8 +19,26 @@ struct Gamma {
|
||||
b: (),
|
||||
}
|
||||
|
||||
struct Delta {
|
||||
a: (),
|
||||
b: (), //~ ERROR field `b` is never read
|
||||
}
|
||||
|
||||
trait Trait {
|
||||
type Assoc;
|
||||
}
|
||||
impl Trait for () {
|
||||
type Assoc = Delta;
|
||||
}
|
||||
|
||||
struct Project<T: Trait> {
|
||||
a: u8, //~ ERROR field `a` is never read
|
||||
b: <T as Trait>::Assoc,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
offset_of!(Alpha, a);
|
||||
offset_of!(Alpha, c.b);
|
||||
offset_of!((Gamma,), 0.b);
|
||||
offset_of!(Project::<()>, b.a);
|
||||
}
|
||||
|
@ -29,5 +29,22 @@ LL | struct Gamma {
|
||||
LL | a: (),
|
||||
| ^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error: field `b` is never read
|
||||
--> $DIR/liveness-offset-of.rs:24:5
|
||||
|
|
||||
LL | struct Delta {
|
||||
| ----- field in this struct
|
||||
LL | a: (),
|
||||
LL | b: (),
|
||||
| ^
|
||||
|
||||
error: field `a` is never read
|
||||
--> $DIR/liveness-offset-of.rs:35:5
|
||||
|
|
||||
LL | struct Project<T: Trait> {
|
||||
| ------- field in this struct
|
||||
LL | a: u8,
|
||||
| ^
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user