Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7ffb29d0
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7ffb29d0
编写于
12月 06, 2021
作者:
D
Devin Ragotzy
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Only filter doc(hidden) fields/variants when not crate local
上级
04210aec
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
70 addition
and
13 deletion
+70
-13
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
+3
-3
compiler/rustc_typeck/src/check/pat.rs
compiler/rustc_typeck/src/check/pat.rs
+2
-1
src/test/ui/pattern/usefulness/doc-hidden-fields.rs
src/test/ui/pattern/usefulness/doc-hidden-fields.rs
+10
-0
src/test/ui/pattern/usefulness/doc-hidden-fields.stderr
src/test/ui/pattern/usefulness/doc-hidden-fields.stderr
+19
-4
src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs
src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs
+13
-0
src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr
...st/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr
+23
-5
未找到文件。
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
浏览文件 @
7ffb29d0
...
...
@@ -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
.variant
s
[
*
idx
]
.def_id
;
return
pcx
.cx.tcx
.is_doc_hidden
(
variant_def_id
)
&&
!
variant_def_id
.is_local
()
;
}
false
}
...
...
compiler/rustc_typeck/src/check/pat.rs
浏览文件 @
7ffb29d0
...
...
@@ -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
();
...
...
src/test/ui/pattern/usefulness/doc-hidden-fields.rs
浏览文件 @
7ffb29d0
...
...
@@ -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`
}
src/test/ui/pattern/usefulness/doc-hidden-fields.stderr
浏览文件 @
7ffb29d0
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:1
1
:9
--> $DIR/doc-hidden-fields.rs:1
8
: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`.
src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.rs
浏览文件 @
7ffb29d0
...
...
@@ -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
}
src/test/ui/pattern/usefulness/doc-hidden-non-exhaustive.stderr
浏览文件 @
7ffb29d0
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:2
0
:11
--> $DIR/doc-hidden-non-exhaustive.rs:2
7
: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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录