Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
77fb6a0f
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,发现更多精彩内容 >>
提交
77fb6a0f
编写于
3月 12, 2021
作者:
C
csmoe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
fix: check before index into generated patterns
上级
2fd2796a
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
25 addition
and
80 deletion
+25
-80
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
+3
-1
compiler/rustc_typeck/src/check/pat.rs
compiler/rustc_typeck/src/check/pat.rs
+0
-49
src/test/ui/structs/struct-variant-privacy-xc.rs
src/test/ui/structs/struct-variant-privacy-xc.rs
+1
-2
src/test/ui/structs/struct-variant-privacy-xc.stderr
src/test/ui/structs/struct-variant-privacy-xc.stderr
+1
-7
src/test/ui/structs/struct-variant-privacy.rs
src/test/ui/structs/struct-variant-privacy.rs
+0
-1
src/test/ui/structs/struct-variant-privacy.stderr
src/test/ui/structs/struct-variant-privacy.stderr
+1
-7
src/test/ui/typeck/issue-82772.rs
src/test/ui/typeck/issue-82772.rs
+5
-5
src/test/ui/typeck/issue-82772.stderr
src/test/ui/typeck/issue-82772.stderr
+14
-8
未找到文件。
compiler/rustc_mir_build/src/thir/pattern/deconstruct_pat.rs
浏览文件 @
77fb6a0f
...
...
@@ -1343,7 +1343,9 @@ fn replace_fields_indexed(
match
&
mut
fields
{
Fields
::
Vec
(
pats
)
=>
{
for
(
i
,
pat
)
in
new_pats
{
pats
[
i
]
=
pat
if
let
Some
(
p
)
=
pats
.get_mut
(
i
)
{
*
p
=
pat
;
}
}
}
Fields
::
Filtered
{
fields
,
..
}
=>
{
...
...
compiler/rustc_typeck/src/check/pat.rs
浏览文件 @
77fb6a0f
...
...
@@ -1176,7 +1176,6 @@ fn check_struct_pat_fields(
let
mut
no_field_errors
=
true
;
let
mut
inexistent_fields
=
vec!
[];
let
mut
invisible_fields
=
vec!
[];
// Typecheck each field.
for
field
in
fields
{
let
span
=
field
.span
;
...
...
@@ -1192,12 +1191,6 @@ fn check_struct_pat_fields(
field_map
.get
(
&
ident
)
.map
(|(
i
,
f
)|
{
if
!
f
.vis
.is_accessible_from
(
tcx
.parent_module
(
pat
.hir_id
)
.to_def_id
(),
tcx
)
{
invisible_fields
.push
(
field
.ident
);
}
self
.write_field_index
(
field
.hir_id
,
*
i
);
self
.tcx
.check_stability
(
f
.did
,
Some
(
pat
.hir_id
),
span
);
self
.field_ty
(
span
,
f
,
substs
)
...
...
@@ -1288,13 +1281,6 @@ fn check_struct_pat_fields(
self
.error_tuple_variant_index_shorthand
(
variant
,
pat
,
fields
)
{
err
.emit
();
}
else
if
!
invisible_fields
.is_empty
()
{
let
mut
err
=
self
.error_invisible_fields
(
adt
.variant_descr
(),
&
invisible_fields
,
variant
,
);
err
.emit
();
}
}
}
...
...
@@ -1373,41 +1359,6 @@ fn error_field_already_bound(&self, span: Span, ident: Ident, other_field: Span)
.emit
();
}
fn
error_invisible_fields
(
&
self
,
kind_name
:
&
str
,
invisible_fields
:
&
[
Ident
],
variant
:
&
ty
::
VariantDef
,
)
->
DiagnosticBuilder
<
'tcx
>
{
let
spans
=
invisible_fields
.iter
()
.map
(|
ident
|
ident
.span
)
.collect
::
<
Vec
<
_
>>
();
let
(
field_names
,
t
)
=
if
invisible_fields
.len
()
==
1
{
(
format!
(
"a field named `{}`"
,
invisible_fields
[
0
]),
"is"
)
}
else
{
(
format!
(
"fields named {}"
,
invisible_fields
.iter
()
.map
(|
ident
|
format!
(
"`{}`"
,
ident
))
.collect
::
<
Vec
<
String
>>
()
.join
(
", "
)
),
"are"
,
)
};
let
err
=
struct_span_err!
(
self
.tcx.sess
,
spans
,
E0603
,
"cannot match on {} of {} `{}`, which {} not accessible in current scope"
,
field_names
,
kind_name
,
self
.tcx
.def_path_str
(
variant
.def_id
),
t
);
err
}
fn
error_inexistent_fields
(
&
self
,
kind_name
:
&
str
,
...
...
src/test/ui/structs/struct-variant-privacy-xc.rs
浏览文件 @
77fb6a0f
...
...
@@ -4,8 +4,7 @@
fn
f
(
b
:
struct_variant_privacy
::
Bar
)
{
//~^ ERROR enum `Bar` is private
match
b
{
struct_variant_privacy
::
Bar
::
Baz
{
a
:
_
a
}
=>
{}
//~ ERROR cannot match on
//~^ ERROR enum `Bar` is private
struct_variant_privacy
::
Bar
::
Baz
{
a
:
_
a
}
=>
{}
//~ ERROR enum `Bar` is private
}
}
...
...
src/test/ui/structs/struct-variant-privacy-xc.stderr
浏览文件 @
77fb6a0f
...
...
@@ -22,12 +22,6 @@ note: the enum `Bar` is defined here
LL | enum Bar {
| ^^^^^^^^
error[E0603]: cannot match on a field named `a` of variant `struct_variant_privacy::Bar::Baz`, which is not accessible in current scope
--> $DIR/struct-variant-privacy-xc.rs:7:44
|
LL | struct_variant_privacy::Bar::Baz { a: _a } => {}
| ^
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0603`.
src/test/ui/structs/struct-variant-privacy.rs
浏览文件 @
77fb6a0f
...
...
@@ -8,7 +8,6 @@ fn f(b: foo::Bar) {
//~^ ERROR enum `Bar` is private
match
b
{
foo
::
Bar
::
Baz
{
a
:
_
a
}
=>
{}
//~ ERROR enum `Bar` is private
//~^ ERROR cannot match on
}
}
...
...
src/test/ui/structs/struct-variant-privacy.stderr
浏览文件 @
77fb6a0f
...
...
@@ -22,12 +22,6 @@ note: the enum `Bar` is defined here
LL | enum Bar {
| ^^^^^^^^
error[E0603]: cannot match on a field named `a` of variant `Bar::Baz`, which is not accessible in current scope
--> $DIR/struct-variant-privacy.rs:10:25
|
LL | foo::Bar::Baz { a: _a } => {}
| ^
error: aborting due to 3 previous errors
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0603`.
src/test/ui/typeck/issue-82772.rs
浏览文件 @
77fb6a0f
// edition:2018
fn
main
()
{
use
a
::
Local
ModPrivateStruct
;
let
Box
{
1
:
_
,
..
}:
Box
<
()
>
;
//~ ERROR cannot match on
let
LocalModPrivateStruct
{
1
:
_
,
..
}
=
LocalModPrivateStruct
::
default
();
//~^ ERROR cannot match on
use
a
::
ModPrivateStruct
;
let
Box
{
0
:
_
,
..
}:
Box
<
()
>
;
//~ ERROR field `0` of
let
Box
{
1
:
_
,
..
}:
Box
<
()
>
;
//~ ERROR field `1` of
let
ModPrivateStruct
{
1
:
_
,
..
}
=
ModPrivateStruct
::
default
();
//~ ERROR field `1` of
}
mod
a
{
#[derive(Default)]
pub
struct
Local
ModPrivateStruct
(
u8
,
u8
);
pub
struct
ModPrivateStruct
(
u8
,
u8
);
}
src/test/ui/typeck/issue-82772.stderr
浏览文件 @
77fb6a0f
error[E0
603]: cannot match on a field named `1` of struct `Box`, which is not accessible in current scop
e
error[E0
451]: field `0` of struct `Box` is privat
e
--> $DIR/issue-82772.rs:5:15
|
LL | let Box { 0: _, .. }: Box<()>;
| ^^^^ private field
error[E0451]: field `1` of struct `Box` is private
--> $DIR/issue-82772.rs:6:15
|
LL | let Box { 1: _, .. }: Box<()>;
| ^
| ^
^^^ private field
error[E0
603]: cannot match on a field named `1` of struct `LocalModPrivateStruct`, which is not accessible in current scop
e
--> $DIR/issue-82772.rs:
6:33
error[E0
451]: field `1` of struct `ModPrivateStruct` is privat
e
--> $DIR/issue-82772.rs:
7:28
|
LL | let
LocalModPrivateStruct { 1: _, .. } = Local
ModPrivateStruct::default();
|
^
LL | let
ModPrivateStruct { 1: _, .. } =
ModPrivateStruct::default();
|
^^^^ private field
error: aborting due to
2
previous errors
error: aborting due to
3
previous errors
For more information about this error, try `rustc --explain E0
603
`.
For more information about this error, try `rustc --explain E0
451
`.
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录