Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
39f848ef
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,发现更多精彩内容 >>
提交
39f848ef
编写于
11月 23, 2017
作者:
M
Maxim Zholobak
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add module population and case of enum in place of expression
上级
08c81c1a
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
31 addition
and
9 deletion
+31
-9
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+6
-3
src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.rs
...st/ui/did_you_mean/issue-43871-enum-instead-of-variant.rs
+8
-0
src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
...i/did_you_mean/issue-43871-enum-instead-of-variant.stderr
+17
-6
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
39f848ef
...
...
@@ -2599,13 +2599,14 @@ fn smart_resolve_path_fragment(&mut self,
}
_
=>
{}
},
(
Def
::
Enum
(
..
),
PathSource
::
TupleStruct
)
=>
{
(
Def
::
Enum
(
..
),
PathSource
::
TupleStruct
)
|
(
Def
::
Enum
(
..
),
PathSource
::
Expr
(
..
))
=>
{
if
let
Some
(
variants
)
=
this
.collect_enum_variants
(
def
)
{
err
.note
(
&
format!
(
"did you mean to use one
\
of the following variants?
\n
{}"
,
variants
.iter
()
.map
(|
suggestion
|
format!
(
"- `{}`"
,
path_names_to_string
(
suggestion
)
))
.map
(|
suggestion
|
path_names_to_string
(
suggestion
))
.map
(|
suggestion
|
format!
(
"- `{}`"
,
suggestion
))
.collect
::
<
Vec
<
_
>>
()
.join
(
"
\n
"
)));
...
...
@@ -3559,6 +3560,8 @@ fn collect_enum_variants(&mut self, enum_def: Def) -> Option<Vec<Path>> {
}
self
.find_module
(
enum_def
)
.map
(|(
enum_module
,
enum_import_suggestion
)|
{
self
.populate_module_if_necessary
(
enum_module
);
let
mut
variants
=
Vec
::
new
();
enum_module
.for_each_child_stable
(|
ident
,
_
,
name_binding
|
{
if
let
Def
::
Variant
(
..
)
=
name_binding
.def
()
{
...
...
src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.rs
浏览文件 @
39f848ef
...
...
@@ -8,12 +8,20 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.
enum
Example
{
Ex
(
String
),
NotEx
}
fn
result_test
()
{
let
x
=
Option
(
1
);
if
let
Option
(
_
)
=
x
{
println!
(
"It is OK."
);
}
let
y
=
Example
::
Ex
(
String
::
from
(
"test"
));
if
let
Example
(
_
)
=
y
{
println!
(
"It is OK."
);
}
}
fn
main
()
{}
src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
浏览文件 @
39f848ef
error[E0423]: expected function, found enum `Option`
--> $DIR/issue-43871-enum-instead-of-variant.rs:12:13
--> $DIR/issue-43871-enum-instead-of-variant.rs:14:13
|
14 | let x = Option(1);
| ^^^^^^
|
12 | let x = Option(1);
| ^^^^^^ not a function
= note: did you mean to use one of the following variants?
- `std::prelude::v1::Option::None`
- `std::prelude::v1::Option::Some`
error[E0532]: expected tuple struct/variant, found enum `Option`
--> $DIR/issue-43871-enum-instead-of-variant.rs:1
4
:12
--> $DIR/issue-43871-enum-instead-of-variant.rs:1
6
:12
|
1
4
| if let Option(_) = x {
1
6
| if let Option(_) = x {
| ^^^^^^
|
= note: did you mean to use one of the following variants?
- `std::prelude::v1::Option::None`
- `std::prelude::v1::Option::Some`
error: aborting due to previous error
error[E0532]: expected tuple struct/variant, found enum `Example`
--> $DIR/issue-43871-enum-instead-of-variant.rs:22:12
|
22 | if let Example(_) = y {
| ^^^^^^^
|
= note: did you mean to use one of the following variants?
- `Example::Ex`
- `Example::NotEx`
error: aborting due to 3 previous errors
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录