mirror of
https://github.com/rust-lang/rust.git
synced 2025-02-08 21:13:55 +00:00
test diagnostics for more ranges
This commit is contained in:
parent
b42b9b34d5
commit
3ec89746ba
@ -8,7 +8,7 @@
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
#![feature(const_transmute)]
|
||||
#![feature(rustc_attrs, const_transmute)]
|
||||
#![allow(const_err)] // make sure we cannot allow away the errors tested here
|
||||
|
||||
use std::mem;
|
||||
@ -23,4 +23,18 @@ const NULL_U8: NonZeroU8 = unsafe { mem::transmute(0u8) };
|
||||
const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
|
||||
// Also test other uses of rustc_layout_scalar_valid_range_start
|
||||
|
||||
#[rustc_layout_scalar_valid_range_start(10)]
|
||||
#[rustc_layout_scalar_valid_range_end(30)]
|
||||
struct RestrictedRange1(u32);
|
||||
const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
|
||||
#[rustc_layout_scalar_valid_range_start(30)]
|
||||
#[rustc_layout_scalar_valid_range_end(10)]
|
||||
struct RestrictedRange2(u32);
|
||||
const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
|
||||
//~^ ERROR it is undefined behavior to use this value
|
||||
|
||||
fn main() {}
|
||||
|
@ -22,6 +22,22 @@ LL | const NULL_USIZE: NonZeroUsize = unsafe { mem::transmute(0usize) };
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-nonnull.rs:31:1
|
||||
|
|
||||
LL | const BAD_RANGE1: RestrictedRange1 = unsafe { RestrictedRange1(42) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 42, but expected something in the range 10..=30
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||
|
||||
error[E0080]: it is undefined behavior to use this value
|
||||
--> $DIR/ub-nonnull.rs:37:1
|
||||
|
|
||||
LL | const BAD_RANGE2: RestrictedRange2 = unsafe { RestrictedRange2(20) };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type validation failed: encountered 20, but expected something less or equal to 10, or greater or equal to 30
|
||||
|
|
||||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rust compiler repository if you believe it should not be considered undefined behavior
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0080`.
|
||||
|
Loading…
Reference in New Issue
Block a user