Skip to content

Commit

Permalink
make error message less confusing
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Mar 11, 2020
1 parent 9681422 commit 93436d8
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 27 deletions.
4 changes: 2 additions & 2 deletions src/librustc/mir/interpret/error.rs
Expand Up @@ -485,8 +485,8 @@ impl fmt::Debug for UnsupportedOpInfo {
initializer"
),

ReadPointerAsBytes => write!(f, "unable to turn this pointer into raw bytes",),
ReadBytesAsPointer => write!(f, "unable to turn these bytes into a pointer"),
ReadPointerAsBytes => write!(f, "unable to turn pointer into raw bytes",),
ReadBytesAsPointer => write!(f, "unable to turn bytes into a pointer"),
}
}
}
Expand Down
Expand Up @@ -12,7 +12,7 @@ error: any use of this value will cause an error
LL | const I32_REF_U8_UNION: u8 = unsafe { Nonsense { int_32_ref: &3 }.uint_8 };
| --------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes
|
= note: `#[deny(const_err)]` on by default

Expand All @@ -22,15 +22,15 @@ error: any use of this value will cause an error
LL | const I32_REF_U16_UNION: u16 = unsafe { Nonsense { int_32_ref: &3 }.uint_16 };
| ----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:34:45
|
LL | const I32_REF_U32_UNION: u32 = unsafe { Nonsense { int_32_ref: &3 }.uint_32 };
| ----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error[E0080]: it is undefined behavior to use this value
--> $DIR/const-pointer-values-in-various-types.rs:37:5
Expand All @@ -54,23 +54,23 @@ error: any use of this value will cause an error
LL | const I32_REF_I8_UNION: i8 = unsafe { Nonsense { int_32_ref: &3 }.int_8 };
| --------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:46:45
|
LL | const I32_REF_I16_UNION: i16 = unsafe { Nonsense { int_32_ref: &3 }.int_16 };
| ----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:49:45
|
LL | const I32_REF_I32_UNION: i32 = unsafe { Nonsense { int_32_ref: &3 }.int_32 };
| ----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error[E0080]: it is undefined behavior to use this value
--> $DIR/const-pointer-values-in-various-types.rs:52:5
Expand All @@ -94,7 +94,7 @@ error: any use of this value will cause an error
LL | const I32_REF_F32_UNION: f32 = unsafe { Nonsense { int_32_ref: &3 }.float_32 };
| ----------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error[E0080]: it is undefined behavior to use this value
--> $DIR/const-pointer-values-in-various-types.rs:61:5
Expand All @@ -110,39 +110,39 @@ error: any use of this value will cause an error
LL | const I32_REF_BOOL_UNION: bool = unsafe { Nonsense { int_32_ref: &3 }.truthy_falsey };
| ------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:67:47
|
LL | const I32_REF_CHAR_UNION: char = unsafe { Nonsense { int_32_ref: &3 }.character };
| ------------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:70:39
|
LL | const STR_U8_UNION: u8 = unsafe { Nonsense { stringy: "3" }.uint_8 };
| ----------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:73:41
|
LL | const STR_U16_UNION: u16 = unsafe { Nonsense { stringy: "3" }.uint_16 };
| ------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:76:41
|
LL | const STR_U32_UNION: u32 = unsafe { Nonsense { stringy: "3" }.uint_32 };
| ------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error[E0080]: it is undefined behavior to use this value
--> $DIR/const-pointer-values-in-various-types.rs:79:5
Expand All @@ -158,31 +158,31 @@ error: any use of this value will cause an error
LL | const STR_U128_UNION: u128 = unsafe { Nonsense { stringy: "3" }.uint_128 };
| --------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:85:39
|
LL | const STR_I8_UNION: i8 = unsafe { Nonsense { stringy: "3" }.int_8 };
| ----------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:88:41
|
LL | const STR_I16_UNION: i16 = unsafe { Nonsense { stringy: "3" }.int_16 };
| ------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:91:41
|
LL | const STR_I32_UNION: i32 = unsafe { Nonsense { stringy: "3" }.int_32 };
| ------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error[E0080]: it is undefined behavior to use this value
--> $DIR/const-pointer-values-in-various-types.rs:94:5
Expand All @@ -198,15 +198,15 @@ error: any use of this value will cause an error
LL | const STR_I128_UNION: i128 = unsafe { Nonsense { stringy: "3" }.int_128 };
| --------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:100:41
|
LL | const STR_F32_UNION: f32 = unsafe { Nonsense { stringy: "3" }.float_32 };
| ------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error[E0080]: it is undefined behavior to use this value
--> $DIR/const-pointer-values-in-various-types.rs:103:5
Expand All @@ -222,15 +222,15 @@ error: any use of this value will cause an error
LL | const STR_BOOL_UNION: bool = unsafe { Nonsense { stringy: "3" }.truthy_falsey };
| --------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: any use of this value will cause an error
--> $DIR/const-pointer-values-in-various-types.rs:109:43
|
LL | const STR_CHAR_UNION: char = unsafe { Nonsense { stringy: "3" }.character };
| --------------------------------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn this pointer into raw bytes
| unable to turn pointer into raw bytes

error: aborting due to 29 previous errors

Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/consts/const-eval/const_raw_ptr_ops.stderr
Expand Up @@ -30,15 +30,15 @@ error: any use of this value will cause an error
LL | const Z2: i32 = unsafe { *(42 as *const i32) };
| -------------------------^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn these bytes into a pointer
| unable to turn bytes into a pointer

error: any use of this value will cause an error
--> $DIR/const_raw_ptr_ops.rs:17:26
|
LL | const Z3: i32 = unsafe { *(44 as *const i32) };
| -------------------------^^^^^^^^^^^^^^^^^^^---
| |
| unable to turn these bytes into a pointer
| unable to turn bytes into a pointer

error: aborting due to 5 previous errors

4 changes: 2 additions & 2 deletions src/test/ui/consts/offset_from_ub.stderr
Expand Up @@ -26,7 +26,7 @@ error: any use of this value will cause an error
LL | intrinsics::ptr_offset_from(self, origin)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| unable to turn these bytes into a pointer
| unable to turn bytes into a pointer
| inside call to `std::ptr::const_ptr::<impl *const u8>::offset_from` at $DIR/offset_from_ub.rs:28:14
|
::: $DIR/offset_from_ub.rs:26:1
Expand Down Expand Up @@ -81,7 +81,7 @@ error: any use of this value will cause an error
LL | intrinsics::ptr_offset_from(self, origin)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
| |
| unable to turn these bytes into a pointer
| unable to turn bytes into a pointer
| inside call to `std::ptr::const_ptr::<impl *const u8>::offset_from` at $DIR/offset_from_ub.rs:49:14
|
::: $DIR/offset_from_ub.rs:45:1
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/error-codes/E0396-fixed.stderr
Expand Up @@ -4,7 +4,7 @@ error: any use of this value will cause an error
LL | const VALUE: u8 = unsafe { *REG_ADDR };
| ---------------------------^^^^^^^^^---
| |
| unable to turn these bytes into a pointer
| unable to turn bytes into a pointer
|
= note: `#[deny(const_err)]` on by default

Expand Down

0 comments on commit 93436d8

Please sign in to comment.