Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
59464709
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,发现更多精彩内容 >>
提交
59464709
编写于
11月 17, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve: Refactor away `DeterminacyExt`
上级
a5f9bd02
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
40 deletion
+27
-40
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+4
-14
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+5
-4
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+18
-22
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
59464709
...
...
@@ -97,19 +97,9 @@ fn is_known_tool(name: Name) -> bool {
[
"clippy"
,
"rustfmt"
]
.contains
(
&&*
name
.as_str
())
}
enum
DeterminacyExt
{
Determined
,
Undetermined
,
WeakUndetermined
,
}
impl
DeterminacyExt
{
fn
to_determinacy
(
self
)
->
Determinacy
{
match
self
{
DeterminacyExt
::
Determined
=>
Determined
,
DeterminacyExt
::
Undetermined
|
DeterminacyExt
::
WeakUndetermined
=>
Undetermined
,
}
}
enum
Weak
{
Yes
,
No
,
}
/// A free importable items suggested in case of resolution failure.
...
...
@@ -2223,7 +2213,7 @@ fn resolve_ident_in_module(
}
let
result
=
self
.resolve_ident_in_module_unadjusted_ext
(
module
,
ident
,
ns
,
parent_scope
,
false
,
record_used
,
path_span
,
)
.map_err
(
DeterminacyExt
::
to_
determinacy
);
)
.map_err
(
|(
determinacy
,
_
)|
determinacy
);
self
.current_module
=
orig_current_module
;
result
}
...
...
src/librustc_resolve/macros.rs
浏览文件 @
59464709
...
...
@@ -9,7 +9,7 @@
// except according to those terms.
use
{
AmbiguityError
,
AmbiguityKind
,
AmbiguityErrorMisc
};
use
{
CrateLint
,
DeterminacyExt
,
Resolver
,
ResolutionError
};
use
{
CrateLint
,
Resolver
,
ResolutionError
,
Weak
};
use
{
Module
,
ModuleKind
,
NameBinding
,
NameBindingKind
,
PathResult
,
ToNameBinding
};
use
{
is_known_tool
,
names_to_string
,
resolve_error
};
use
ModuleOrUniformRoot
;
...
...
@@ -688,10 +688,11 @@ struct Flags: u8 {
};
Ok
((
binding
,
Flags
::
MODULE
|
misc_flags
))
}
Err
(
DeterminacyExt
::
Undetermined
)
=>
Err
(
(
Determinacy
::
Undetermined
,
Weak
::
No
)
)
=>
return
Err
(
Determinacy
::
determined
(
force
)),
Err
(
DeterminacyExt
::
WeakUndetermined
)
=>
Err
(
Determinacy
::
Undetermined
),
Err
(
DeterminacyExt
::
Determined
)
=>
Err
(
Determinacy
::
Determined
),
Err
((
Determinacy
::
Undetermined
,
Weak
::
Yes
))
=>
Err
(
Determinacy
::
Undetermined
),
Err
((
Determinacy
::
Determined
,
_
))
=>
Err
(
Determinacy
::
Determined
),
}
}
WhereToResolve
::
MacroUsePrelude
=>
{
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
59464709
...
...
@@ -11,7 +11,7 @@
use
self
::
ImportDirectiveSubclass
::
*
;
use
{
AmbiguityError
,
AmbiguityKind
,
AmbiguityErrorMisc
};
use
{
CrateLint
,
DeterminacyExt
,
Module
,
ModuleOrUniformRoot
,
PerNS
,
UniformRootKind
};
use
{
CrateLint
,
Module
,
ModuleOrUniformRoot
,
PerNS
,
UniformRootKind
,
Weak
};
use
Namespace
::{
self
,
TypeNS
,
MacroNS
};
use
{
NameBinding
,
NameBindingKind
,
ToNameBinding
,
PathResult
,
PrivacyError
};
use
{
Resolver
,
Segment
};
...
...
@@ -145,7 +145,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
)
->
Result
<&
'a
NameBinding
<
'a
>
,
Determinacy
>
{
self
.resolve_ident_in_module_unadjusted_ext
(
module
,
ident
,
ns
,
None
,
false
,
record_used
,
path_span
)
.map_err
(
DeterminacyExt
::
to_
determinacy
)
)
.map_err
(
|(
determinacy
,
_
)|
determinacy
)
}
/// Attempts to resolve `ident` in namespaces `ns` of `module`.
...
...
@@ -159,7 +159,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
restricted_shadowing
:
bool
,
record_used
:
bool
,
path_span
:
Span
,
)
->
Result
<&
'a
NameBinding
<
'a
>
,
DeterminacyExt
>
{
)
->
Result
<&
'a
NameBinding
<
'a
>
,
(
Determinacy
,
Weak
)
>
{
let
module
=
match
module
{
ModuleOrUniformRoot
::
Module
(
module
)
=>
module
,
ModuleOrUniformRoot
::
UniformRoot
(
uniform_root_kind
)
=>
{
...
...
@@ -171,9 +171,9 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
Ok
(
binding
)
}
else
if
!
self
.graph_root.unresolved_invocations
.borrow
()
.is_empty
()
{
// Macro-expanded `extern crate` items can add names to extern prelude.
Err
(
DeterminacyExt
::
Undetermined
)
Err
(
(
Undetermined
,
Weak
::
No
)
)
}
else
{
Err
(
DeterminacyExt
::
Determined
)
Err
(
(
Determined
,
Weak
::
No
)
)
}
}
UniformRootKind
::
CurrentScope
=>
{
...
...
@@ -198,10 +198,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
let
binding
=
self
.early_resolve_ident_in_lexical_scope
(
ident
,
ns
,
None
,
true
,
parent_scope
,
record_used
,
record_used
,
path_span
);
return
binding
.map_err
(|
determinacy
|
match
determinacy
{
Determined
=>
DeterminacyExt
::
Determined
,
Undetermined
=>
DeterminacyExt
::
Undetermined
,
});
return
binding
.map_err
(|
determinacy
|
(
determinacy
,
Weak
::
No
));
}
}
}
...
...
@@ -211,8 +208,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
let
resolution
=
self
.resolution
(
module
,
ident
,
ns
)
.try_borrow_mut
()
// This happens when there is a cycle of imports.
.map_err
(|
_
|
DeterminacyExt
::
Determined
)
?
;
.map_err
(|
_
|
(
Determined
,
Weak
::
No
))
?
;
// This happens when there is a cycle of imports.
if
let
Some
(
binding
)
=
resolution
.binding
{
if
!
restricted_shadowing
&&
binding
.expansion
!=
Mark
::
root
()
{
...
...
@@ -226,13 +222,13 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
// `extern crate` are always usable for backwards compatibility, see issue #37020,
// remove this together with `PUB_USE_OF_PRIVATE_EXTERN_CRATE`.
let
usable
=
this
.is_accessible
(
binding
.vis
)
||
binding
.is_extern_crate
();
if
usable
{
Ok
(
binding
)
}
else
{
Err
(
DeterminacyExt
::
Determined
)
}
if
usable
{
Ok
(
binding
)
}
else
{
Err
(
(
Determined
,
Weak
::
No
)
)
}
};
if
record_used
{
return
resolution
.binding
.ok_or
(
DeterminacyExt
::
Determined
)
.and_then
(|
binding
|
{
return
resolution
.binding
.ok_or
(
(
Determined
,
Weak
::
No
)
)
.and_then
(|
binding
|
{
if
self
.last_import_segment
&&
check_usable
(
self
,
binding
)
.is_err
()
{
Err
(
DeterminacyExt
::
Determined
)
Err
(
(
Determined
,
Weak
::
No
)
)
}
else
{
self
.record_use
(
ident
,
ns
,
binding
,
restricted_shadowing
);
...
...
@@ -279,7 +275,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
continue
;
}
let
module
=
unwrap_or!
(
single_import
.imported_module
.get
(),
return
Err
(
DeterminacyExt
::
Undetermined
));
return
Err
(
(
Undetermined
,
Weak
::
No
)
));
let
ident
=
match
single_import
.subclass
{
SingleImport
{
source
,
..
}
=>
source
,
_
=>
unreachable!
(),
...
...
@@ -290,7 +286,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
Ok
(
binding
)
if
!
self
.is_accessible_from
(
binding
.vis
,
single_import
.parent_scope.module
)
=>
continue
,
Ok
(
_
)
|
Err
(
Undetermined
)
=>
return
Err
(
DeterminacyExt
::
Undetermined
),
Ok
(
_
)
|
Err
(
Undetermined
)
=>
return
Err
(
(
Undetermined
,
Weak
::
No
)
),
}
}
...
...
@@ -311,7 +307,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
if
!
unexpanded_macros
||
ns
==
MacroNS
||
restricted_shadowing
{
return
check_usable
(
self
,
binding
);
}
else
{
return
Err
(
DeterminacyExt
::
Undetermined
);
return
Err
(
(
Undetermined
,
Weak
::
No
)
);
}
}
...
...
@@ -321,12 +317,12 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
// expansion. With restricted shadowing names from globs and macro expansions cannot
// shadow names from outer scopes, so we can freely fallback from module search to search
// in outer scopes. For `early_resolve_ident_in_lexical_scope` to continue search in outer
// scopes we return `
WeakUndetermined` instead of full `Undetermined
`.
// scopes we return `
Undetermined` with `Weak::Yes
`.
// Check if one of unexpanded macros can still define the name,
// if it can then our "no resolution" result is not determined and can be invalidated.
if
unexpanded_macros
{
return
Err
(
DeterminacyExt
::
WeakUndetermined
);
return
Err
(
(
Undetermined
,
Weak
::
Yes
)
);
}
// Check if one of glob imports can still define the name,
...
...
@@ -338,7 +334,7 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
let
module
=
match
glob_import
.imported_module
.get
()
{
Some
(
ModuleOrUniformRoot
::
Module
(
module
))
=>
module
,
Some
(
ModuleOrUniformRoot
::
UniformRoot
(
_
))
=>
continue
,
None
=>
return
Err
(
DeterminacyExt
::
WeakUndetermined
),
None
=>
return
Err
(
(
Undetermined
,
Weak
::
Yes
)
),
};
let
(
orig_current_module
,
mut
ident
)
=
(
self
.current_module
,
ident
.modern
());
match
ident
.span
.glob_adjust
(
module
.expansion
,
glob_import
.span
.ctxt
()
.modern
())
{
...
...
@@ -360,12 +356,12 @@ fn resolution(&self, module: Module<'a>, ident: Ident, ns: Namespace)
Ok
(
binding
)
if
!
self
.is_accessible_from
(
binding
.vis
,
glob_import
.parent_scope.module
)
=>
continue
,
Ok
(
_
)
|
Err
(
Undetermined
)
=>
return
Err
(
DeterminacyExt
::
WeakUndetermined
),
Ok
(
_
)
|
Err
(
Undetermined
)
=>
return
Err
(
(
Undetermined
,
Weak
::
Yes
)
),
}
}
// No resolution and no one else can define the name - determinate error.
Err
(
DeterminacyExt
::
Determined
)
Err
(
(
Determined
,
Weak
::
No
)
)
}
// Add an import directive to the current module.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录