Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
de08d0ec
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,发现更多精彩内容 >>
未验证
提交
de08d0ec
编写于
3月 22, 2019
作者:
M
Mazdak Farrokhzad
提交者:
GitHub
3月 22, 2019
浏览文件
操作
浏览文件
下载
差异文件
Rollup merge of #59323 - euclio:enum-instead-of-variant, r=varkor
use suggestions for "enum instead of variant" error
上级
9d33d6fa
16a8abe1
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
118 addition
and
47 deletion
+118
-47
src/librustc_resolve/error_reporting.rs
src/librustc_resolve/error_reporting.rs
+14
-7
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
+19
-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
+42
-13
src/test/ui/glob-resolve1.stderr
src/test/ui/glob-resolve1.stderr
+1
-4
src/test/ui/resolve/privacy-enum-ctor.stderr
src/test/ui/resolve/privacy-enum-ctor.stderr
+42
-23
未找到文件。
src/librustc_resolve/error_reporting.rs
浏览文件 @
de08d0ec
...
...
@@ -293,13 +293,20 @@ fn smart_resolve_context_dependent_help(
(
Def
::
Enum
(
..
),
PathSource
::
TupleStruct
)
|
(
Def
::
Enum
(
..
),
PathSource
::
Expr
(
..
))
=>
{
if
let
Some
(
variants
)
=
self
.collect_enum_variants
(
def
)
{
err
.note
(
&
format!
(
"did you mean to use one
\
of the following variants?
\n
{}"
,
variants
.iter
()
.map
(|
suggestion
|
path_names_to_string
(
suggestion
))
.map
(|
suggestion
|
format!
(
"- `{}`"
,
suggestion
))
.collect
::
<
Vec
<
_
>>
()
.join
(
"
\n
"
)));
if
!
variants
.is_empty
()
{
let
msg
=
if
variants
.len
()
==
1
{
"try using the enum's variant"
}
else
{
"try using one of the enum's variants"
};
err
.span_suggestions
(
span
,
msg
,
variants
.iter
()
.map
(
path_names_to_string
),
Applicability
::
MaybeIncorrect
,
);
}
}
else
{
err
.note
(
"did you mean to use one of the enum's variants?"
);
}
...
...
src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.rs
浏览文件 @
de08d0ec
enum
Example
{
Ex
(
String
),
NotEx
}
enum
Void
{}
enum
ManyVariants
{
One
,
Two
,
Three
,
Four
,
Five
,
Six
,
Seven
,
Eight
,
Nine
,
Ten
,
}
fn
result_test
()
{
let
x
=
Option
(
1
);
//~ ERROR expected function, found enum
...
...
@@ -12,6 +27,10 @@ fn result_test() {
if
let
Example
(
_
)
=
y
{
//~ ERROR expected tuple struct/variant, found enum
println!
(
"It is OK."
);
}
let
y
=
Void
();
//~ ERROR expected function, found enum
let
z
=
ManyVariants
();
//~ ERROR expected function, found enum
}
fn
main
()
{}
src/test/ui/did_you_mean/issue-43871-enum-instead-of-variant.stderr
浏览文件 @
de08d0ec
error[E0423]: expected function, found enum `Option`
--> $DIR/issue-43871-enum-instead-of-variant.rs:
4
:13
--> $DIR/issue-43871-enum-instead-of-variant.rs:
19
:13
|
LL | let x = Option(1);
| ^^^^^^
help: try using one of the enum's variants
|
= note: did you mean to use one of the following variants?
- `std::prelude::v1::Option::None`
- `std::prelude::v1::Option::Some`
LL | let x = std::prelude::v1::Option::None(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | let x = std::prelude::v1::Option::Some(1);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0532]: expected tuple struct/variant, found enum `Option`
--> $DIR/issue-43871-enum-instead-of-variant.rs:
6
:12
--> $DIR/issue-43871-enum-instead-of-variant.rs:
21
:12
|
LL | if let Option(_) = x {
| ^^^^^^
help: try using one of the enum's variants
|
= note: did you mean to use one of the following variants?
- `std::prelude::v1::Option::None`
- `std::prelude::v1::Option::Some`
LL | if let std::prelude::v1::Option::None(_) = x {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
LL | if let std::prelude::v1::Option::Some(_) = x {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
error[E0532]: expected tuple struct/variant, found enum `Example`
--> $DIR/issue-43871-enum-instead-of-variant.rs:
12
:12
--> $DIR/issue-43871-enum-instead-of-variant.rs:
27
:12
|
LL | if let Example(_) = y {
| ^^^^^^^
help: try using one of the enum's variants
|
= note: did you mean to use one of the following variants?
- `Example::Ex`
- `Example::NotEx`
LL | if let Example::Ex(_) = y {
| ^^^^^^^^^^^
LL | if let Example::NotEx(_) = y {
| ^^^^^^^^^^^^^^
error: aborting due to 3 previous errors
error[E0423]: expected function, found enum `Void`
--> $DIR/issue-43871-enum-instead-of-variant.rs:31:13
|
LL | let y = Void();
| ^^^^
error[E0423]: expected function, found enum `ManyVariants`
--> $DIR/issue-43871-enum-instead-of-variant.rs:33:13
|
LL | let z = ManyVariants();
| ^^^^^^^^^^^^
help: try using one of the enum's variants
|
LL | let z = ManyVariants::Eight();
| ^^^^^^^^^^^^^^^^^^^
LL | let z = ManyVariants::Five();
| ^^^^^^^^^^^^^^^^^^
LL | let z = ManyVariants::Four();
| ^^^^^^^^^^^^^^^^^^
LL | let z = ManyVariants::Nine();
| ^^^^^^^^^^^^^^^^^^
and 6 other candidates
error: aborting due to 5 previous errors
Some errors occurred: E0423, E0532.
For more information about an error, try `rustc --explain E0423`.
src/test/ui/glob-resolve1.stderr
浏览文件 @
de08d0ec
...
...
@@ -22,10 +22,7 @@ error[E0423]: expected value, found enum `B`
--> $DIR/glob-resolve1.rs:24:5
|
LL | B;
| ^
|
= note: did you mean to use one of the following variants?
- `B::B1`
| ^ help: try using the enum's variant: `B::B1`
error[E0425]: cannot find value `C` in this scope
--> $DIR/glob-resolve1.rs:25:5
...
...
src/test/ui/resolve/privacy-enum-ctor.stderr
浏览文件 @
de08d0ec
...
...
@@ -3,22 +3,32 @@ error[E0423]: expected value, found enum `n::Z`
|
LL | n::Z;
| ^^^^
help: try using one of the enum's variants
|
= note: did you mean to use one of the following variants?
- `m::Z::Fn`
- `m::Z::Struct`
- `m::Z::Unit`
LL | m::Z::Fn;
| ^^^^^^^^
LL | m::Z::Struct;
| ^^^^^^^^^^^^
LL | m::Z::Unit;
| ^^^^^^^^^^
error[E0423]: expected value, found enum `Z`
--> $DIR/privacy-enum-ctor.rs:25:9
|
LL | Z;
| ^ help: a function with a similar name exists: `f`
| ^
help: a function with a similar name exists
|
LL | f;
| ^
help: try using one of the enum's variants
|
= note: did you mean to use one of the following variants?
- `m::Z::Fn`
- `m::Z::Struct`
- `m::Z::Unit`
LL | m::Z::Fn;
| ^^^^^^^^
LL | m::Z::Struct;
| ^^^^^^^^^^^^
LL | m::Z::Unit;
| ^^^^^^^^^^
error[E0423]: expected value, found struct variant `Z::Struct`
--> $DIR/privacy-enum-ctor.rs:29:20
...
...
@@ -31,15 +41,18 @@ error[E0423]: expected value, found enum `m::E`
|
LL | let _: E = m::E;
| ^^^^
|
= note: did you mean to use one of the following variants?
- `E::Fn`
- `E::Struct`
- `E::Unit`
help: a function with a similar name exists
|
LL | let _: E = m::f;
| ^
help: try using one of the enum's variants
|
LL | let _: E = E::Fn;
| ^^^^^
LL | let _: E = E::Struct;
| ^^^^^^^^^
LL | let _: E = E::Unit;
| ^^^^^^^
help: possible better candidates are found in other modules, you can import them into scope
|
LL | use std::f32::consts::E;
...
...
@@ -58,11 +71,14 @@ error[E0423]: expected value, found enum `E`
|
LL | let _: E = E;
| ^
help: try using one of the enum's variants
|
= note: did you mean to use one of the following variants?
- `E::Fn`
- `E::Struct`
- `E::Unit`
LL | let _: E = E::Fn;
| ^^^^^
LL | let _: E = E::Struct;
| ^^^^^^^^^
LL | let _: E = E::Unit;
| ^^^^^^^
help: possible better candidates are found in other modules, you can import them into scope
|
LL | use std::f32::consts::E;
...
...
@@ -95,11 +111,14 @@ error[E0423]: expected value, found enum `m::n::Z`
|
LL | let _: Z = m::n::Z;
| ^^^^^^^
help: try using one of the enum's variants
|
= note: did you mean to use one of the following variants?
- `m::Z::Fn`
- `m::Z::Struct`
- `m::Z::Unit`
LL | let _: Z = m::Z::Fn;
| ^^^^^^^^
LL | let _: Z = m::Z::Struct;
| ^^^^^^^^^^^^
LL | let _: Z = m::Z::Unit;
| ^^^^^^^^^^
error[E0412]: cannot find type `Z` in this scope
--> $DIR/privacy-enum-ctor.rs:61:12
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录