From 7f661ec417616ea7036f0cc4aefc7034592a3647 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 11 Mar 2016 13:36:55 -0500 Subject: [PATCH] new tests for RFC #1445 --- src/test/compile-fail/issue-6804.rs | 4 -- src/test/compile-fail/rfc1445/feature-gate.rs | 36 +++++++++++++++++ .../rfc1445/match-forbidden-without-eq.rs | 39 +++++++++++++++++++ .../rfc1445/eq-allows-match-on-ty-in-macro.rs | 32 +++++++++++++++ src/test/run-pass/rfc1445/eq-allows-match.rs | 26 +++++++++++++ 5 files changed, 133 insertions(+), 4 deletions(-) create mode 100644 src/test/compile-fail/rfc1445/feature-gate.rs create mode 100644 src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs create mode 100644 src/test/run-pass/rfc1445/eq-allows-match-on-ty-in-macro.rs create mode 100644 src/test/run-pass/rfc1445/eq-allows-match.rs diff --git a/src/test/compile-fail/issue-6804.rs b/src/test/compile-fail/issue-6804.rs index 1cb5dbccf210..f6b7e13c4f5e 100644 --- a/src/test/compile-fail/issue-6804.rs +++ b/src/test/compile-fail/issue-6804.rs @@ -26,8 +26,6 @@ fn main() { //~ ERROR compilation successful //~^^^ WARNING unmatchable NaN in pattern, use the is_nan method in a guard instead //~| WARNING floating point constants cannot be used //~| WARNING this was previously accepted - //~| WARNING floating point constants cannot be used - //~| WARNING this was previously accepted match [x, 1.0] { [NAN, _] => {}, _ => {}, @@ -35,6 +33,4 @@ fn main() { //~ ERROR compilation successful //~^^^ WARNING unmatchable NaN in pattern, use the is_nan method in a guard instead //~| WARNING floating point constants cannot be used //~| WARNING this was previously accepted - //~| WARNING floating point constants cannot be used - //~| WARNING this was previously accepted } diff --git a/src/test/compile-fail/rfc1445/feature-gate.rs b/src/test/compile-fail/rfc1445/feature-gate.rs new file mode 100644 index 000000000000..1f2d7819e26d --- /dev/null +++ b/src/test/compile-fail/rfc1445/feature-gate.rs @@ -0,0 +1,36 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that structural match is only permitted with a feature gate, +// and that if a feature gate is supplied, it permits the type to be +// used in a match. + +// revisions: with_gate no_gate + +#![allow(dead_code)] +#![deny(future_incompatible)] +#![feature(rustc_attrs)] +#![cfg_attr(with_gate, feature(structural_match))] + +#[structural_match] //[no_gate]~ ERROR semantics of constant patterns is not yet settled +struct Foo { + x: u32 +} + +const FOO: Foo = Foo { x: 0 }; + +#[rustc_error] +fn main() { //[with_gate]~ ERROR compilation successful + let y = Foo { x: 1 }; + match y { + FOO => { } + _ => { } + } +} diff --git a/src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs b/src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs new file mode 100644 index 000000000000..b3e465688fdd --- /dev/null +++ b/src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs @@ -0,0 +1,39 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(dead_code)] +#![deny(future_incompatible)] + +use std::f32; + +#[derive(PartialEq)] +struct Foo { + x: u32 +} + +const FOO: Foo = Foo { x: 0 }; + +fn main() { + let y = Foo { x: 1 }; + match y { + FOO => { } + //~^ ERROR must be annotated with `#[derive(Eq)]` + //~| WARNING will become a hard error + _ => { } + } + + let x = 0.0; + match x { + f32::INFINITY => { } + //~^ ERROR floating point constants cannot be used in patterns + //~| WARNING will become a hard error + _ => { } + } +} diff --git a/src/test/run-pass/rfc1445/eq-allows-match-on-ty-in-macro.rs b/src/test/run-pass/rfc1445/eq-allows-match-on-ty-in-macro.rs new file mode 100644 index 000000000000..241fe6c6ab1e --- /dev/null +++ b/src/test/run-pass/rfc1445/eq-allows-match-on-ty-in-macro.rs @@ -0,0 +1,32 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(dead_code)] + +macro_rules! foo { + (#[$attr:meta] $x:ident) => { + #[$attr] + struct $x { + x: u32 + } + } +} + +foo! { #[derive(PartialEq, Eq)] Foo } + +const FOO: Foo = Foo { x: 0 }; + +fn main() { + let y = Foo { x: 1 }; + match y { + FOO => { } + _ => { } + } +} diff --git a/src/test/run-pass/rfc1445/eq-allows-match.rs b/src/test/run-pass/rfc1445/eq-allows-match.rs new file mode 100644 index 000000000000..f02a45625c9f --- /dev/null +++ b/src/test/run-pass/rfc1445/eq-allows-match.rs @@ -0,0 +1,26 @@ +// Copyright 2012 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +#![allow(dead_code)] + +#[derive(PartialEq, Eq)] +struct Foo { + x: u32 +} + +const FOO: Foo = Foo { x: 0 }; + +fn main() { + let y = Foo { x: 1 }; + match y { + FOO => { } + _ => { } + } +}