Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b9896cbf
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,发现更多精彩内容 >>
提交
b9896cbf
编写于
9月 20, 2014
作者:
J
Jakub Wieczorek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix handling of struct variants in a couple of places
Fixes #17405. Fixes #17518. Fixes #17800.
上级
c5864907
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
86 addition
and
14 deletion
+86
-14
src/librustc/diagnostics.rs
src/librustc/diagnostics.rs
+3
-5
src/librustc/middle/typeck/check/_match.rs
src/librustc/middle/typeck/check/_match.rs
+24
-7
src/librustc/middle/typeck/check/mod.rs
src/librustc/middle/typeck/check/mod.rs
+1
-1
src/test/compile-fail/issue-15896.rs
src/test/compile-fail/issue-15896.rs
+1
-1
src/test/compile-fail/issue-17405.rs
src/test/compile-fail/issue-17405.rs
+19
-0
src/test/compile-fail/issue-17518.rs
src/test/compile-fail/issue-17518.rs
+17
-0
src/test/compile-fail/issue-17800.rs
src/test/compile-fail/issue-17800.rs
+21
-0
未找到文件。
src/librustc/diagnostics.rs
浏览文件 @
b9896cbf
...
...
@@ -38,7 +38,6 @@
E0017
,
E0019
,
E0020
,
E0021
,
E0022
,
E0023
,
E0024
,
...
...
@@ -62,7 +61,6 @@
E0045
,
E0046
,
E0047
,
E0048
,
E0049
,
E0050
,
E0051
,
...
...
@@ -117,8 +115,6 @@
E0109
,
E0110
,
E0113
,
E0114
,
E0115
,
E0116
,
E0117
,
E0118
,
...
...
@@ -152,5 +148,7 @@
E0158
,
E0159
,
E0161
,
E0162
E0162
,
E0163
,
E0164
)
src/librustc/middle/typeck/check/_match.rs
浏览文件 @
b9896cbf
...
...
@@ -382,26 +382,43 @@ pub fn check_struct_like_enum_variant_pat(pcx: &pat_ctxt,
// Find the variant that was specified.
match
tcx
.def_map
.borrow
()
.find
(
&
pat_id
)
{
Some
(
&
def
::
DefVariant
(
found_enum_id
,
variant_id
,
_
))
Some
(
&
def
::
DefVariant
(
found_enum_id
,
variant_id
,
true
))
if
found_enum_id
==
enum_id
=>
{
// Get the struct fields from this struct-like enum variant.
let
class_fields
=
ty
::
lookup_struct_fields
(
tcx
,
variant_id
);
check_struct_pat_fields
(
pcx
,
span
,
fields
,
class_fields
,
let
struct_fields
=
ty
::
lookup_struct_fields
(
tcx
,
variant_id
);
check_struct_pat_fields
(
pcx
,
span
,
fields
,
struct_fields
,
variant_id
,
substitutions
,
etc
);
fcx
.write_ty
(
pat_id
,
expected
);
}
Some
(
&
def
::
DefVariant
(
_
,
_
,
false
))
=>
{
let
name
=
pprust
::
path_to_string
(
path
);
span_err!
(
tcx
.sess
,
span
,
E0163
,
"`{}` does not name a struct variant"
,
name
);
fcx
.write_error
(
pat_id
);
}
Some
(
&
def
::
DefVariant
(
_
,
_
,
true
))
=>
{
let
name
=
pprust
::
path_to_string
(
path
);
span_err!
(
tcx
.sess
,
span
,
E0164
,
"`{}` does not name a variant of the type being matched against"
,
name
);
fcx
.write_error
(
pat_id
);
}
Some
(
&
def
::
DefStruct
(
..
))
|
Some
(
&
def
::
DefVariant
(
..
))
|
Some
(
&
def
::
DefTy
(
..
))
=>
{
let
name
=
pprust
::
path_to_string
(
path
);
span_err!
(
tcx
.sess
,
span
,
E0028
,
"
mismatched types: expected `{}`, found `{}`"
,
fcx
.infcx
()
.ty_to_string
(
expected
),
name
);
"
`{}` does not name a variant"
,
name
);
fcx
.write_error
(
pat_id
);
}
_
=>
{
tcx
.sess
.span_bug
(
span
,
"resolve didn't write in variant"
);
}
}
if
ty
::
type_is_error
(
fcx
.node_ty
(
pat_id
))
{
for
field
in
fields
.iter
()
{
check_pat
(
pcx
,
&*
field
.pat
,
ty
::
mk_err
());
}
}
}
// Pattern checking is top-down rather than bottom-up so that bindings get
...
...
src/librustc/middle/typeck/check/mod.rs
浏览文件 @
b9896cbf
...
...
@@ -4330,7 +4330,7 @@ fn check_struct_fields_on_error(fcx: &FnCtxt,
// Resolve the path.
let
def
=
tcx
.def_map
.borrow
()
.find
(
&
id
)
.map
(|
i
|
*
i
);
let
struct_id
=
match
def
{
Some
(
def
::
DefVariant
(
enum_id
,
variant_id
,
_
))
=>
{
Some
(
def
::
DefVariant
(
enum_id
,
variant_id
,
true
))
=>
{
check_struct_enum_variant
(
fcx
,
id
,
expr
.span
,
enum_id
,
variant_id
,
fields
.as_slice
());
enum_id
...
...
src/test/compile-fail/issue-15896.rs
浏览文件 @
b9896cbf
...
...
@@ -18,7 +18,7 @@ enum E { B(R, Tau) }
let
e
=
B
(
REB
(()),
Tau
{
t
:
3
});
let
u
=
match
e
{
B
(
Tau
{
t
:
x
},
//~ ERROR mismatched types
Tau
{
t
:
x
},
//~ ERROR `Tau` does not name a variant
_
)
=>
x
,
};
}
src/test/compile-fail/issue-17405.rs
0 → 100644
浏览文件 @
b9896cbf
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum
Foo
{
Bar
(
int
)
}
fn
main
()
{
match
Bar
(
1
i
)
{
Foo
{
i
}
=>
()
//~ ERROR `Foo` does not name a variant
}
}
src/test/compile-fail/issue-17518.rs
0 → 100644
浏览文件 @
b9896cbf
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum
SomeEnum
{
E
}
fn
main
()
{
E
{
name
:
"foobar"
};
//~ ERROR `E` does not name a structure
}
src/test/compile-fail/issue-17800.rs
0 → 100644
浏览文件 @
b9896cbf
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum
MyOption
<
T
>
{
MySome
(
T
),
MyNone
,
}
fn
main
()
{
match
MySome
(
42
i
)
{
MySome
{
x
:
42
i
}
=>
(),
//~ ERROR `MySome` does not name a struct variant
_
=>
(),
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录