-
Notifications
You must be signed in to change notification settings - Fork 12.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #90358 - DevinR528:omitted-field-fix, r=jackh726
Fix exposing fields marked unstable or doc hidden Closes #89837 Work towards #89554 Filter fields that are marked `doc(hidden)` or are unstable with that feature turned off. This brings structs and enums into alignment behavior-wise when emitting warning/errors about pattern exhaustiveness/reachability. cc `@Nadrieril`
- Loading branch information
Showing
21 changed files
with
422 additions
and
79 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
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 |
---|---|---|
@@ -1,6 +1,14 @@ | ||
pub enum Foo { | ||
pub enum HiddenEnum { | ||
A, | ||
B, | ||
#[doc(hidden)] | ||
C, | ||
} | ||
|
||
#[derive(Default)] | ||
pub struct HiddenStruct { | ||
pub one: u8, | ||
pub two: bool, | ||
#[doc(hidden)] | ||
pub hide: usize, | ||
} |
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,26 @@ | ||
// aux-build:hidden.rs | ||
|
||
extern crate hidden; | ||
|
||
use hidden::HiddenStruct; | ||
|
||
struct InCrate { | ||
a: usize, | ||
b: bool, | ||
#[doc(hidden)] | ||
im_hidden: u8 | ||
} | ||
|
||
fn main() { | ||
let HiddenStruct { one, two } = HiddenStruct::default(); | ||
//~^ pattern requires `..` due to inaccessible fields | ||
|
||
let HiddenStruct { one } = HiddenStruct::default(); | ||
//~^ pattern does not mention field `two` and inaccessible fields | ||
|
||
let HiddenStruct { one, hide } = HiddenStruct::default(); | ||
//~^ pattern does not mention field `two` | ||
|
||
let InCrate { a, b } = InCrate { a: 0, b: false, im_hidden: 0 }; | ||
//~^ pattern does not mention field `im_hidden` | ||
} |
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,59 @@ | ||
error: pattern requires `..` due to inaccessible fields | ||
--> $DIR/doc-hidden-fields.rs:15:9 | ||
| | ||
LL | let HiddenStruct { one, two } = HiddenStruct::default(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
help: ignore the inaccessible and unused fields | ||
| | ||
LL | let HiddenStruct { one, two, .. } = HiddenStruct::default(); | ||
| ++++ | ||
|
||
error[E0027]: pattern does not mention field `two` and inaccessible fields | ||
--> $DIR/doc-hidden-fields.rs:18:9 | ||
| | ||
LL | let HiddenStruct { one } = HiddenStruct::default(); | ||
| ^^^^^^^^^^^^^^^^^^^^ missing field `two` and inaccessible fields | ||
| | ||
help: include the missing field in the pattern and ignore the inaccessible fields | ||
| | ||
LL | let HiddenStruct { one, two, .. } = HiddenStruct::default(); | ||
| ~~~~~~~~~~~ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | let HiddenStruct { one, .. } = HiddenStruct::default(); | ||
| ~~~~~~ | ||
|
||
error[E0027]: pattern does not mention field `two` | ||
--> $DIR/doc-hidden-fields.rs:21:9 | ||
| | ||
LL | let HiddenStruct { one, hide } = HiddenStruct::default(); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `two` | ||
| | ||
help: include the missing field in the pattern | ||
| | ||
LL | let HiddenStruct { one, hide, two } = HiddenStruct::default(); | ||
| ~~~~~~~ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | let HiddenStruct { one, hide, .. } = HiddenStruct::default(); | ||
| ~~~~~~ | ||
|
||
error[E0027]: pattern does not mention field `im_hidden` | ||
--> $DIR/doc-hidden-fields.rs:24:9 | ||
| | ||
LL | let InCrate { a, b } = InCrate { a: 0, b: false, im_hidden: 0 }; | ||
| ^^^^^^^^^^^^^^^^ missing field `im_hidden` | ||
| | ||
help: include the missing field in the pattern | ||
| | ||
LL | let InCrate { a, b, im_hidden } = InCrate { a: 0, b: false, im_hidden: 0 }; | ||
| ~~~~~~~~~~~~~ | ||
help: if you don't care about this missing field, you can explicitly ignore it | ||
| | ||
LL | let InCrate { a, b, .. } = InCrate { a: 0, b: false, im_hidden: 0 }; | ||
| ~~~~~~ | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0027`. |
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
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,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(); | ||
} |
Oops, something went wrong.