Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
31fce914
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,发现更多精彩内容 >>
提交
31fce914
编写于
9月 06, 2018
作者:
E
Eduard-Mihai Burtescu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc_resolve: allow `use crate_name;` under `uniform_paths`.
上级
35a5541f
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
39 addition
and
32 deletion
+39
-32
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+18
-1
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+8
-16
src/test/run-pass/redundant.rs
src/test/run-pass/redundant.rs
+13
-1
src/test/ui/rust-2018/uniform-paths/redundant.stderr
src/test/ui/rust-2018/uniform-paths/redundant.stderr
+0
-14
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
31fce914
...
@@ -181,6 +181,23 @@ fn build_reduced_graph_for_use_tree(
...
@@ -181,6 +181,23 @@ fn build_reduced_graph_for_use_tree(
self
.session
.features_untracked
()
.uniform_paths
);
self
.session
.features_untracked
()
.uniform_paths
);
let
source
=
module_path
[
0
];
let
source
=
module_path
[
0
];
// HACK(eddyb) For `use x::{self, ...};`, use the ID of the
// `self` nested import for the canary. This allows the
// ambiguity reporting scope to ignore false positives
// in the same way it does for `use x;` (by comparing IDs).
let
mut
canary_id
=
id
;
if
let
ast
::
UseTreeKind
::
Nested
(
ref
items
)
=
use_tree
.kind
{
for
&
(
ref
use_tree
,
id
)
in
items
{
if
let
ast
::
UseTreeKind
::
Simple
(
..
)
=
use_tree
.kind
{
if
use_tree
.ident
()
.name
==
keywords
::
SelfValue
.name
()
{
canary_id
=
id
;
break
;
}
}
}
}
// Helper closure to emit a canary with the given base path.
// Helper closure to emit a canary with the given base path.
let
emit
=
|
this
:
&
mut
Self
,
base
:
Option
<
Ident
>
|
{
let
emit
=
|
this
:
&
mut
Self
,
base
:
Option
<
Ident
>
|
{
let
subclass
=
SingleImport
{
let
subclass
=
SingleImport
{
...
@@ -200,7 +217,7 @@ fn build_reduced_graph_for_use_tree(
...
@@ -200,7 +217,7 @@ fn build_reduced_graph_for_use_tree(
base
.into_iter
()
.collect
(),
base
.into_iter
()
.collect
(),
subclass
.clone
(),
subclass
.clone
(),
source
.span
,
source
.span
,
id
,
canary_
id
,
root_use_tree
.span
,
root_use_tree
.span
,
root_id
,
root_id
,
ty
::
Visibility
::
Invisible
,
ty
::
Visibility
::
Invisible
,
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
31fce914
...
@@ -664,6 +664,14 @@ struct UniformPathsCanaryResult {
...
@@ -664,6 +664,14 @@ struct UniformPathsCanaryResult {
self
.per_ns
(|
_
,
ns
|
{
self
.per_ns
(|
_
,
ns
|
{
if
let
Some
(
result
)
=
result
[
ns
]
.get
()
.ok
()
{
if
let
Some
(
result
)
=
result
[
ns
]
.get
()
.ok
()
{
if
let
NameBindingKind
::
Import
{
directive
,
..
}
=
result
.kind
{
// Skip canaries that resolve to the import itself.
// These come from `use crate_name;`, which isn't really
// ambiguous, as the import can't actually shadow itself.
if
directive
.id
==
import
.id
{
return
;
}
}
if
has_explicit_self
{
if
has_explicit_self
{
// There should only be one `self::x` (module-scoped) canary.
// There should only be one `self::x` (module-scoped) canary.
assert_eq!
(
canary_results
[
ns
]
.module_scope
,
None
);
assert_eq!
(
canary_results
[
ns
]
.module_scope
,
None
);
...
@@ -718,22 +726,6 @@ struct UniformPathsCanaryResult {
...
@@ -718,22 +726,6 @@ struct UniformPathsCanaryResult {
errors
=
true
;
errors
=
true
;
// Special-case the error when `self::x` finds its own `use x;`.
if
has_external_crate
&&
results
.module_scope
==
Some
(
span
)
&&
results
.block_scopes
.is_empty
()
{
let
msg
=
format!
(
"`{}` import is redundant"
,
name
);
this
.session
.struct_span_err
(
span
,
&
msg
)
.span_label
(
span
,
format!
(
"refers to external crate `::{}`"
,
name
))
.span_label
(
span
,
format!
(
"defines `self::{}`, shadowing itself"
,
name
))
.help
(
&
format!
(
"remove or write `::{}` explicitly instead"
,
name
))
.note
(
"relative `use` paths enabled by `#![feature(uniform_paths)]`"
)
.emit
();
return
;
}
let
msg
=
format!
(
"`{}` import is ambiguous"
,
name
);
let
msg
=
format!
(
"`{}` import is ambiguous"
,
name
);
let
mut
err
=
this
.session
.struct_span_err
(
span
,
&
msg
);
let
mut
err
=
this
.session
.struct_span_err
(
span
,
&
msg
);
let
mut
suggestion_choices
=
String
::
new
();
let
mut
suggestion_choices
=
String
::
new
();
...
...
src/test/
ui/rust-2018/uniform-path
s/redundant.rs
→
src/test/
run-pas
s/redundant.rs
浏览文件 @
31fce914
...
@@ -14,4 +14,16 @@
...
@@ -14,4 +14,16 @@
use
std
;
use
std
;
fn
main
()
{}
mod
foo
{
pub
use
std
as
my_std
;
}
mod
bar
{
pub
use
std
::{
self
};
}
fn
main
()
{
self
::
std
::
io
::
stdout
();
foo
::
my_std
::
io
::
stdout
();
bar
::
std
::
io
::
stdout
();
}
src/test/ui/rust-2018/uniform-paths/redundant.stderr
已删除
100644 → 0
浏览文件 @
35a5541f
error: `std` import is redundant
--> $DIR/redundant.rs:15:5
|
LL | use std;
| ^^^
| |
| refers to external crate `::std`
| defines `self::std`, shadowing itself
|
= help: remove or write `::std` explicitly instead
= note: relative `use` paths enabled by `#![feature(uniform_paths)]`
error: aborting due to previous error
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录