Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
e8c87935
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
e8c87935
编写于
1月 12, 2021
作者:
C
Camelid
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Include `..` suggestion if fields are all wildcards
上级
d7307a71
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
35 addition
and
8 deletion
+35
-8
compiler/rustc_typeck/src/check/pat.rs
compiler/rustc_typeck/src/check/pat.rs
+3
-2
src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr
...ructuring-assignment/tuple_struct_destructure_fail.stderr
+8
-0
src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
...sues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
+4
-0
src/test/ui/match/match-pattern-field-mismatch.stderr
src/test/ui/match/match-pattern-field-mismatch.stderr
+4
-0
src/test/ui/pattern/pat-tuple-underfield.rs
src/test/ui/pattern/pat-tuple-underfield.rs
+2
-0
src/test/ui/pattern/pat-tuple-underfield.stderr
src/test/ui/pattern/pat-tuple-underfield.stderr
+14
-6
未找到文件。
compiler/rustc_typeck/src/check/pat.rs
浏览文件 @
e8c87935
...
...
@@ -1068,8 +1068,9 @@ fn e0023(
Applicability
::
MaybeIncorrect
,
);
// Only suggest `..` if more than one field is missing.
if
fields
.len
()
-
subpats
.len
()
>
1
{
// Only suggest `..` if more than one field is missing
// or the pattern consists of all wildcards.
if
fields
.len
()
-
subpats
.len
()
>
1
||
all_wildcards
{
if
subpats
.is_empty
()
||
all_wildcards
{
err
.span_suggestion_verbose
(
all_fields_span
,
...
...
src/test/ui/destructuring-assignment/tuple_struct_destructure_fail.stderr
浏览文件 @
e8c87935
...
...
@@ -36,6 +36,10 @@ help: use `_` to explicitly ignore each field
|
LL | TupleStruct(_, _) = TupleStruct(1, 2);
| ^^^
help: use `..` to ignore all fields
|
LL | TupleStruct(..) = TupleStruct(1, 2);
| ^^
error[E0023]: this pattern has 3 fields, but the corresponding tuple variant has 2 fields
--> $DIR/tuple_struct_destructure_fail.rs:34:5
...
...
@@ -59,6 +63,10 @@ help: use `_` to explicitly ignore each field
|
LL | Enum::SingleVariant(_, _) = Enum::SingleVariant(1, 2);
| ^^^
help: use `..` to ignore all fields
|
LL | Enum::SingleVariant(..) = Enum::SingleVariant(1, 2);
| ^^
error[E0070]: invalid left-hand side of assignment
--> $DIR/tuple_struct_destructure_fail.rs:40:12
...
...
src/test/ui/issues/issue-67037-pat-tup-scrut-ty-diff-less-fields.stderr
浏览文件 @
e8c87935
...
...
@@ -22,6 +22,10 @@ help: use `_` to explicitly ignore each field
|
LL | let P(_) = U {};
| ^
help: use `..` to ignore all fields
|
LL | let P(..) = U {};
| ^^
error: aborting due to 2 previous errors
...
...
src/test/ui/match/match-pattern-field-mismatch.stderr
浏览文件 @
e8c87935
...
...
@@ -11,6 +11,10 @@ help: use `_` to explicitly ignore each field
|
LL | Color::Rgb(_, _, _) => { }
| ^^^
help: use `..` to ignore all fields
|
LL | Color::Rgb(..) => { }
| ^^
error: aborting due to previous error
...
...
src/test/ui/pattern/pat-tuple-underfield.rs
浏览文件 @
e8c87935
...
...
@@ -14,6 +14,7 @@ fn main() {
S
(
_
)
=>
{}
//~^ ERROR this pattern has 1 field, but the corresponding tuple struct has 2 fields
//~| HELP use `_` to explicitly ignore each field
//~| HELP use `..` to ignore all fields
}
match
S
(
0
,
1.0
)
{
S
()
=>
{}
...
...
@@ -31,6 +32,7 @@ fn main() {
E
::
S
(
_
)
=>
{}
//~^ ERROR this pattern has 1 field, but the corresponding tuple variant has 2 fields
//~| HELP use `_` to explicitly ignore each field
//~| HELP use `..` to ignore all fields
}
match
E
::
S
(
0
,
1.0
)
{
E
::
S
()
=>
{}
...
...
src/test/ui/pattern/pat-tuple-underfield.stderr
浏览文件 @
e8c87935
error[E0532]: expected unit struct, unit variant or constant, found tuple variant `E::S`
--> $DIR/pat-tuple-underfield.rs:4
2
:9
--> $DIR/pat-tuple-underfield.rs:4
4
:9
|
LL | S(i32, f32),
| ----------- `E::S` defined here
...
...
@@ -34,9 +34,13 @@ help: use `_` to explicitly ignore each field
|
LL | S(_, _) => {}
| ^^^
help: use `..` to ignore all fields
|
LL | S(..) => {}
| ^^
error[E0023]: this pattern has 0 fields, but the corresponding tuple struct has 2 fields
--> $DIR/pat-tuple-underfield.rs:
19
:9
--> $DIR/pat-tuple-underfield.rs:
20
:9
|
LL | struct S(i32, f32);
| ------------------- tuple struct defined here
...
...
@@ -54,7 +58,7 @@ LL | S(..) => {}
| ^^
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> $DIR/pat-tuple-underfield.rs:2
6
:9
--> $DIR/pat-tuple-underfield.rs:2
7
:9
|
LL | S(i32, f32),
| ----------- tuple variant defined here
...
...
@@ -68,7 +72,7 @@ LL | E::S(x, _) => {}
| ^^^
error[E0023]: this pattern has 1 field, but the corresponding tuple variant has 2 fields
--> $DIR/pat-tuple-underfield.rs:3
1
:9
--> $DIR/pat-tuple-underfield.rs:3
2
:9
|
LL | S(i32, f32),
| ----------- tuple variant defined here
...
...
@@ -80,9 +84,13 @@ help: use `_` to explicitly ignore each field
|
LL | E::S(_, _) => {}
| ^^^
help: use `..` to ignore all fields
|
LL | E::S(..) => {}
| ^^
error[E0023]: this pattern has 0 fields, but the corresponding tuple variant has 2 fields
--> $DIR/pat-tuple-underfield.rs:3
6
:9
--> $DIR/pat-tuple-underfield.rs:3
8
:9
|
LL | S(i32, f32),
| ----------- tuple variant defined here
...
...
@@ -100,7 +108,7 @@ LL | E::S(..) => {}
| ^^
error[E0023]: this pattern has 2 fields, but the corresponding tuple struct has 4 fields
--> $DIR/pat-tuple-underfield.rs:
48
:9
--> $DIR/pat-tuple-underfield.rs:
50
:9
|
LL | struct Point4(i32, i32, i32, i32);
| ---------------------------------- tuple struct defined here
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录