Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
be2bb808
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
be2bb808
编写于
5月 22, 2018
作者:
N
Niko Matsakis
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
thread info about `CrateLint` through more deeply
上级
e9e8514c
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
63 addition
and
15 deletion
+63
-15
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+63
-15
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
be2bb808
...
...
@@ -2247,7 +2247,13 @@ fn resolve_use_tree(&mut self, id: NodeId, use_tree: &ast::UseTree, prefix: &Pat
if
items
.len
()
==
0
{
// Resolve prefix of an import with empty braces (issue #28388).
self
.smart_resolve_path
(
id
,
None
,
&
path
,
PathSource
::
ImportPrefix
);
self
.smart_resolve_path_with_crate_lint
(
id
,
None
,
&
path
,
PathSource
::
ImportPrefix
,
CrateLint
::
SimplePath
(
id
),
// TODO seems wrong
);
}
else
{
for
&
(
ref
tree
,
nested_id
)
in
items
{
self
.resolve_use_tree
(
nested_id
,
tree
,
&
path
);
...
...
@@ -2354,7 +2360,8 @@ fn with_optional_trait_ref<T, F>(&mut self, opt_trait_ref: Option<&TraitRef>, f:
None
,
&
path
,
trait_ref
.path.span
,
PathSource
::
Trait
(
AliasPossibility
::
No
)
PathSource
::
Trait
(
AliasPossibility
::
No
),
CrateLint
::
SimplePath
(
trait_ref
.ref_id
),
)
.base_def
();
if
def
!=
Def
::
Err
{
new_id
=
Some
(
def
.def_id
());
...
...
@@ -2787,10 +2794,29 @@ fn smart_resolve_path(&mut self,
path
:
&
Path
,
source
:
PathSource
)
->
PathResolution
{
self
.smart_resolve_path_with_crate_lint
(
id
,
qself
,
path
,
source
,
CrateLint
::
SimplePath
(
id
))
}
/// A variant of `smart_resolve_path` where you also specify extra
/// information about where the path came from; this extra info is
/// sometimes needed for the lint that recommends rewriting
/// absoluate paths to `crate`, so that it knows how to frame the
/// suggestion. If you are just resolving a path like `foo::bar`
/// that appears...somewhere, though, then you just want
/// `CrateLint::SimplePath`, which is what `smart_resolve_path`
/// already provides.
fn
smart_resolve_path_with_crate_lint
(
&
mut
self
,
id
:
NodeId
,
qself
:
Option
<&
QSelf
>
,
path
:
&
Path
,
source
:
PathSource
,
crate_lint
:
CrateLint
)
->
PathResolution
{
let
segments
=
&
path
.segments
.iter
()
.map
(|
seg
|
seg
.ident
)
.collect
::
<
Vec
<
_
>>
();
self
.smart_resolve_path_fragment
(
id
,
qself
,
segments
,
path
.span
,
source
)
self
.smart_resolve_path_fragment
(
id
,
qself
,
segments
,
path
.span
,
source
,
crate_lint
)
}
fn
smart_resolve_path_fragment
(
&
mut
self
,
...
...
@@ -2798,7 +2824,8 @@ fn smart_resolve_path_fragment(&mut self,
qself
:
Option
<&
QSelf
>
,
path
:
&
[
Ident
],
span
:
Span
,
source
:
PathSource
)
source
:
PathSource
,
crate_lint
:
CrateLint
)
->
PathResolution
{
let
ident_span
=
path
.last
()
.map_or
(
span
,
|
ident
|
ident
.span
);
let
ns
=
source
.namespace
();
...
...
@@ -2999,9 +3026,16 @@ fn smart_resolve_path_fragment(&mut self,
err_path_resolution
()
};
let
resolution
=
match
self
.resolve_qpath_anywhere
(
id
,
qself
,
path
,
ns
,
span
,
source
.defer_to_typeck
(),
source
.global_by_default
())
{
let
resolution
=
match
self
.resolve_qpath_anywhere
(
id
,
qself
,
path
,
ns
,
span
,
source
.defer_to_typeck
(),
source
.global_by_default
(),
crate_lint
,
)
{
Some
(
resolution
)
if
resolution
.unresolved_segments
()
==
0
=>
{
if
is_expected
(
resolution
.base_def
())
||
resolution
.base_def
()
==
Def
::
Err
{
resolution
...
...
@@ -3102,14 +3136,15 @@ fn resolve_qpath_anywhere(&mut self,
primary_ns
:
Namespace
,
span
:
Span
,
defer_to_typeck
:
bool
,
global_by_default
:
bool
)
global_by_default
:
bool
,
crate_lint
:
CrateLint
)
->
Option
<
PathResolution
>
{
let
mut
fin_res
=
None
;
// FIXME: can't resolve paths in macro namespace yet, macros are
// processed by the little special hack below.
for
(
i
,
ns
)
in
[
primary_ns
,
TypeNS
,
ValueNS
,
/*MacroNS*/
]
.iter
()
.cloned
()
.enumerate
()
{
if
i
==
0
||
ns
!=
primary_ns
{
match
self
.resolve_qpath
(
id
,
qself
,
path
,
ns
,
span
,
global_by_default
)
{
match
self
.resolve_qpath
(
id
,
qself
,
path
,
ns
,
span
,
global_by_default
,
crate_lint
)
{
// If defer_to_typeck, then resolution > no resolution,
// otherwise full resolution > partial resolution > no resolution.
Some
(
res
)
if
res
.unresolved_segments
()
==
0
||
defer_to_typeck
=>
...
...
@@ -3137,7 +3172,8 @@ fn resolve_qpath(&mut self,
path
:
&
[
Ident
],
ns
:
Namespace
,
span
:
Span
,
global_by_default
:
bool
)
global_by_default
:
bool
,
crate_lint
:
CrateLint
)
->
Option
<
PathResolution
>
{
debug!
(
"resolve_qpath(id={:?}, qself={:?}, path={:?},
\
...
...
@@ -3159,8 +3195,14 @@ fn resolve_qpath(&mut self,
}
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
let
ns
=
if
qself
.position
+
1
==
path
.len
()
{
ns
}
else
{
TypeNS
};
let
res
=
self
.smart_resolve_path_fragment
(
id
,
None
,
&
path
[
..
qself
.position
+
1
],
span
,
PathSource
::
TraitItem
(
ns
));
let
res
=
self
.smart_resolve_path_fragment
(
id
,
None
,
&
path
[
..
qself
.position
+
1
],
span
,
PathSource
::
TraitItem
(
ns
),
crate_lint
,
// TODO wrong
);
return
Some
(
PathResolution
::
with_unresolved_segments
(
res
.base_def
(),
res
.unresolved_segments
()
+
path
.len
()
-
qself
.position
-
1
));
...
...
@@ -4113,8 +4155,14 @@ fn resolve_visibility(&mut self, vis: &ast::Visibility) -> ty::Visibility {
let
segments
=
path
.make_root
()
.iter
()
.chain
(
path
.segments
.iter
())
.map
(|
seg
|
seg
.ident
)
.collect
::
<
Vec
<
_
>>
();
let
def
=
self
.smart_resolve_path_fragment
(
id
,
None
,
&
segments
,
path
.span
,
PathSource
::
Visibility
)
.base_def
();
let
def
=
self
.smart_resolve_path_fragment
(
id
,
None
,
&
segments
,
path
.span
,
PathSource
::
Visibility
,
CrateLint
::
SimplePath
(
id
),
)
.base_def
();
if
def
==
Def
::
Err
{
ty
::
Visibility
::
Public
}
else
{
...
...
@@ -4474,7 +4522,7 @@ pub enum MakeGlobMap {
No
,
}
#[derive(Debug)]
#[derive(
Copy,
Clone,
Debug)]
enum
CrateLint
{
/// Do not issue the lint
No
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录