Add struct to stability ui tests in usefulness
This commit is contained in:
parent
4bf281a20c
commit
f481dba3d4
5 changed files with 60 additions and 15 deletions
|
@ -2,7 +2,7 @@
|
|||
#![stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||
|
||||
#[stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||
pub enum Foo {
|
||||
pub enum UnstableEnum {
|
||||
#[stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||
Stable,
|
||||
#[stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||
|
@ -10,3 +10,14 @@ pub enum Foo {
|
|||
#[unstable(feature = "unstable_test_feature", issue = "none")]
|
||||
Unstable,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||
pub struct UnstableStruct {
|
||||
#[stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||
pub stable: bool,
|
||||
#[stable(feature = "stable_test_feature", since = "1.0.0")]
|
||||
pub stable2: usize,
|
||||
#[unstable(feature = "unstable_test_feature", issue = "none")]
|
||||
pub unstable: u8,
|
||||
}
|
||||
|
|
16
src/test/ui/pattern/usefulness/stable-gated-fields.rs
Normal file
16
src/test/ui/pattern/usefulness/stable-gated-fields.rs
Normal file
|
@ -0,0 +1,16 @@
|
|||
// aux-build:unstable.rs
|
||||
|
||||
extern crate unstable;
|
||||
|
||||
use unstable::UnstableStruct;
|
||||
|
||||
fn main() {
|
||||
let UnstableStruct { stable } = UnstableStruct::default();
|
||||
//~^ pattern does not mention field `stable2` and inaccessible fields
|
||||
|
||||
let UnstableStruct { stable, stable2 } = UnstableStruct::default();
|
||||
//~^ pattern requires `..` due to inaccessible fields
|
||||
|
||||
// OK: stable field is matched
|
||||
let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
|
||||
}
|
|
@ -2,17 +2,17 @@
|
|||
|
||||
extern crate unstable;
|
||||
|
||||
use unstable::Foo;
|
||||
use unstable::UnstableEnum;
|
||||
|
||||
fn main() {
|
||||
match Foo::Stable {
|
||||
Foo::Stable => {}
|
||||
match UnstableEnum::Stable {
|
||||
UnstableEnum::Stable => {}
|
||||
}
|
||||
//~^^^ non-exhaustive patterns: `Stable2` and `_` not covered
|
||||
|
||||
match Foo::Stable {
|
||||
Foo::Stable => {}
|
||||
Foo::Stable2 => {}
|
||||
match UnstableEnum::Stable {
|
||||
UnstableEnum::Stable => {}
|
||||
UnstableEnum::Stable2 => {}
|
||||
}
|
||||
//~^^^^ non-exhaustive patterns: `_` not covered
|
||||
}
|
||||
|
|
18
src/test/ui/pattern/usefulness/unstable-gated-fields.rs
Normal file
18
src/test/ui/pattern/usefulness/unstable-gated-fields.rs
Normal file
|
@ -0,0 +1,18 @@
|
|||
#![feature(unstable_test_feature)]
|
||||
|
||||
// aux-build:unstable.rs
|
||||
|
||||
extern crate unstable;
|
||||
|
||||
use unstable::UnstableStruct;
|
||||
|
||||
fn main() {
|
||||
let UnstableStruct { stable, stable2, } = UnstableStruct::default();
|
||||
//~^ pattern does not mention field `unstable`
|
||||
|
||||
let UnstableStruct { stable, unstable, } = UnstableStruct::default();
|
||||
//~^ pattern does not mention field `stable2`
|
||||
|
||||
// OK: stable field is matched
|
||||
let UnstableStruct { stable, stable2, unstable } = UnstableStruct::default();
|
||||
}
|
|
@ -4,19 +4,19 @@
|
|||
|
||||
extern crate unstable;
|
||||
|
||||
use unstable::Foo;
|
||||
use unstable::UnstableEnum;
|
||||
|
||||
fn main() {
|
||||
match Foo::Stable {
|
||||
Foo::Stable => {}
|
||||
Foo::Stable2 => {}
|
||||
match UnstableEnum::Stable {
|
||||
UnstableEnum::Stable => {}
|
||||
UnstableEnum::Stable2 => {}
|
||||
}
|
||||
//~^^^^ non-exhaustive patterns: `Unstable` not covered
|
||||
|
||||
// Ok: all variants are explicitly matched
|
||||
match Foo::Stable {
|
||||
Foo::Stable => {}
|
||||
Foo::Stable2 => {}
|
||||
Foo::Unstable => {}
|
||||
match UnstableEnum::Stable {
|
||||
UnstableEnum::Stable => {}
|
||||
UnstableEnum::Stable2 => {}
|
||||
UnstableEnum::Unstable => {}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue