forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
56ebf2b
commit 7f661ec
Showing
5 changed files
with
133 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 => { } | ||
_ => { } | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/test/compile-fail/rfc1445/match-forbidden-without-eq.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 | ||
_ => { } | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/test/run-pass/rfc1445/eq-allows-match-on-ty-in-macro.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 => { } | ||
_ => { } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, 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 => { } | ||
_ => { } | ||
} | ||
} |