Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
32a0cfeb
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,发现更多精彩内容 >>
提交
32a0cfeb
编写于
8月 22, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid reporting multiple ambiguity errors for a single use of a name.
上级
681a14f2
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
32 addition
and
11 deletion
+32
-11
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+19
-11
src/test/compile-fail/imports/duplicate.rs
src/test/compile-fail/imports/duplicate.rs
+13
-0
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
32a0cfeb
...
...
@@ -1065,6 +1065,7 @@ pub struct Resolver<'a> {
pub
maybe_unused_trait_imports
:
NodeSet
,
privacy_errors
:
Vec
<
PrivacyError
<
'a
>>
,
ambiguity_errors
:
Vec
<
(
Span
,
Name
,
&
'a
NameBinding
<
'a
>
)
>
,
arenas
:
&
'a
ResolverArenas
<
'a
>
,
dummy_binding
:
&
'a
NameBinding
<
'a
>
,
...
...
@@ -1218,6 +1219,7 @@ pub fn new(session: &'a Session, make_glob_map: MakeGlobMap, arenas: &'a Resolve
maybe_unused_trait_imports
:
NodeSet
(),
privacy_errors
:
Vec
::
new
(),
ambiguity_errors
:
Vec
::
new
(),
arenas
:
arenas
,
dummy_binding
:
arenas
.alloc_name_binding
(
NameBinding
{
...
...
@@ -1245,7 +1247,7 @@ pub fn resolve_crate(&mut self, krate: &Crate) {
visit
::
walk_crate
(
self
,
krate
);
check_unused
::
check_crate
(
self
,
krate
);
self
.report_
privacy_
errors
();
self
.report_errors
();
}
fn
new_module
(
&
self
,
parent_link
:
ParentLink
<
'a
>
,
def
:
Option
<
Def
>
,
normal_ancestor_id
:
NodeId
)
...
...
@@ -1276,14 +1278,8 @@ fn record_use(&mut self, name: Name, ns: Namespace, binding: &'a NameBinding<'a>
self
.add_to_glob_map
(
directive
.id
,
name
);
}
if
let
Some
((
b1
,
b2
))
=
binding
.ambiguity
()
{
let
msg1
=
format!
(
"`{}` could resolve to the name imported here"
,
name
);
let
msg2
=
format!
(
"`{}` could also resolve to the name imported here"
,
name
);
self
.session
.struct_span_err
(
span
,
&
format!
(
"`{}` is ambiguous"
,
name
))
.span_note
(
b1
.span
,
&
msg1
)
.span_note
(
b2
.span
,
&
msg2
)
.note
(
&
format!
(
"Consider adding an explicit import of `{}` to disambiguate"
,
name
))
.emit
();
if
binding
.ambiguity
()
.is_some
()
{
self
.ambiguity_errors
.push
((
span
,
name
,
binding
));
return
true
;
}
...
...
@@ -3289,9 +3285,21 @@ fn is_accessible_from(&self, vis: ty::Visibility, module: Module<'a>) -> bool {
vis
.is_accessible_from
(
module
.normal_ancestor_id
,
self
)
}
fn
report_privacy_errors
(
&
self
)
{
if
self
.privacy_errors
.len
()
==
0
{
return
}
fn
report_errors
(
&
self
)
{
let
mut
reported_spans
=
FnvHashSet
();
for
&
(
span
,
name
,
binding
)
in
&
self
.ambiguity_errors
{
if
!
reported_spans
.insert
(
span
)
{
continue
}
let
(
b1
,
b2
)
=
binding
.ambiguity
()
.unwrap
();
let
msg1
=
format!
(
"`{}` could resolve to the name imported here"
,
name
);
let
msg2
=
format!
(
"`{}` could also resolve to the name imported here"
,
name
);
self
.session
.struct_span_err
(
span
,
&
format!
(
"`{}` is ambiguous"
,
name
))
.span_note
(
b1
.span
,
&
msg1
)
.span_note
(
b2
.span
,
&
msg2
)
.note
(
&
format!
(
"Consider adding an explicit import of `{}` to disambiguate"
,
name
))
.emit
();
}
for
&
PrivacyError
(
span
,
name
,
binding
)
in
&
self
.privacy_errors
{
if
!
reported_spans
.insert
(
span
)
{
continue
}
if
binding
.is_extern_crate
()
{
...
...
src/test/compile-fail/imports/duplicate.rs
浏览文件 @
32a0cfeb
...
...
@@ -50,3 +50,16 @@ fn main() {
g
::
foo
();
//~ ERROR `foo` is ambiguous
//~| NOTE Consider adding an explicit import of `foo` to disambiguate
}
mod
ambiguous_module_errors
{
pub
mod
m1
{
pub
use
super
::
m1
as
foo
;
}
pub
mod
m2
{
pub
use
super
::
m2
as
foo
;
}
use
self
::
m1
::
*
;
//~ NOTE
use
self
::
m2
::
*
;
//~ NOTE
fn
f
()
{
foo
::
bar
();
//~ ERROR `foo` is ambiguous
//~| NOTE
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录