Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7f3491c3
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,发现更多精彩内容 >>
提交
7f3491c3
编写于
3月 08, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix name resolution in lexical scopes
上级
8b7c3f20
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
26 addition
and
67 deletion
+26
-67
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+25
-65
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+1
-2
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
7f3491c3
...
...
@@ -1357,7 +1357,6 @@ fn search_parent_externals(needle: Name, module: Module) -> Option<Module> {
/// On success, returns the resolved module, and the closest *private*
/// module found to the destination when resolving this path.
fn
resolve_module_path
(
&
mut
self
,
module_
:
Module
<
'a
>
,
module_path
:
&
[
Name
],
use_lexical_scope
:
UseLexicalScopeFlag
,
span
:
Span
)
...
...
@@ -1368,10 +1367,10 @@ fn resolve_module_path(&mut self,
debug!
(
"(resolving module path for import) processing `{}` rooted at `{}`"
,
names_to_string
(
module_path
),
module_to_string
(
&
module_
));
module_to_string
(
self
.current_module
));
// Resolve the module prefix, if any.
let
module_prefix_result
=
self
.resolve_module_prefix
(
module_
,
module_
path
);
let
module_prefix_result
=
self
.resolve_module_prefix
(
module_path
);
let
search_module
;
let
start_index
;
...
...
@@ -1413,8 +1412,7 @@ fn resolve_module_path(&mut self,
// This is not a crate-relative path. We resolve the
// first component of the path in the current lexical
// scope and then proceed to resolve below that.
match
self
.resolve_item_in_lexical_scope
(
module_
,
module_path
[
0
],
match
self
.resolve_item_in_lexical_scope
(
module_path
[
0
],
TypeNS
,
true
)
{
Failed
(
err
)
=>
return
Failed
(
err
),
...
...
@@ -1448,61 +1446,30 @@ fn resolve_module_path(&mut self,
/// Invariant: This must only be called during main resolution, not during
/// import resolution.
fn
resolve_item_in_lexical_scope
(
&
mut
self
,
module_
:
Module
<
'a
>
,
name
:
Name
,
namespace
:
Namespace
,
record_used
:
bool
)
->
ResolveResult
<&
'a
NameBinding
<
'a
>>
{
debug!
(
"(resolving item in lexical scope) resolving `{}` in namespace {:?} in `{}`"
,
name
,
namespace
,
module_to_string
(
&
module_
));
// Proceed up the scope chain looking for parent modules.
let
mut
search_module
=
module_
;
loop
{
// Resolve the name in the parent module.
match
self
.resolve_name_in_module
(
search_module
,
name
,
namespace
,
true
,
record_used
)
{
Failed
(
Some
((
span
,
msg
)))
=>
{
resolve_error
(
self
,
span
,
ResolutionError
::
FailedToResolve
(
&
msg
));
}
Failed
(
None
)
=>
(),
// Continue up the search chain.
Indeterminate
=>
{
// We couldn't see through the higher scope because of an
// unresolved import higher up. Bail.
debug!
(
"(resolving item in lexical scope) indeterminate higher scope; bailing"
);
return
Indeterminate
;
}
Success
(
binding
)
=>
{
// We found the module.
debug!
(
"(resolving item in lexical scope) found name in module, done"
);
return
Success
(
binding
);
}
// Check the local set of ribs.
for
i
in
(
0
..
self
.get_ribs
(
namespace
)
.len
())
.rev
()
{
if
let
Some
(
_
)
=
self
.get_ribs
(
namespace
)[
i
]
.bindings
.get
(
&
name
)
.cloned
()
{
return
Failed
(
None
);
}
// Go to the next parent.
match
search_module
.parent_link
{
NoParentLink
=>
{
// No more parents. This module was unresolved.
debug!
(
"(resolving item in lexical scope) unresolved module: no parent module"
);
return
Failed
(
None
);
}
ModuleParentLink
(
parent_module_node
,
_
)
=>
{
if
search_module
.is_normal
()
{
// We stop the search here.
debug!
(
"(resolving item in lexical scope) unresolved module: not
\
searching through module parents"
);
return
Failed
(
None
);
}
else
{
search_module
=
parent_module_node
;
}
}
BlockParentLink
(
parent_module_node
,
_
)
=>
{
search_module
=
parent_module_node
;
if
let
ModuleRibKind
(
module
)
=
self
.get_ribs
(
namespace
)[
i
]
.kind
{
if
let
Success
(
binding
)
=
self
.resolve_name_in_module
(
module
,
name
,
namespace
,
true
,
record_used
)
{
return
Success
(
binding
);
}
// We can only see through anonymous modules
if
module
.def
.is_some
()
{
return
Failed
(
None
);
}
}
}
Failed
(
None
)
}
/// Returns the nearest normal module parent of the given module.
...
...
@@ -1538,9 +1505,7 @@ fn get_nearest_normal_module_parent_or_self(&mut self, module_: Module<'a>) -> M
/// Resolves a "module prefix". A module prefix is one or both of (a) `self::`;
/// (b) some chain of `super::`.
/// grammar: (SELF MOD_SEP ) ? (SUPER MOD_SEP) *
fn
resolve_module_prefix
(
&
mut
self
,
module_
:
Module
<
'a
>
,
module_path
:
&
[
Name
])
fn
resolve_module_prefix
(
&
mut
self
,
module_path
:
&
[
Name
])
->
ResolveResult
<
ModulePrefixResult
<
'a
>>
{
// Start at the current module if we see `self` or `super`, or at the
// top of the crate otherwise.
...
...
@@ -1549,6 +1514,7 @@ fn resolve_module_prefix(&mut self,
"super"
=>
0
,
_
=>
return
Success
(
NoPrefixFound
),
};
let
module_
=
self
.current_module
;
let
mut
containing_module
=
self
.get_nearest_normal_module_parent_or_self
(
module_
);
// Now loop through all the `super`s we find.
...
...
@@ -2594,8 +2560,7 @@ fn resolve_bare_identifier_pattern(&mut self,
name
:
Name
,
span
:
Span
)
->
BareIdentifierPatternResolution
{
let
module
=
self
.current_module
;
match
self
.resolve_item_in_lexical_scope
(
module
,
name
,
ValueNS
,
true
)
{
match
self
.resolve_item_in_lexical_scope
(
name
,
ValueNS
,
true
)
{
Success
(
binding
)
=>
{
debug!
(
"(resolve bare identifier pattern) succeeded in finding {} at {:?}"
,
name
,
...
...
@@ -2754,9 +2719,8 @@ fn resolve_identifier(&mut self,
}
// Check the items.
let
module
=
self
.current_module
;
let
name
=
identifier
.unhygienic_name
;
match
self
.resolve_item_in_lexical_scope
(
module
,
name
,
namespace
,
record_used
)
{
match
self
.resolve_item_in_lexical_scope
(
name
,
namespace
,
record_used
)
{
Success
(
binding
)
=>
binding
.def
()
.map
(
LocalDef
::
from_def
),
Failed
(
Some
((
span
,
msg
)))
=>
{
resolve_error
(
self
,
span
,
ResolutionError
::
FailedToResolve
(
&
msg
));
...
...
@@ -2869,8 +2833,7 @@ fn resolve_module_relative_path(&mut self,
.collect
::
<
Vec
<
_
>>
();
let
containing_module
;
let
current_module
=
self
.current_module
;
match
self
.resolve_module_path
(
current_module
,
&
module_path
,
UseLexicalScope
,
span
)
{
match
self
.resolve_module_path
(
&
module_path
,
UseLexicalScope
,
span
)
{
Failed
(
err
)
=>
{
let
(
span
,
msg
)
=
match
err
{
Some
((
span
,
msg
))
=>
(
span
,
msg
),
...
...
@@ -3024,7 +2987,6 @@ fn get_module<'a, 'tcx>(this: &mut Resolver<'a, 'tcx>,
span
:
Span
,
name_path
:
&
[
ast
::
Name
])
->
Option
<
Module
<
'a
>>
{
let
root
=
this
.current_module
;
let
last_name
=
name_path
.last
()
.unwrap
();
if
name_path
.len
()
==
1
{
...
...
@@ -3034,7 +2996,7 @@ fn get_module<'a, 'tcx>(this: &mut Resolver<'a, 'tcx>,
.and_then
(
NameBinding
::
module
)
}
}
else
{
this
.resolve_module_path
(
root
,
&
name_path
,
UseLexicalScope
,
span
)
.success
()
this
.resolve_module_path
(
&
name_path
,
UseLexicalScope
,
span
)
.success
()
}
}
...
...
@@ -3274,10 +3236,8 @@ fn resolve_expr(&mut self, expr: &Expr) {
let
name_path
=
path
.segments
.iter
()
.map
(|
seg
|
seg
.identifier.name
)
.collect
::
<
Vec
<
_
>>
();
let
current_module
=
self
.current_module
;
match
self
.resolve_module_path
(
current_module
,
&
name_path
[
..
],
match
self
.resolve_module_path
(
&
name_path
[
..
],
UseLexicalScope
,
expr
.span
)
{
Success
(
_
)
=>
{
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
7f3491c3
...
...
@@ -427,8 +427,7 @@ fn resolve_import_for_module(&mut self,
module_to_string
(
&
module_
));
self
.resolver
.resolve_module_path
(
module_
,
&
import_directive
.module_path
,
.resolve_module_path
(
&
import_directive
.module_path
,
UseLexicalScopeFlag
::
DontUseLexicalScope
,
import_directive
.span
)
.and_then
(|
containing_module
|
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录