提交 7ffb29d0 编写于 作者: D Devin Ragotzy

Only filter doc(hidden) fields/variants when not crate local

上级 04210aec
......@@ -692,11 +692,11 @@ pub(super) fn is_unstable_variant(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> bool {
}
/// Checks if the `Constructor` is a `Constructor::Variant` with a `#[doc(hidden)]`
/// attribute.
/// attribute from a type not local to the current crate.
pub(super) fn is_doc_hidden_variant(&self, pcx: PatCtxt<'_, '_, 'tcx>) -> bool {
if let Constructor::Variant(idx) = self && let ty::Adt(adt, _) = pcx.ty.kind() {
let variant_def_id = adt.variant(*idx).def_id;
return pcx.cx.tcx.is_doc_hidden(variant_def_id);
let variant_def_id = adt.variants[*idx].def_id;
return pcx.cx.tcx.is_doc_hidden(variant_def_id) && !variant_def_id.is_local();
}
false
}
......
......@@ -1313,7 +1313,8 @@ fn check_struct_pat_fields(
tcx.eval_stability(field.did, None, DUMMY_SP, None),
EvalResult::Deny { .. }
)
&& !tcx.is_doc_hidden(field.did)
// We only want to report the error if it is hidden and not local
&& !(tcx.is_doc_hidden(field.did) && !field.did.is_local())
})
.collect();
......
......@@ -4,6 +4,13 @@
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
......@@ -13,4 +20,7 @@ fn main() {
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`
}
error: pattern requires `..` due to inaccessible fields
--> $DIR/doc-hidden-fields.rs:8:9
--> $DIR/doc-hidden-fields.rs:15:9
|
LL | let HiddenStruct { one, two, } = HiddenStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
......@@ -10,7 +10,7 @@ LL | let HiddenStruct { one, two, .., } = HiddenStruct::default();
| ++++
error[E0027]: pattern does not mention field `two` and inaccessible fields
--> $DIR/doc-hidden-fields.rs:11:9
--> $DIR/doc-hidden-fields.rs:18:9
|
LL | let HiddenStruct { one, } = HiddenStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^ missing field `two` and inaccessible fields
......@@ -25,7 +25,7 @@ LL | let HiddenStruct { one, .. } = HiddenStruct::default();
| ~~~~~~
error[E0027]: pattern does not mention field `two`
--> $DIR/doc-hidden-fields.rs:14:9
--> $DIR/doc-hidden-fields.rs:21:9
|
LL | let HiddenStruct { one, hide } = HiddenStruct::default();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ missing field `two`
......@@ -39,6 +39,21 @@ help: if you don't care about this missing field, you can explicitly ignore it
LL | let HiddenStruct { one, hide, .. } = HiddenStruct::default();
| ~~~~~~
error: aborting due to 3 previous errors
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`.
......@@ -4,6 +4,13 @@
use hidden::HiddenEnum;
enum InCrate {
A,
B,
#[doc(hidden)]
C,
}
fn main() {
match HiddenEnum::A {
HiddenEnum::A => {}
......@@ -27,4 +34,10 @@ fn main() {
Some(HiddenEnum::A) => {}
}
//~^^^^ non-exhaustive patterns: `Some(B)` and `Some(_)` not covered
match InCrate::A {
InCrate::A => {}
InCrate::B => {}
}
//~^^^^ non-exhaustive patterns: `C` not covered
}
error[E0004]: non-exhaustive patterns: `_` not covered
--> $DIR/doc-hidden-non-exhaustive.rs:8:11
--> $DIR/doc-hidden-non-exhaustive.rs:15:11
|
LL | match HiddenEnum::A {
| ^^^^^^^^^^^^^ pattern `_` not covered
......@@ -8,7 +8,7 @@ LL | match HiddenEnum::A {
= note: the matched value is of type `HiddenEnum`
error[E0004]: non-exhaustive patterns: `B` not covered
--> $DIR/doc-hidden-non-exhaustive.rs:14:11
--> $DIR/doc-hidden-non-exhaustive.rs:21:11
|
LL | match HiddenEnum::A {
| ^^^^^^^^^^^^^ pattern `B` not covered
......@@ -23,7 +23,7 @@ LL | B,
= note: the matched value is of type `HiddenEnum`
error[E0004]: non-exhaustive patterns: `B` and `_` not covered
--> $DIR/doc-hidden-non-exhaustive.rs:20:11
--> $DIR/doc-hidden-non-exhaustive.rs:27:11
|
LL | match HiddenEnum::A {
| ^^^^^^^^^^^^^ patterns `B` and `_` not covered
......@@ -38,7 +38,7 @@ LL | B,
= note: the matched value is of type `HiddenEnum`
error[E0004]: non-exhaustive patterns: `Some(B)` and `Some(_)` not covered
--> $DIR/doc-hidden-non-exhaustive.rs:25:11
--> $DIR/doc-hidden-non-exhaustive.rs:32:11
|
LL | match None {
| ^^^^ patterns `Some(B)` and `Some(_)` not covered
......@@ -52,6 +52,24 @@ LL | Some(#[stable(feature = "rust1", since = "1.0.0")] T),
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `Option<HiddenEnum>`
error: aborting due to 4 previous errors
error[E0004]: non-exhaustive patterns: `C` not covered
--> $DIR/doc-hidden-non-exhaustive.rs:38:11
|
LL | / enum InCrate {
LL | | A,
LL | | B,
LL | | #[doc(hidden)]
LL | | C,
| | - not covered
LL | | }
| |_- `InCrate` defined here
...
LL | match InCrate::A {
| ^^^^^^^^^^ pattern `C` not covered
|
= help: ensure that all possible cases are being handled, possibly by adding wildcards or more match arms
= note: the matched value is of type `InCrate`
error: aborting due to 5 previous errors
For more information about this error, try `rustc --explain E0004`.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册