Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3344833

Browse files
committed
Add unstable struct fields to ui tests
1 parent 8663ee1 commit 3344833

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/test/ui/rfc-2008-non-exhaustive/auxiliary/unstable.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,34 @@ impl OnlyUnstableEnum {
2727
Self::Unstable
2828
}
2929
}
30+
31+
#[derive(Default)]
32+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
33+
#[non_exhaustive]
34+
pub struct UnstableStruct {
35+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
36+
pub stable: bool,
37+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
38+
pub stable2: usize,
39+
#[unstable(feature = "unstable_test_feature", issue = "none")]
40+
pub unstable: u8,
41+
}
42+
43+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
44+
#[non_exhaustive]
45+
pub struct OnlyUnstableStruct {
46+
#[unstable(feature = "unstable_test_feature", issue = "none")]
47+
pub unstable: u8,
48+
#[unstable(feature = "unstable_test_feature", issue = "none")]
49+
pub unstable2: bool,
50+
}
51+
52+
impl OnlyUnstableStruct {
53+
#[stable(feature = "stable_test_feature", since = "1.0.0")]
54+
pub fn new() -> Self {
55+
Self {
56+
unstable: 0,
57+
unstable2: false,
58+
}
59+
}
60+
}

src/test/ui/rfc-2008-non-exhaustive/omitted-patterns.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use enums::{
1313
EmptyNonExhaustiveEnum, NestedNonExhaustive, NonExhaustiveEnum, NonExhaustiveSingleVariant,
1414
VariantNonExhaustive,
1515
};
16-
use unstable::{UnstableEnum, OnlyUnstableEnum};
16+
use unstable::{UnstableEnum, OnlyUnstableEnum, UnstableStruct, OnlyUnstableStruct};
1717
use structs::{FunctionalRecord, MixedVisFields, NestedStruct, NormalStruct};
1818

1919
#[non_exhaustive]
@@ -145,6 +145,7 @@ fn main() {
145145
}
146146
//~^^ some variants are not matched explicitly
147147

148+
// Ok: the feature is on and all variants are matched
148149
#[deny(non_exhaustive_omitted_patterns)]
149150
match UnstableEnum::Stable {
150151
UnstableEnum::Stable => {}
@@ -167,4 +168,20 @@ fn main() {
167168
_ => {}
168169
}
169170
//~^^ some variants are not matched explicitly
171+
172+
#[warn(non_exhaustive_omitted_patterns)]
173+
let OnlyUnstableStruct { unstable, .. } = OnlyUnstableStruct::new();
174+
//~^ some fields are not explicitly listed
175+
176+
// OK: both unstable fields are matched with feature on
177+
#[warn(non_exhaustive_omitted_patterns)]
178+
let OnlyUnstableStruct { unstable, unstable2, .. } = OnlyUnstableStruct::new();
179+
180+
#[warn(non_exhaustive_omitted_patterns)]
181+
let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
182+
//~^ some fields are not explicitly listed
183+
184+
// OK: both unstable and stable fields are matched with feature on
185+
#[warn(non_exhaustive_omitted_patterns)]
186+
let UnstableStruct { stable, stable2, unstable, .. } = UnstableStruct::default();
170187
}

src/test/ui/rfc-2008-non-exhaustive/stable-omitted-patterns.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
// aux-build:unstable.rs
77
extern crate unstable;
88

9-
use unstable::{UnstableEnum, OnlyUnstableEnum};
9+
use unstable::{UnstableEnum, OnlyUnstableEnum, UnstableStruct, OnlyUnstableStruct};
1010

1111
fn main() {
1212
// OK: this matches all the stable variants
@@ -30,4 +30,16 @@ fn main() {
3030
match OnlyUnstableEnum::new() {
3131
_ => {}
3232
}
33+
34+
// Ok: Same as the above enum (no fields can be matched on)
35+
#[warn(non_exhaustive_omitted_patterns)]
36+
let OnlyUnstableStruct { .. } = OnlyUnstableStruct::new();
37+
38+
#[warn(non_exhaustive_omitted_patterns)]
39+
let UnstableStruct { stable, .. } = UnstableStruct::default();
40+
//~^ some fields are not explicitly listed
41+
42+
// OK: stable field is matched
43+
#[warn(non_exhaustive_omitted_patterns)]
44+
let UnstableStruct { stable, stable2, .. } = UnstableStruct::default();
3345
}

0 commit comments

Comments
 (0)