Skip to content

Commit f481dba

Browse files
committed
Add struct to stability ui tests in usefulness
1 parent 4bf281a commit f481dba

File tree

5 files changed

+60
-15
lines changed

5 files changed

+60
-15
lines changed

src/test/ui/pattern/usefulness/auxiliary/unstable.rs

+12-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,22 @@
22
#![stable(feature = "stable_test_feature", since = "1.0.0")]
33

44
#[stable(feature = "stable_test_feature", since = "1.0.0")]
5-
pub enum Foo {
5+
pub enum UnstableEnum {
66
#[stable(feature = "stable_test_feature", since = "1.0.0")]
77
Stable,
88
#[stable(feature = "stable_test_feature", since = "1.0.0")]
99
Stable2,
1010
#[unstable(feature = "unstable_test_feature", issue = "none")]
1111
Unstable,
1212
}
13+
14+
#[derive(Default)]
15+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
16+
pub struct UnstableStruct {
17+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
18+
pub stable: bool,
19+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
20+
pub stable2: usize,
21+
#[unstable(feature = "unstable_test_feature", issue = "none")]
22+
pub unstable: u8,
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// aux-build:unstable.rs
2+
3+
extern crate unstable;
4+
5+
use unstable::UnstableStruct;
6+
7+
fn main() {
8+
let UnstableStruct { stable } = UnstableStruct::default();
9+
//~^ pattern does not mention field `stable2` and inaccessible fields
10+
11+
let UnstableStruct { stable, stable2 } = UnstableStruct::default();
12+
//~^ pattern requires `..` due to inaccessible fields
13+
14+
// OK: stable field is matched
15+
let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
16+
}

src/test/ui/pattern/usefulness/stable-gated-patterns.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,17 @@
22

33
extern crate unstable;
44

5-
use unstable::Foo;
5+
use unstable::UnstableEnum;
66

77
fn main() {
8-
match Foo::Stable {
9-
Foo::Stable => {}
8+
match UnstableEnum::Stable {
9+
UnstableEnum::Stable => {}
1010
}
1111
//~^^^ non-exhaustive patterns: `Stable2` and `_` not covered
1212

13-
match Foo::Stable {
14-
Foo::Stable => {}
15-
Foo::Stable2 => {}
13+
match UnstableEnum::Stable {
14+
UnstableEnum::Stable => {}
15+
UnstableEnum::Stable2 => {}
1616
}
1717
//~^^^^ non-exhaustive patterns: `_` not covered
1818
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#![feature(unstable_test_feature)]
2+
3+
// aux-build:unstable.rs
4+
5+
extern crate unstable;
6+
7+
use unstable::UnstableStruct;
8+
9+
fn main() {
10+
let UnstableStruct { stable, stable2, } = UnstableStruct::default();
11+
//~^ pattern does not mention field `unstable`
12+
13+
let UnstableStruct { stable, unstable, } = UnstableStruct::default();
14+
//~^ pattern does not mention field `stable2`
15+
16+
// OK: stable field is matched
17+
let UnstableStruct { stable, stable2, unstable } = UnstableStruct::default();
18+
}

src/test/ui/pattern/usefulness/unstable-gated-patterns.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,19 @@
44

55
extern crate unstable;
66

7-
use unstable::Foo;
7+
use unstable::UnstableEnum;
88

99
fn main() {
10-
match Foo::Stable {
11-
Foo::Stable => {}
12-
Foo::Stable2 => {}
10+
match UnstableEnum::Stable {
11+
UnstableEnum::Stable => {}
12+
UnstableEnum::Stable2 => {}
1313
}
1414
//~^^^^ non-exhaustive patterns: `Unstable` not covered
1515

1616
// Ok: all variants are explicitly matched
17-
match Foo::Stable {
18-
Foo::Stable => {}
19-
Foo::Stable2 => {}
20-
Foo::Unstable => {}
17+
match UnstableEnum::Stable {
18+
UnstableEnum::Stable => {}
19+
UnstableEnum::Stable2 => {}
20+
UnstableEnum::Unstable => {}
2121
}
2222
}

0 commit comments

Comments
 (0)