Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
21c580e4
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,发现更多精彩内容 >>
提交
21c580e4
编写于
9月 30, 2017
作者:
M
Maxim Zholobak
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add hints for the case of confusing enum with its variants
上级
c703ff27
变更
1
显示空白变更内容
内联
并排
Showing
1 changed file
with
79 addition
and
0 deletion
+79
-0
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+79
-0
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
21c580e4
...
...
@@ -2599,6 +2599,21 @@ fn smart_resolve_path_fragment(&mut self,
}
_
=>
{}
},
(
Def
::
Enum
(
..
),
PathSource
::
TupleStruct
)
=>
{
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
)))
.collect
::
<
Vec
<
_
>>
()
.join
(
"
\n
"
)));
}
else
{
err
.note
(
"did you mean to use one of the enum's variants?"
);
}
return
(
err
,
candidates
);
},
_
if
ns
==
ValueNS
&&
is_struct_like
(
def
)
=>
{
if
let
Def
::
Struct
(
def_id
)
=
def
{
if
let
Some
((
ctor_def
,
ctor_vis
))
...
...
@@ -3495,6 +3510,70 @@ fn lookup_import_candidates<FilterFn>(&mut self,
candidates
}
fn
find_module
(
&
mut
self
,
module_def
:
Def
)
->
Option
<
(
Module
<
'a
>
,
ImportSuggestion
)
>
{
let
mut
result
=
None
;
let
mut
worklist
=
Vec
::
new
();
let
mut
seen_modules
=
FxHashSet
();
worklist
.push
((
self
.graph_root
,
Vec
::
new
()));
while
let
Some
((
in_module
,
path_segments
))
=
worklist
.pop
()
{
// abort if the module is already found
if
let
Some
(
_
)
=
result
{
break
;
}
self
.populate_module_if_necessary
(
in_module
);
in_module
.for_each_child
(|
ident
,
_
,
name_binding
|
{
// abort if the module is already found
if
let
Some
(
_
)
=
result
{
return
();
}
if
let
Some
(
module
)
=
name_binding
.module
()
{
// form the path
let
mut
path_segments
=
path_segments
.clone
();
path_segments
.push
(
ast
::
PathSegment
::
from_ident
(
ident
,
name_binding
.span
));
if
module
.def
()
==
Some
(
module_def
)
{
let
path
=
Path
{
span
:
name_binding
.span
,
segments
:
path_segments
,
};
result
=
Some
((
module
,
ImportSuggestion
{
path
:
path
}));
}
else
{
// add the module to the lookup
if
seen_modules
.insert
(
module
.def_id
()
.unwrap
())
{
worklist
.push
((
module
,
path_segments
));
}
}
}
});
}
result
}
fn
collect_enum_variants
(
&
mut
self
,
enum_def
:
Def
)
->
Option
<
Vec
<
Path
>>
{
if
let
Def
::
Enum
(
..
)
=
enum_def
{}
else
{
panic!
(
"Non-enum def passed to collect_enum_variants: {:?}"
,
enum_def
)
}
self
.find_module
(
enum_def
)
.map
(|(
enum_module
,
enum_import_suggestion
)|
{
let
mut
variants
=
Vec
::
new
();
enum_module
.for_each_child_stable
(|
ident
,
_
,
name_binding
|
{
if
let
Def
::
Variant
(
..
)
=
name_binding
.def
()
{
let
mut
segms
=
enum_import_suggestion
.path.segments
.clone
();
segms
.push
(
ast
::
PathSegment
::
from_ident
(
ident
,
name_binding
.span
));
variants
.push
(
Path
{
span
:
name_binding
.span
,
segments
:
segms
,
});
}
});
variants
})
}
fn
record_def
(
&
mut
self
,
node_id
:
NodeId
,
resolution
:
PathResolution
)
{
debug!
(
"(recording def) recording {:?} for {}"
,
resolution
,
node_id
);
if
let
Some
(
prev_res
)
=
self
.def_map
.insert
(
node_id
,
resolution
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录