Auto merge of #67133 - oli-obk:it_must_be_a_sign, r=eddyb

Deduplicate pretty printing of constants

r? @eddyb for the pretty printing logic
cc @RalfJung
This commit is contained in:
bors 2020-03-16 16:31:23 +00:00
commit dd67187965
15 changed files with 396 additions and 206 deletions

View file

@ -14,7 +14,7 @@ fn main() {}
// START rustc.FOO.PromoteTemps.before.mir
// bb0: {
// ...
// _5 = const Scalar(alloc1+0) : &i32;
// _5 = const {alloc1+0: &i32};
// _4 = &(*_5);
// _3 = [move _4];
// _2 = &_3;
@ -31,7 +31,7 @@ fn main() {}
// START rustc.BAR.PromoteTemps.before.mir
// bb0: {
// ...
// _5 = const Scalar(alloc0+0) : &i32;
// _5 = const {alloc0+0: &i32};
// _4 = &(*_5);
// _3 = [move _4];
// _2 = &_3;

View file

@ -31,7 +31,7 @@ fn main() {
// START rustc.main.ConstProp.after.mir
// bb0: {
// ...
// _3 = const Scalar(0x01) : std::option::Option<bool>;
// _3 = const {transmute(0x01): std::option::Option<bool>};
// _4 = const 1isize;
// switchInt(const 1isize) -> [1isize: bb2, otherwise: bb1];
// }

View file

@ -29,7 +29,7 @@ fn main() {
// START rustc.main.ConstProp.after.mir
// bb0: {
// ...
// _3 = const Scalar(<ZST>) : ();
// _3 = const ();
// _2 = (move _3, const 0u8, const 0u8);
// ...
// _1 = const encode(move _2) -> bb1;

View file

@ -10,10 +10,10 @@ fn main() {
// START rustc.main.ConstProp.before.mir
// bb0: {
// ...
// _3 = const Scalar(alloc0+0) : &u8;
// _3 = const {alloc0+0: &u8};
// _2 = (*_3);
// ...
// _5 = const Scalar(alloc0+0) : &u8;
// _5 = const {alloc0+0: &u8};
// _4 = (*_5);
// _1 = Add(move _2, move _4);
// ...

View file

@ -1,18 +1,18 @@
// compile-flags: -C overflow-checks=no
fn use_zst(_: ((), ())) { }
fn use_zst(_: ((), ())) {}
struct Temp {
x: u8
x: u8,
}
fn use_u8(_: u8) { }
fn use_u8(_: u8) {}
fn main() {
let ((), ()) = ((), ());
use_zst(((), ()));
use_u8((Temp { x : 40 }).x + 2);
use_u8((Temp { x: 40 }).x + 2);
}
// END RUST SOURCE
@ -35,28 +35,28 @@ fn main() {
// bb0: {
// StorageLive(_1);
// StorageLive(_2);
// _2 = const Scalar(<ZST>) : ();
// _2 = const ();
// StorageLive(_3);
// _3 = const Scalar(<ZST>) : ();
// _1 = const Scalar(<ZST>) : ((), ());
// _3 = const ();
// _1 = const {transmute(()): ((), ())};
// StorageDead(_3);
// StorageDead(_2);
// StorageDead(_1);
// StorageLive(_4);
// StorageLive(_6);
// _6 = const Scalar(<ZST>) : ();
// _6 = const ();
// StorageLive(_7);
// _7 = const Scalar(<ZST>) : ();
// _7 = const ();
// StorageDead(_7);
// StorageDead(_6);
// _4 = const use_zst(const Scalar(<ZST>) : ((), ())) -> bb1;
// _4 = const use_zst(const {transmute(()): ((), ())}) -> bb1;
// }
// bb1: {
// StorageDead(_4);
// StorageLive(_8);
// StorageLive(_10);
// StorageLive(_11);
// _11 = const Scalar(0x28) : Temp;
// _11 = const {transmute(0x28) : Temp};
// _10 = const 40u8;
// StorageDead(_10);
// _8 = const use_u8(const 42u8) -> bb2;
@ -75,7 +75,7 @@ fn main() {
// }
// bb0: {
// StorageLive(_1);
// _1 = const use_zst(const Scalar(<ZST>) : ((), ())) -> bb1;
// _1 = const use_zst(const {transmute(()): ((), ())}) -> bb1;
// }
// bb1: {
// StorageDead(_1);

View file

@ -10,7 +10,7 @@ error[E0282]: type annotations needed
--> $DIR/cannot-infer-const-args.rs:9:5
|
LL | foo();
| ^^^ cannot infer type for fn item `fn() -> usize {foo::<_: usize>}`
| ^^^ cannot infer type for fn item `fn() -> usize {foo::<{_: usize}>}`
error: aborting due to previous error

View file

@ -7,5 +7,5 @@
struct S<const N: usize>;
fn main() {
assert_eq!(std::any::type_name::<S<3>>(), "const_generic_type_name::S<3usize>");
assert_eq!(std::any::type_name::<S<3>>(), "const_generic_type_name::S<3>");
}

View file

@ -10,12 +10,12 @@ error[E0308]: mismatched types
--> $DIR/fn-const-param-infer.rs:16:31
|
LL | let _: Checked<not_one> = Checked::<not_two>;
| ---------------- ^^^^^^^^^^^^^^^^^^ expected `not_one`, found `not_two`
| ---------------- ^^^^^^^^^^^^^^^^^^ expected `{not_one as fn(usize) -> bool}`, found `{not_two as fn(usize) -> bool}`
| |
| expected due to this
|
= note: expected struct `Checked<not_one>`
found struct `Checked<not_two>`
= note: expected struct `Checked<{not_one as fn(usize) -> bool}>`
found struct `Checked<{not_two as fn(usize) -> bool}>`
error[E0308]: mismatched types
--> $DIR/fn-const-param-infer.rs:20:24
@ -36,12 +36,12 @@ error[E0308]: mismatched types
--> $DIR/fn-const-param-infer.rs:25:40
|
LL | let _: Checked<{generic::<u32>}> = Checked::<{generic::<u16>}>;
| ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `generic::<u32>`, found `generic::<u16>`
| ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{generic::<u32> as fn(usize) -> bool}`, found `{generic::<u16> as fn(usize) -> bool}`
| |
| expected due to this
|
= note: expected struct `Checked<generic::<u32>>`
found struct `Checked<generic::<u16>>`
= note: expected struct `Checked<{generic::<u32> as fn(usize) -> bool}>`
found struct `Checked<{generic::<u16> as fn(usize) -> bool}>`
error: aborting due to 4 previous errors

View file

@ -4,6 +4,6 @@
struct Const<const P: *const u32>;
fn main() {
let _: Const<{15 as *const _}> = Const::<{10 as *const _}>; //~ mismatched types
let _: Const<{10 as *const _}> = Const::<{10 as *const _}>;
let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>; //~ mismatched types
let _: Const<{ 10 as *const _ }> = Const::<{ 10 as *const _ }>;
}

View file

@ -7,15 +7,15 @@ LL | #![feature(const_generics, const_compare_raw_pointers)]
= note: `#[warn(incomplete_features)]` on by default
error[E0308]: mismatched types
--> $DIR/raw-ptr-const-param.rs:7:38
--> $DIR/raw-ptr-const-param.rs:7:40
|
LL | let _: Const<{15 as *const _}> = Const::<{10 as *const _}>;
| ----------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{pointer}`, found `{pointer}`
LL | let _: Const<{ 15 as *const _ }> = Const::<{ 10 as *const _ }>;
| ------------------------- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `{0xf as *const u32}`, found `{0xa as *const u32}`
| |
| expected due to this
|
= note: expected struct `Const<{pointer}>`
found struct `Const<{pointer}>`
= note: expected struct `Const<{0xf as *const u32}>`
found struct `Const<{0xa as *const u32}>`
error: aborting due to previous error

View file

@ -43,7 +43,7 @@ error: any use of this value will cause an error
LL | intrinsics::ptr_offset_from(self, origin)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| exact_div: 1 cannot be divided by 2 without remainder
| exact_div: 1isize cannot be divided by 2isize without remainder
| inside call to `std::ptr::const_ptr::<impl *const u16>::offset_from` at $DIR/offset_from_ub.rs:36:14
|
::: $DIR/offset_from_ub.rs:31:1