diff options
| author | Trevor Gross <tmgross@umich.edu> | 2024-03-26 06:01:09 -0400 |
|---|---|---|
| committer | Trevor Gross <tmgross@umich.edu> | 2024-06-23 04:28:42 -0500 |
| commit | 6fb6c19c961369b98e2dd9466c1a83ac2d783ae2 (patch) | |
| tree | 685a1447dd914e65f19e28da055902571d3467f1 /tests | |
| parent | acb62737aca7045f331e7a05adc38bed213e278d (diff) | |
Replace `f16` and `f128` pattern matching stubs with real implementations
This section of code depends on `rustc_apfloat` rather than our internal types, so this is one potential ICE that we should be able to melt now. This also fixes some missing range and match handling in `rustc_middle`.
Diffstat (limited to 'tests')
6 files changed, 223 insertions, 27 deletions
diff --git a/tests/ui/half-open-range-patterns/half-open-range-pats-semantics.rs b/tests/ui/half-open-range-patterns/half-open-range-pats-semantics.rs index 3487bac5282..38ade060cb1 100644 --- a/tests/ui/half-open-range-patterns/half-open-range-pats-semantics.rs +++ b/tests/ui/half-open-range-patterns/half-open-range-pats-semantics.rs @@ -4,6 +4,8 @@ // via `.contains(...)` and make sure the dynamic semantics match. #![allow(unreachable_patterns)] +#![feature(f128)] +#![feature(f16)] macro_rules! yes { ($scrutinee:expr, $($t:tt)+) => { @@ -39,6 +41,17 @@ fn range_to_inclusive() { assert!(yes!('a', ..='a')); assert!(!yes!('b', ..='a')); + // f16; `..=X` + // FIXME(f16_f128): remove gate when ABI issues are resolved + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + // FIXME(f16_f128): enable infinity tests when constants are available + // assert!(yes!(f16::NEG_INFINITY, ..=f16::NEG_INFINITY)); + // assert!(yes!(f16::NEG_INFINITY, ..=1.0f16)); + assert!(yes!(1.5f16, ..=1.5f16)); + assert!(!yes!(1.6f16, ..=-1.5f16)); + } + // f32; `..=X` assert!(yes!(f32::NEG_INFINITY, ..=f32::NEG_INFINITY)); assert!(yes!(f32::NEG_INFINITY, ..=1.0f32)); @@ -50,6 +63,17 @@ fn range_to_inclusive() { assert!(yes!(f64::NEG_INFINITY, ..=1.0f64)); assert!(yes!(1.5f64, ..=1.5f64)); assert!(!yes!(1.6f64, ..=-1.5f64)); + + // f128; `..=X` + // FIXME(f16_f128): remove gate when ABI issues are resolved + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + // FIXME(f16_f128): enable infinity tests when constants are available + // assert!(yes!(f128::NEG_INFINITY, ..=f128::NEG_INFINITY)); + // assert!(yes!(f128::NEG_INFINITY, ..=1.0f128)); + assert!(yes!(1.5f128, ..=1.5f128)); + assert!(!yes!(1.6f128, ..=-1.5f128)); + } } fn range_to() { @@ -83,6 +107,18 @@ fn range_to() { assert!(!yes!('a', ..'a')); assert!(!yes!('b', ..'a')); + // f16; `..X` + // FIXME(f16_f128): remove gate when ABI issues are resolved + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + // FIXME(f16_f128): enable infinity tests when constants are available + // assert!(yes!(f16::NEG_INFINITY, ..1.0f16)); + assert!(!yes!(1.5f16, ..1.5f16)); + const E16: f16 = 1.5f16 + f16::EPSILON; + assert!(yes!(1.5f16, ..E16)); + assert!(!yes!(1.6f16, ..1.5f16)); + } + // f32; `..X` assert!(yes!(f32::NEG_INFINITY, ..1.0f32)); assert!(!yes!(1.5f32, ..1.5f32)); @@ -96,6 +132,18 @@ fn range_to() { const E64: f64 = 1.5f64 + f64::EPSILON; assert!(yes!(1.5f64, ..E64)); assert!(!yes!(1.6f64, ..1.5f64)); + + // f128; `..X` + // FIXME(f16_f128): remove gate when ABI issues are resolved + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + // FIXME(f16_f128): enable infinity tests when constants are available + // assert!(yes!(f128::NEG_INFINITY, ..1.0f128)); + assert!(!yes!(1.5f128, ..1.5f128)); + const E128: f128 = 1.5f128 + f128::EPSILON; + assert!(yes!(1.5f128, ..E128)); + assert!(!yes!(1.6f128, ..1.5f128)); + } } fn range_from() { @@ -129,6 +177,21 @@ fn range_from() { assert!(!yes!('a', 'b'..)); assert!(yes!(core::char::MAX, core::char::MAX..)); + // f16; `X..` + // FIXME(f16_f128): remove gate when ABI issues are resolved + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + // FIXME(f16_f128): enable infinity tests when constants are available + // assert!(yes!(f16::NEG_INFINITY, f16::NEG_INFINITY..)); + // assert!(yes!(f16::INFINITY, f16::NEG_INFINITY..)); + // assert!(!yes!(f16::NEG_INFINITY, 1.0f16..)); + // assert!(yes!(f16::INFINITY, 1.0f16..)); + assert!(!yes!(1.0f16 - f16::EPSILON, 1.0f16..)); + assert!(yes!(1.0f16, 1.0f16..)); + // assert!(yes!(f16::INFINITY, 1.0f16..)); + // assert!(yes!(f16::INFINITY, f16::INFINITY..)); + } + // f32; `X..` assert!(yes!(f32::NEG_INFINITY, f32::NEG_INFINITY..)); assert!(yes!(f32::INFINITY, f32::NEG_INFINITY..)); @@ -148,6 +211,21 @@ fn range_from() { assert!(yes!(1.0f64, 1.0f64..)); assert!(yes!(f64::INFINITY, 1.0f64..)); assert!(yes!(f64::INFINITY, f64::INFINITY..)); + + // f128; `X..` + // FIXME(f16_f128): remove gate when ABI issues are resolved + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + { + // FIXME(f16_f128): enable infinity tests when constants are available + // assert!(yes!(f128::NEG_INFINITY, f128::NEG_INFINITY..)); + // assert!(yes!(f128::INFINITY, f128::NEG_INFINITY..)); + // assert!(!yes!(f128::NEG_INFINITY, 1.0f128..)); + // assert!(yes!(f128::INFINITY, 1.0f128..)); + assert!(!yes!(1.0f128 - f128::EPSILON, 1.0f128..)); + assert!(yes!(1.0f128, 1.0f128..)); + // assert!(yes!(f128::INFINITY, 1.0f128..)); + // assert!(yes!(f128::INFINITY, f128::INFINITY..)); + } } fn main() { diff --git a/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs b/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs index 9ca8dd25ed7..a35bb51acbc 100644 --- a/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs +++ b/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.rs @@ -27,6 +27,7 @@ fn main() { m!(0, ..i128::MIN); //~^ ERROR lower range bound must be less than upper + // FIXME(f16_f128): add tests when NEG_INFINITY is available m!(0f32, ..f32::NEG_INFINITY); //~^ ERROR lower range bound must be less than upper m!(0f64, ..f64::NEG_INFINITY); diff --git a/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr b/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr index 668b5c858f0..fb2f1841a6d 100644 --- a/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr +++ b/tests/ui/half-open-range-patterns/half-open-range-pats-thir-lower-empty.stderr @@ -59,19 +59,19 @@ LL | m!(0, ..i128::MIN); | ^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-thir-lower-empty.rs:30:14 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:31:14 | LL | m!(0f32, ..f32::NEG_INFINITY); | ^^^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-thir-lower-empty.rs:32:14 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:33:14 | LL | m!(0f64, ..f64::NEG_INFINITY); | ^^^^^^^^^^^^^^^^^^^ error[E0579]: lower range bound must be less than upper - --> $DIR/half-open-range-pats-thir-lower-empty.rs:35:13 + --> $DIR/half-open-range-pats-thir-lower-empty.rs:36:13 | LL | m!('a', ..'\u{0}'); | ^^^^^^^^^ diff --git a/tests/ui/match/match-float.rs b/tests/ui/match/match-float.rs index f8514568d15..70283eaeec5 100644 --- a/tests/ui/match/match-float.rs +++ b/tests/ui/match/match-float.rs @@ -1,7 +1,22 @@ //@ run-pass // Makes sure we use `==` (not bitwise) semantics for float comparison. -fn main() { +#![feature(f128)] +#![feature(f16)] + +// FIXME(f16_f128): remove gates when ABI issues are resolved + +#[cfg(all(target_arch = "aarch64", target_os = "linux"))] +fn check_f16() { + const F1: f16 = 0.0; + const F2: f16 = -0.0; + assert_eq!(F1, F2); + assert_ne!(F1.to_bits(), F2.to_bits()); + assert!(matches!(F1, F2)); + assert!(matches!(F2, F1)); +} + +fn check_f32() { const F1: f32 = 0.0; const F2: f32 = -0.0; assert_eq!(F1, F2); @@ -9,3 +24,31 @@ fn main() { assert!(matches!(F1, F2)); assert!(matches!(F2, F1)); } + +fn check_f64() { + const F1: f64 = 0.0; + const F2: f64 = -0.0; + assert_eq!(F1, F2); + assert_ne!(F1.to_bits(), F2.to_bits()); + assert!(matches!(F1, F2)); + assert!(matches!(F2, F1)); +} + +#[cfg(all(target_arch = "aarch64", target_os = "linux"))] +fn check_f128() { + const F1: f128 = 0.0; + const F2: f128 = -0.0; + assert_eq!(F1, F2); + assert_ne!(F1.to_bits(), F2.to_bits()); + assert!(matches!(F1, F2)); + assert!(matches!(F2, F1)); +} + +fn main() { + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + check_f16(); + check_f32(); + check_f64(); + #[cfg(all(target_arch = "aarch64", target_os = "linux"))] + check_f128(); +} diff --git a/tests/ui/pattern/usefulness/floats.rs b/tests/ui/pattern/usefulness/floats.rs index b3d49ba8e15..0b27e33e4ef 100644 --- a/tests/ui/pattern/usefulness/floats.rs +++ b/tests/ui/pattern/usefulness/floats.rs @@ -1,4 +1,6 @@ #![deny(unreachable_patterns)] +#![feature(f128)] +#![feature(f16)] fn main() { match 0.0 { @@ -11,6 +13,32 @@ fn main() { 0.0..=1.0 => {} } + match 1.0f16 { + 0.01f16..=6.5f16 => {} + 0.01f16 => {} //~ ERROR unreachable pattern + 0.02f16 => {} //~ ERROR unreachable pattern + 6.5f16 => {} //~ ERROR unreachable pattern + _ => {} + }; + match 1.0f16 { + 0.01f16..6.5f16 => {} + 6.5f16 => {} // this is reachable + _ => {} + }; + + match 1.0f32 { + 0.01f32..=6.5f32 => {} + 0.01f32 => {} //~ ERROR unreachable pattern + 0.02f32 => {} //~ ERROR unreachable pattern + 6.5f32 => {} //~ ERROR unreachable pattern + _ => {} + }; + match 1.0f32 { + 0.01f32..6.5f32 => {} + 6.5f32 => {} // this is reachable + _ => {} + }; + match 1.0f64 { 0.01f64..=6.5f64 => {} 0.005f64 => {} @@ -28,16 +56,20 @@ fn main() { _ => {} }; - match 1.0f32 { - 0.01f32..=6.5f32 => {} - 0.01f32 => {} //~ ERROR unreachable pattern - 0.02f32 => {} //~ ERROR unreachable pattern - 6.5f32 => {} //~ ERROR unreachable pattern + match 1.0f128 { + 0.01f128..=6.5f128 => {} + 0.005f128 => {} + 0.01f128 => {} //~ ERROR unreachable pattern + 0.02f128 => {} //~ ERROR unreachable pattern + 6.5f128 => {} //~ ERROR unreachable pattern + 6.6f128 => {} + 1.0f128..=4.0f128 => {} //~ ERROR unreachable pattern + 5.0f128..=7.0f128 => {} _ => {} }; - match 1.0f32 { - 0.01f32..6.5f32 => {} - 6.5f32 => {} // this is reachable + match 1.0f128 { + 0.01f128..6.5f128 => {} + 6.5f128 => {} // this is reachable _ => {} }; } diff --git a/tests/ui/pattern/usefulness/floats.stderr b/tests/ui/pattern/usefulness/floats.stderr index 04f2fe3cd94..684f6c93a16 100644 --- a/tests/ui/pattern/usefulness/floats.stderr +++ b/tests/ui/pattern/usefulness/floats.stderr @@ -1,5 +1,5 @@ error[E0004]: non-exhaustive patterns: `_` not covered - --> $DIR/floats.rs:9:11 + --> $DIR/floats.rs:11:11 | LL | match 0.0 { | ^^^ pattern `_` not covered @@ -12,9 +12,9 @@ LL + _ => todo!() | error: unreachable pattern - --> $DIR/floats.rs:17:9 + --> $DIR/floats.rs:18:9 | -LL | 0.01f64 => {} +LL | 0.01f16 => {} | ^^^^^^^ | note: the lint level is defined here @@ -24,41 +24,83 @@ LL | #![deny(unreachable_patterns)] | ^^^^^^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/floats.rs:18:9 + --> $DIR/floats.rs:19:9 + | +LL | 0.02f16 => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/floats.rs:20:9 + | +LL | 6.5f16 => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/floats.rs:31:9 + | +LL | 0.01f32 => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/floats.rs:32:9 + | +LL | 0.02f32 => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/floats.rs:33:9 + | +LL | 6.5f32 => {} + | ^^^^^^ + +error: unreachable pattern + --> $DIR/floats.rs:45:9 + | +LL | 0.01f64 => {} + | ^^^^^^^ + +error: unreachable pattern + --> $DIR/floats.rs:46:9 | LL | 0.02f64 => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/floats.rs:19:9 + --> $DIR/floats.rs:47:9 | LL | 6.5f64 => {} | ^^^^^^ error: unreachable pattern - --> $DIR/floats.rs:21:9 + --> $DIR/floats.rs:49:9 | LL | 1.0f64..=4.0f64 => {} | ^^^^^^^^^^^^^^^ error: unreachable pattern - --> $DIR/floats.rs:33:9 + --> $DIR/floats.rs:62:9 | -LL | 0.01f32 => {} - | ^^^^^^^ +LL | 0.01f128 => {} + | ^^^^^^^^ error: unreachable pattern - --> $DIR/floats.rs:34:9 + --> $DIR/floats.rs:63:9 | -LL | 0.02f32 => {} +LL | 0.02f128 => {} + | ^^^^^^^^ + +error: unreachable pattern + --> $DIR/floats.rs:64:9 + | +LL | 6.5f128 => {} | ^^^^^^^ error: unreachable pattern - --> $DIR/floats.rs:35:9 + --> $DIR/floats.rs:66:9 | -LL | 6.5f32 => {} - | ^^^^^^ +LL | 1.0f128..=4.0f128 => {} + | ^^^^^^^^^^^^^^^^^ -error: aborting due to 8 previous errors +error: aborting due to 15 previous errors For more information about this error, try `rustc --explain E0004`. |
