Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
24b37a73
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,发现更多精彩内容 >>
提交
24b37a73
编写于
4月 08, 2022
作者:
C
Camille GILLOT
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Pass last_import_segment and unusable_binding as parameters.
上级
eb7f5673
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
177 addition
and
79 deletion
+177
-79
compiler/rustc_resolve/src/build_reduced_graph.rs
compiler/rustc_resolve/src/build_reduced_graph.rs
+2
-2
compiler/rustc_resolve/src/diagnostics.rs
compiler/rustc_resolve/src/diagnostics.rs
+7
-5
compiler/rustc_resolve/src/ident.rs
compiler/rustc_resolve/src/ident.rs
+102
-9
compiler/rustc_resolve/src/imports.rs
compiler/rustc_resolve/src/imports.rs
+18
-20
compiler/rustc_resolve/src/late.rs
compiler/rustc_resolve/src/late.rs
+36
-21
compiler/rustc_resolve/src/late/diagnostics.rs
compiler/rustc_resolve/src/late/diagnostics.rs
+1
-2
compiler/rustc_resolve/src/lib.rs
compiler/rustc_resolve/src/lib.rs
+2
-18
compiler/rustc_resolve/src/macros.rs
compiler/rustc_resolve/src/macros.rs
+9
-2
未找到文件。
compiler/rustc_resolve/src/build_reduced_graph.rs
浏览文件 @
24b37a73
...
...
@@ -297,6 +297,7 @@ fn try_resolve_visibility<'ast>(
Some
(
TypeNS
),
parent_scope
,
if
finalize
{
Finalize
::
SimplePath
(
id
,
path
.span
)
}
else
{
Finalize
::
No
},
None
,
)
{
PathResult
::
Module
(
ModuleOrUniformRoot
::
Module
(
module
))
=>
{
let
res
=
module
.res
()
.expect
(
"visibility resolved to unnamed block"
);
...
...
@@ -1124,12 +1125,11 @@ fn process_macro_use_imports(&mut self, item: &Item, module: Module<'a>) -> bool
});
}
else
{
for
ident
in
single_imports
.iter
()
.cloned
()
{
let
result
=
self
.r
.resolve_ident_in_module
(
let
result
=
self
.r
.
maybe_
resolve_ident_in_module
(
ModuleOrUniformRoot
::
Module
(
module
),
ident
,
MacroNS
,
&
self
.parent_scope
,
None
,
);
if
let
Ok
(
binding
)
=
result
{
let
import
=
macro_use_import
(
self
,
ident
.span
);
...
...
compiler/rustc_resolve/src/diagnostics.rs
浏览文件 @
24b37a73
...
...
@@ -25,7 +25,7 @@
use
crate
::
path_names_to_string
;
use
crate
::{
AmbiguityError
,
AmbiguityErrorMisc
,
AmbiguityKind
};
use
crate
::{
BindingError
,
HasGenericParams
,
MacroRulesScope
,
Module
,
ModuleOrUniformRoot
};
use
crate
::{
Finalize
,
NameBinding
,
NameBindingKind
,
PrivacyError
,
VisResolutionError
};
use
crate
::{
NameBinding
,
NameBindingKind
,
PrivacyError
,
VisResolutionError
};
use
crate
::{
ParentScope
,
PathResult
,
ResolutionError
,
Resolver
,
Scope
,
ScopeSet
,
Segment
};
type
Res
=
def
::
Res
<
ast
::
NodeId
>
;
...
...
@@ -1076,6 +1076,8 @@ fn lookup_import_candidates_from_module<FilterFn>(
&
parent_scope
,
None
,
false
,
false
,
None
,
)
{
let
desc
=
match
binding
.res
()
{
Res
::
Def
(
DefKind
::
Macro
(
MacroKind
::
Bang
),
_
)
=>
{
...
...
@@ -1422,7 +1424,7 @@ fn make_missing_self_suggestion(
)
->
Option
<
(
Vec
<
Segment
>
,
Vec
<
String
>
)
>
{
// Replace first ident with `self` and check if that is valid.
path
[
0
]
.ident.name
=
kw
::
SelfLower
;
let
result
=
self
.r
.
resolve_path
(
&
path
,
None
,
parent_scope
,
Finalize
::
No
);
let
result
=
self
.r
.
maybe_resolve_path
(
&
path
,
None
,
parent_scope
);
debug!
(
"make_missing_self_suggestion: path={:?} result={:?}"
,
path
,
result
);
if
let
PathResult
::
Module
(
..
)
=
result
{
Some
((
path
,
Vec
::
new
()))
}
else
{
None
}
}
...
...
@@ -1441,7 +1443,7 @@ fn make_missing_crate_suggestion(
)
->
Option
<
(
Vec
<
Segment
>
,
Vec
<
String
>
)
>
{
// Replace first ident with `crate` and check if that is valid.
path
[
0
]
.ident.name
=
kw
::
Crate
;
let
result
=
self
.r
.
resolve_path
(
&
path
,
None
,
parent_scope
,
Finalize
::
No
);
let
result
=
self
.r
.
maybe_resolve_path
(
&
path
,
None
,
parent_scope
);
debug!
(
"make_missing_crate_suggestion: path={:?} result={:?}"
,
path
,
result
);
if
let
PathResult
::
Module
(
..
)
=
result
{
Some
((
...
...
@@ -1472,7 +1474,7 @@ fn make_missing_super_suggestion(
)
->
Option
<
(
Vec
<
Segment
>
,
Vec
<
String
>
)
>
{
// Replace first ident with `crate` and check if that is valid.
path
[
0
]
.ident.name
=
kw
::
Super
;
let
result
=
self
.r
.
resolve_path
(
&
path
,
None
,
parent_scope
,
Finalize
::
No
);
let
result
=
self
.r
.
maybe_resolve_path
(
&
path
,
None
,
parent_scope
);
debug!
(
"make_missing_super_suggestion: path={:?} result={:?}"
,
path
,
result
);
if
let
PathResult
::
Module
(
..
)
=
result
{
Some
((
path
,
Vec
::
new
()))
}
else
{
None
}
}
...
...
@@ -1506,7 +1508,7 @@ fn make_external_crate_suggestion(
for
name
in
extern_crate_names
.into_iter
()
{
// Replace first ident with a crate name and check if that is valid.
path
[
0
]
.ident.name
=
name
;
let
result
=
self
.r
.
resolve_path
(
&
path
,
None
,
parent_scope
,
Finalize
::
No
);
let
result
=
self
.r
.
maybe_resolve_path
(
&
path
,
None
,
parent_scope
);
debug!
(
"make_external_crate_suggestion: name={:?} path={:?} result={:?}"
,
name
,
path
,
result
...
...
compiler/rustc_resolve/src/ident.rs
浏览文件 @
24b37a73
...
...
@@ -280,6 +280,7 @@ fn hygienic_lexical_parent(
///
/// Invariant: This must only be called during main resolution, not during
/// import resolution.
#[tracing::instrument(level
=
"debug"
,
skip(self,
ribs))]
crate
fn
resolve_ident_in_lexical_scope
(
&
mut
self
,
mut
ident
:
Ident
,
...
...
@@ -287,6 +288,7 @@ fn hygienic_lexical_parent(
parent_scope
:
&
ParentScope
<
'a
>
,
finalize_full
:
Finalize
,
ribs
:
&
[
Rib
<
'a
>
],
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
Option
<
LexicalScopeBinding
<
'a
>>
{
assert
!
(
ns
==
TypeNS
||
ns
==
ValueNS
);
let
orig_ident
=
ident
;
...
...
@@ -349,6 +351,8 @@ fn hygienic_lexical_parent(
ns
,
parent_scope
,
finalize
,
false
,
unusable_binding
,
);
if
let
Ok
(
binding
)
=
item
{
// The ident resolves to an item.
...
...
@@ -361,6 +365,8 @@ fn hygienic_lexical_parent(
parent_scope
,
finalize
,
finalize
.is_some
(),
false
,
unusable_binding
,
)
.ok
()
.map
(
LexicalScopeBinding
::
Item
)
...
...
@@ -371,6 +377,7 @@ fn hygienic_lexical_parent(
/// expansion and import resolution (perhaps they can be merged in the future).
/// The function is used for resolving initial segments of macro paths (e.g., `foo` in
/// `foo::bar!(); or `foo!();`) and also for import paths on 2018 edition.
#[tracing::instrument(level
=
"debug"
,
skip(self,
scope_set))]
crate
fn
early_resolve_ident_in_lexical_scope
(
&
mut
self
,
orig_ident
:
Ident
,
...
...
@@ -378,6 +385,8 @@ fn hygienic_lexical_parent(
parent_scope
:
&
ParentScope
<
'a
>
,
finalize
:
Option
<
Span
>
,
force
:
bool
,
last_import_segment
:
bool
,
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
Result
<&
'a
NameBinding
<
'a
>
,
Determinacy
>
{
bitflags
::
bitflags!
{
struct
Flags
:
u8
{
...
...
@@ -497,6 +506,8 @@ struct Flags: u8 {
ns
,
parent_scope
,
finalize
,
last_import_segment
,
unusable_binding
,
);
match
binding
{
Ok
(
binding
)
=>
Ok
((
binding
,
Flags
::
MODULE
|
Flags
::
MISC_SUGGEST_CRATE
)),
...
...
@@ -518,6 +529,8 @@ struct Flags: u8 {
adjusted_parent_scope
,
!
matches!
(
scope_set
,
ScopeSet
::
Late
(
..
)),
finalize
,
last_import_segment
,
unusable_binding
,
);
match
binding
{
Ok
(
binding
)
=>
{
...
...
@@ -602,6 +615,8 @@ struct Flags: u8 {
ns
,
parent_scope
,
None
,
last_import_segment
,
unusable_binding
,
)
{
if
use_prelude
||
this
.is_builtin_macro
(
binding
.res
())
{
result
=
Ok
((
binding
,
Flags
::
MISC_FROM_PRELUDE
));
...
...
@@ -715,6 +730,19 @@ struct Flags: u8 {
Err
(
Determinacy
::
determined
(
determinacy
==
Determinacy
::
Determined
||
force
))
}
#[tracing::instrument(level
=
"debug"
,
skip(self))]
crate
fn
maybe_resolve_ident_in_module
(
&
mut
self
,
module
:
ModuleOrUniformRoot
<
'a
>
,
ident
:
Ident
,
ns
:
Namespace
,
parent_scope
:
&
ParentScope
<
'a
>
,
)
->
Result
<&
'a
NameBinding
<
'a
>
,
Determinacy
>
{
self
.resolve_ident_in_module_ext
(
module
,
ident
,
ns
,
parent_scope
,
None
,
false
,
None
)
.map_err
(|(
determinacy
,
_
)|
determinacy
)
}
#[tracing::instrument(level
=
"debug"
,
skip(self))]
crate
fn
resolve_ident_in_module
(
&
mut
self
,
module
:
ModuleOrUniformRoot
<
'a
>
,
...
...
@@ -722,11 +750,25 @@ struct Flags: u8 {
ns
:
Namespace
,
parent_scope
:
&
ParentScope
<
'a
>
,
finalize
:
Option
<
Span
>
,
// We are resolving a last import segment during import validation.
last_import_segment
:
bool
,
// This binding should be ignored during in-module resolution, so that we don't get
// "self-confirming" import resolutions during import validation.
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
Result
<&
'a
NameBinding
<
'a
>
,
Determinacy
>
{
self
.resolve_ident_in_module_ext
(
module
,
ident
,
ns
,
parent_scope
,
finalize
)
.map_err
(|(
determinacy
,
_
)|
determinacy
)
self
.resolve_ident_in_module_ext
(
module
,
ident
,
ns
,
parent_scope
,
finalize
,
last_import_segment
,
unusable_binding
,
)
.map_err
(|(
determinacy
,
_
)|
determinacy
)
}
#[tracing::instrument(level
=
"debug"
,
skip(self))]
fn
resolve_ident_in_module_ext
(
&
mut
self
,
module
:
ModuleOrUniformRoot
<
'a
>
,
...
...
@@ -734,6 +776,8 @@ fn resolve_ident_in_module_ext(
ns
:
Namespace
,
parent_scope
:
&
ParentScope
<
'a
>
,
finalize
:
Option
<
Span
>
,
last_import_segment
:
bool
,
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
Result
<&
'a
NameBinding
<
'a
>
,
(
Determinacy
,
Weak
)
>
{
let
tmp_parent_scope
;
let
mut
adjusted_parent_scope
=
parent_scope
;
...
...
@@ -759,9 +803,12 @@ fn resolve_ident_in_module_ext(
adjusted_parent_scope
,
false
,
finalize
,
last_import_segment
,
unusable_binding
,
)
}
#[tracing::instrument(level
=
"debug"
,
skip(self))]
fn
resolve_ident_in_module_unadjusted
(
&
mut
self
,
module
:
ModuleOrUniformRoot
<
'a
>
,
...
...
@@ -769,6 +816,8 @@ fn resolve_ident_in_module_unadjusted(
ns
:
Namespace
,
parent_scope
:
&
ParentScope
<
'a
>
,
finalize
:
Option
<
Span
>
,
last_import_segment
:
bool
,
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
Result
<&
'a
NameBinding
<
'a
>
,
Determinacy
>
{
self
.resolve_ident_in_module_unadjusted_ext
(
module
,
...
...
@@ -777,12 +826,15 @@ fn resolve_ident_in_module_unadjusted(
parent_scope
,
false
,
finalize
,
last_import_segment
,
unusable_binding
,
)
.map_err
(|(
determinacy
,
_
)|
determinacy
)
}
/// Attempts to resolve `ident` in namespaces `ns` of `module`.
/// Invariant: if `finalize` is `Some`, expansion and import resolution must be complete.
#[tracing::instrument(level
=
"debug"
,
skip(self))]
fn
resolve_ident_in_module_unadjusted_ext
(
&
mut
self
,
module
:
ModuleOrUniformRoot
<
'a
>
,
...
...
@@ -791,6 +843,8 @@ fn resolve_ident_in_module_unadjusted_ext(
parent_scope
:
&
ParentScope
<
'a
>
,
restricted_shadowing
:
bool
,
finalize
:
Option
<
Span
>
,
last_import_segment
:
bool
,
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
Result
<&
'a
NameBinding
<
'a
>
,
(
Determinacy
,
Weak
)
>
{
let
module
=
match
module
{
ModuleOrUniformRoot
::
Module
(
module
)
=>
module
,
...
...
@@ -802,6 +856,8 @@ fn resolve_ident_in_module_unadjusted_ext(
parent_scope
,
finalize
,
finalize
.is_some
(),
last_import_segment
,
unusable_binding
,
);
return
binding
.map_err
(|
determinacy
|
(
determinacy
,
Weak
::
No
));
}
...
...
@@ -841,6 +897,8 @@ fn resolve_ident_in_module_unadjusted_ext(
parent_scope
,
finalize
,
finalize
.is_some
(),
last_import_segment
,
unusable_binding
,
);
return
binding
.map_err
(|
determinacy
|
(
determinacy
,
Weak
::
No
));
}
...
...
@@ -865,7 +923,7 @@ fn resolve_ident_in_module_unadjusted_ext(
// binding if it exists. What we really want here is having two separate scopes in
// a module - one for non-globs and one for globs, but until that's done use this
// hack to avoid inconsistent resolution ICEs during import validation.
if
let
Some
(
unusable_binding
)
=
self
.
unusable_binding
if
let
Some
(
unusable_binding
)
=
unusable_binding
&&
ptr
::
eq
(
binding
,
unusable_binding
)
{
let
Some
(
shadowed
)
=
resolution
.shadowed_glob
else
{
...
...
@@ -880,7 +938,7 @@ fn resolve_ident_in_module_unadjusted_ext(
}
if
!
self
.is_accessible_from
(
binding
.vis
,
parent_scope
.module
)
{
if
self
.
last_import_segment
{
if
last_import_segment
{
return
Err
((
Determined
,
Weak
::
No
));
}
else
{
self
.privacy_errors
.push
(
PrivacyError
{
...
...
@@ -912,7 +970,7 @@ fn resolve_ident_in_module_unadjusted_ext(
}
let
check_usable
=
|
this
:
&
mut
Self
,
binding
:
&
'a
NameBinding
<
'a
>
|
{
if
let
Some
(
unusable_binding
)
=
this
.
unusable_binding
{
if
let
Some
(
unusable_binding
)
=
unusable_binding
{
if
ptr
::
eq
(
binding
,
unusable_binding
)
{
return
Err
((
Determined
,
Weak
::
No
));
}
...
...
@@ -942,8 +1000,15 @@ fn resolve_ident_in_module_unadjusted_ext(
let
ImportKind
::
Single
{
source
:
ident
,
..
}
=
single_import
.kind
else
{
unreachable!
();
};
match
self
.resolve_ident_in_module
(
module
,
ident
,
ns
,
&
single_import
.parent_scope
,
None
)
{
match
self
.resolve_ident_in_module
(
module
,
ident
,
ns
,
&
single_import
.parent_scope
,
None
,
last_import_segment
,
unusable_binding
,
)
{
Err
(
Determined
)
=>
continue
,
Ok
(
binding
)
if
!
self
.is_accessible_from
(
binding
.vis
,
single_import
.parent_scope.module
)
=>
...
...
@@ -1018,6 +1083,8 @@ fn resolve_ident_in_module_unadjusted_ext(
ns
,
adjusted_parent_scope
,
None
,
last_import_segment
,
unusable_binding
,
);
match
result
{
...
...
@@ -1036,6 +1103,7 @@ fn resolve_ident_in_module_unadjusted_ext(
}
/// Validate a local resolution (from ribs).
#[tracing::instrument(level
=
"debug"
,
skip(self,
all_ribs))]
fn
validate_res_from_ribs
(
&
mut
self
,
rib_index
:
usize
,
...
...
@@ -1268,14 +1336,26 @@ fn validate_res_from_ribs(
res
}
#[tracing::instrument(level
=
"debug"
,
skip(self))]
crate
fn
maybe_resolve_path
(
&
mut
self
,
path
:
&
[
Segment
],
opt_ns
:
Option
<
Namespace
>
,
// `None` indicates a module path in import
parent_scope
:
&
ParentScope
<
'a
>
,
)
->
PathResult
<
'a
>
{
self
.resolve_path_with_ribs
(
path
,
opt_ns
,
parent_scope
,
Finalize
::
No
,
None
,
None
)
}
#[tracing::instrument(level
=
"debug"
,
skip(self))]
crate
fn
resolve_path
(
&
mut
self
,
path
:
&
[
Segment
],
opt_ns
:
Option
<
Namespace
>
,
// `None` indicates a module path in import
parent_scope
:
&
ParentScope
<
'a
>
,
finalize
:
Finalize
,
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
PathResult
<
'a
>
{
self
.resolve_path_with_ribs
(
path
,
opt_ns
,
parent_scope
,
finalize
,
None
)
self
.resolve_path_with_ribs
(
path
,
opt_ns
,
parent_scope
,
finalize
,
None
,
unusable_binding
)
}
crate
fn
resolve_path_with_ribs
(
...
...
@@ -1285,6 +1365,7 @@ fn validate_res_from_ribs(
parent_scope
:
&
ParentScope
<
'a
>
,
finalize_full
:
Finalize
,
ribs
:
Option
<&
PerNS
<
Vec
<
Rib
<
'a
>>>>
,
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
PathResult
<
'a
>
{
debug!
(
"resolve_path(path={:?}, opt_ns={:?}, finalize={:?})"
,
path
,
opt_ns
,
finalize_full
);
...
...
@@ -1382,7 +1463,15 @@ enum FindBindingResult<'a> {
}
let
find_binding_in_ns
=
|
this
:
&
mut
Self
,
ns
|
{
let
binding
=
if
let
Some
(
module
)
=
module
{
this
.resolve_ident_in_module
(
module
,
ident
,
ns
,
parent_scope
,
finalize
)
this
.resolve_ident_in_module
(
module
,
ident
,
ns
,
parent_scope
,
finalize
,
false
,
unusable_binding
,
)
}
else
if
ribs
.is_none
()
||
opt_ns
.is_none
()
||
opt_ns
==
Some
(
MacroNS
)
{
let
scopes
=
ScopeSet
::
All
(
ns
,
opt_ns
.is_none
());
this
.early_resolve_ident_in_lexical_scope
(
...
...
@@ -1391,6 +1480,8 @@ enum FindBindingResult<'a> {
parent_scope
,
finalize
,
finalize
.is_some
(),
false
,
unusable_binding
,
)
}
else
{
match
this
.resolve_ident_in_lexical_scope
(
...
...
@@ -1399,6 +1490,7 @@ enum FindBindingResult<'a> {
parent_scope
,
finalize_full
,
&
ribs
.unwrap
()[
ns
],
unusable_binding
,
)
{
// we found a locally-imported or available item/module
Some
(
LexicalScopeBinding
::
Item
(
binding
))
=>
Ok
(
binding
),
...
...
@@ -1514,6 +1606,7 @@ enum FindBindingResult<'a> {
parent_scope
,
Finalize
::
No
,
&
ribs
.unwrap
()[
ValueNS
],
unusable_binding
,
)
{
// Name matches a local variable. For example:
// ```
...
...
compiler/rustc_resolve/src/imports.rs
浏览文件 @
24b37a73
...
...
@@ -499,7 +499,7 @@ fn resolve_import(&mut self, import: &'b Import<'b>) -> bool {
// not define any names while resolving its module path.
let
orig_vis
=
import
.vis
.replace
(
ty
::
Visibility
::
Invisible
);
let
path_res
=
self
.r
.
resolve_path
(
&
import
.module_path
,
None
,
&
import
.parent_scope
,
Finalize
::
No
);
self
.r
.
maybe_resolve_path
(
&
import
.module_path
,
None
,
&
import
.parent_scope
);
import
.vis
.set
(
orig_vis
);
match
path_res
{
...
...
@@ -539,6 +539,8 @@ fn resolve_import(&mut self, import: &'b Import<'b>) -> bool {
ns
,
&
import
.parent_scope
,
None
,
false
,
None
,
);
import
.vis
.set
(
orig_vis
);
source_bindings
[
ns
]
.set
(
binding
);
...
...
@@ -584,10 +586,8 @@ fn resolve_import(&mut self, import: &'b Import<'b>) -> bool {
/// consolidate multiple unresolved import errors into a single diagnostic.
fn
finalize_import
(
&
mut
self
,
import
:
&
'b
Import
<
'b
>
)
->
Option
<
UnresolvedImportError
>
{
let
orig_vis
=
import
.vis
.replace
(
ty
::
Visibility
::
Invisible
);
let
orig_unusable_binding
=
match
&
import
.kind
{
ImportKind
::
Single
{
target_bindings
,
..
}
=>
{
Some
(
mem
::
replace
(
&
mut
self
.r.unusable_binding
,
target_bindings
[
TypeNS
]
.get
()))
}
let
unusable_binding
=
match
&
import
.kind
{
ImportKind
::
Single
{
target_bindings
,
..
}
=>
target_bindings
[
TypeNS
]
.get
(),
_
=>
None
,
};
let
prev_ambiguity_errors_len
=
self
.r.ambiguity_errors
.len
();
...
...
@@ -596,12 +596,14 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
root_span
:
import
.root_span
,
path_span
:
import
.span
,
};
let
path_res
=
self
.r
.resolve_path
(
&
import
.module_path
,
None
,
&
import
.parent_scope
,
finalize
);
let
path_res
=
self
.r
.resolve_path
(
&
import
.module_path
,
None
,
&
import
.parent_scope
,
finalize
,
unusable_binding
,
);
let
no_ambiguity
=
self
.r.ambiguity_errors
.len
()
==
prev_ambiguity_errors_len
;
if
let
Some
(
orig_unusable_binding
)
=
orig_unusable_binding
{
self
.r.unusable_binding
=
orig_unusable_binding
;
}
import
.vis
.set
(
orig_vis
);
if
let
PathResult
::
Failed
{
..
}
|
PathResult
::
NonModule
(
..
)
=
path_res
{
// Consider erroneous imports used to avoid duplicate diagnostics.
...
...
@@ -714,18 +716,15 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
self
.r
.per_ns
(|
this
,
ns
|
{
if
!
type_ns_only
||
ns
==
TypeNS
{
let
orig_vis
=
import
.vis
.replace
(
ty
::
Visibility
::
Invisible
);
let
orig_unusable_binding
=
mem
::
replace
(
&
mut
this
.unusable_binding
,
target_bindings
[
ns
]
.get
());
let
orig_last_import_segment
=
mem
::
replace
(
&
mut
this
.last_import_segment
,
true
);
let
binding
=
this
.resolve_ident_in_module
(
module
,
ident
,
ns
,
&
import
.parent_scope
,
Some
(
import
.span
),
true
,
target_bindings
[
ns
]
.get
(),
);
this
.last_import_segment
=
orig_last_import_segment
;
this
.unusable_binding
=
orig_unusable_binding
;
import
.vis
.set
(
orig_vis
);
match
binding
{
...
...
@@ -784,6 +783,8 @@ fn finalize_import(&mut self, import: &'b Import<'b>) -> Option<UnresolvedImport
ns
,
&
import
.parent_scope
,
Some
(
import
.span
),
false
,
None
,
);
if
binding
.is_ok
()
{
all_ns_failed
=
false
;
...
...
@@ -998,15 +999,14 @@ fn check_for_redundant_imports(
return
;
}
let
orig_unusable_binding
=
mem
::
replace
(
&
mut
this
.unusable_binding
,
target_bindings
[
ns
]
.get
());
match
this
.early_resolve_ident_in_lexical_scope
(
target
,
ScopeSet
::
All
(
ns
,
false
),
&
import
.parent_scope
,
None
,
false
,
false
,
target_bindings
[
ns
]
.get
(),
)
{
Ok
(
other_binding
)
=>
{
is_redundant
[
ns
]
=
Some
(
...
...
@@ -1016,8 +1016,6 @@ fn check_for_redundant_imports(
}
Err
(
_
)
=>
is_redundant
[
ns
]
=
Some
(
false
),
}
this
.unusable_binding
=
orig_unusable_binding
;
}
});
...
...
compiler/rustc_resolve/src/late.rs
浏览文件 @
24b37a73
...
...
@@ -8,7 +8,7 @@
use
RibKind
::
*
;
use
crate
::{
path_names_to_string
,
BindingError
,
Finalize
,
LexicalScopeBinding
};
use
crate
::{
Module
,
ModuleOrUniformRoot
,
ParentScope
,
PathResult
};
use
crate
::{
Module
,
ModuleOrUniformRoot
,
NameBinding
,
ParentScope
,
PathResult
};
use
crate
::{
ResolutionError
,
Resolver
,
Segment
,
UseError
};
use
rustc_ast
::
ptr
::
P
;
...
...
@@ -487,6 +487,7 @@ fn visit_ty(&mut self, ty: &'ast Ty) {
self_ty
,
TypeNS
,
Finalize
::
SimplePath
(
ty
.id
,
ty
.span
),
None
,
)
.map_or
(
Res
::
Err
,
|
d
|
d
.res
());
self
.r
.record_partial_res
(
ty
.id
,
PartialRes
::
new
(
res
));
...
...
@@ -676,12 +677,8 @@ fn visit_generic_arg(&mut self, arg: &'ast GenericArg) {
// checking.
if
path
.segments
.len
()
==
1
&&
path
.segments
[
0
]
.args
.is_none
()
{
let
mut
check_ns
=
|
ns
|
{
self
.resolve_ident_in_lexical_scope
(
path
.segments
[
0
]
.ident
,
ns
,
Finalize
::
No
,
)
.is_some
()
self
.maybe_resolve_ident_in_lexical_scope
(
path
.segments
[
0
]
.ident
,
ns
)
.is_some
()
};
if
!
check_ns
(
TypeNS
)
&&
check_ns
(
ValueNS
)
{
// This must be equivalent to `visit_anon_const`, but we cannot call it
...
...
@@ -750,11 +747,27 @@ fn new(resolver: &'b mut Resolver<'a>) -> LateResolutionVisitor<'a, 'b, 'ast> {
}
}
fn
maybe_resolve_ident_in_lexical_scope
(
&
mut
self
,
ident
:
Ident
,
ns
:
Namespace
,
)
->
Option
<
LexicalScopeBinding
<
'a
>>
{
self
.r
.resolve_ident_in_lexical_scope
(
ident
,
ns
,
&
self
.parent_scope
,
Finalize
::
No
,
&
self
.ribs
[
ns
],
None
,
)
}
fn
resolve_ident_in_lexical_scope
(
&
mut
self
,
ident
:
Ident
,
ns
:
Namespace
,
finalize
:
Finalize
,
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
)
->
Option
<
LexicalScopeBinding
<
'a
>>
{
self
.r
.resolve_ident_in_lexical_scope
(
ident
,
...
...
@@ -762,6 +775,7 @@ fn resolve_ident_in_lexical_scope(
&
self
.parent_scope
,
finalize
,
&
self
.ribs
[
ns
],
unusable_binding
,
)
}
...
...
@@ -771,7 +785,14 @@ fn resolve_path(
opt_ns
:
Option
<
Namespace
>
,
// `None` indicates a module path in import
finalize
:
Finalize
,
)
->
PathResult
<
'a
>
{
self
.r
.resolve_path_with_ribs
(
path
,
opt_ns
,
&
self
.parent_scope
,
finalize
,
Some
(
&
self
.ribs
))
self
.r
.resolve_path_with_ribs
(
path
,
opt_ns
,
&
self
.parent_scope
,
finalize
,
Some
(
&
self
.ribs
),
None
,
)
}
// AST resolution
...
...
@@ -934,19 +955,16 @@ fn future_proof_import(&mut self, use_tree: &UseTree) {
};
for
&
ns
in
nss
{
match
self
.
resolve_ident_in_lexical_scope
(
ident
,
ns
,
Finalize
::
No
)
{
match
self
.
maybe_resolve_ident_in_lexical_scope
(
ident
,
ns
)
{
Some
(
LexicalScopeBinding
::
Res
(
..
))
=>
{
report_error
(
self
,
ns
);
}
Some
(
LexicalScopeBinding
::
Item
(
binding
))
=>
{
let
orig_unusable_binding
=
replace
(
&
mut
self
.r.unusable_binding
,
Some
(
binding
));
if
let
Some
(
LexicalScopeBinding
::
Res
(
..
))
=
self
.resolve_ident_in_lexical_scope
(
ident
,
ns
,
Finalize
::
No
)
if
let
Some
(
LexicalScopeBinding
::
Res
(
..
))
=
self
.resolve_ident_in_lexical_scope
(
ident
,
ns
,
Finalize
::
No
,
Some
(
binding
))
{
report_error
(
self
,
ns
);
}
self
.r.unusable_binding
=
orig_unusable_binding
;
}
None
=>
{}
}
...
...
@@ -1802,7 +1820,7 @@ fn try_resolve_as_non_binding(
// also be interpreted as a path to e.g. a constant, variant, etc.
let
is_syntactic_ambiguity
=
!
has_sub
&&
bm
==
BindingMode
::
ByValue
(
Mutability
::
Not
);
let
ls_binding
=
self
.
resolve_ident_in_lexical_scope
(
ident
,
ValueNS
,
Finalize
::
No
)
?
;
let
ls_binding
=
self
.
maybe_resolve_ident_in_lexical_scope
(
ident
,
ValueNS
)
?
;
let
(
res
,
binding
)
=
match
ls_binding
{
LexicalScopeBinding
::
Item
(
binding
)
if
is_syntactic_ambiguity
&&
binding
.is_ambiguity
()
=>
...
...
@@ -2071,17 +2089,14 @@ fn smart_resolve_path_fragment(
}
fn
self_type_is_available
(
&
mut
self
)
->
bool
{
let
binding
=
self
.resolve_ident_in_lexical_scope
(
Ident
::
with_dummy_span
(
kw
::
SelfUpper
),
TypeNS
,
Finalize
::
No
,
);
let
binding
=
self
.maybe_resolve_ident_in_lexical_scope
(
Ident
::
with_dummy_span
(
kw
::
SelfUpper
),
TypeNS
);
if
let
Some
(
LexicalScopeBinding
::
Res
(
res
))
=
binding
{
res
!=
Res
::
Err
}
else
{
false
}
}
fn
self_value_is_available
(
&
mut
self
,
self_span
:
Span
)
->
bool
{
let
ident
=
Ident
::
new
(
kw
::
SelfLower
,
self_span
);
let
binding
=
self
.
resolve_ident_in_lexical_scope
(
ident
,
ValueNS
,
Finalize
::
No
);
let
binding
=
self
.
maybe_resolve_ident_in_lexical_scope
(
ident
,
ValueNS
);
if
let
Some
(
LexicalScopeBinding
::
Res
(
res
))
=
binding
{
res
!=
Res
::
Err
}
else
{
false
}
}
...
...
compiler/rustc_resolve/src/late/diagnostics.rs
浏览文件 @
24b37a73
...
...
@@ -1271,12 +1271,11 @@ fn extract_node_id(t: &Ty) -> Option<NodeId> {
// Look for associated items in the current trait.
if
let
Some
((
module
,
_
))
=
self
.current_trait_ref
{
if
let
Ok
(
binding
)
=
self
.r
.resolve_ident_in_module
(
if
let
Ok
(
binding
)
=
self
.r
.
maybe_
resolve_ident_in_module
(
ModuleOrUniformRoot
::
Module
(
module
),
ident
,
ns
,
&
self
.parent_scope
,
None
,
)
{
let
res
=
binding
.res
();
if
filter_fn
(
res
)
{
...
...
compiler/rustc_resolve/src/lib.rs
浏览文件 @
24b37a73
...
...
@@ -925,13 +925,6 @@ pub struct Resolver<'a> {
/// All non-determined imports.
indeterminate_imports
:
Vec
<&
'a
Import
<
'a
>>
,
/// FIXME: Refactor things so that these fields are passed through arguments and not resolver.
/// We are resolving a last import segment during import validation.
last_import_segment
:
bool
,
/// This binding should be ignored during in-module resolution, so that we don't get
/// "self-confirming" import resolutions during import validation.
unusable_binding
:
Option
<&
'a
NameBinding
<
'a
>>
,
// Spans for local variables found during pattern resolution.
// Used for suggestions during error reporting.
pat_span_map
:
NodeMap
<
Span
>
,
...
...
@@ -1339,9 +1332,6 @@ pub fn new(
determined_imports
:
Vec
::
new
(),
indeterminate_imports
:
Vec
::
new
(),
last_import_segment
:
false
,
unusable_binding
:
None
,
pat_span_map
:
Default
::
default
(),
partial_res_map
:
Default
::
default
(),
import_res_map
:
Default
::
default
(),
...
...
@@ -2294,12 +2284,7 @@ pub fn resolve_rustdoc_path(
}
let
module
=
self
.expect_module
(
module_id
);
match
self
.resolve_path
(
&
segments
,
Some
(
ns
),
&
ParentScope
::
module
(
module
,
self
),
Finalize
::
No
,
)
{
match
self
.maybe_resolve_path
(
&
segments
,
Some
(
ns
),
&
ParentScope
::
module
(
module
,
self
))
{
PathResult
::
Module
(
ModuleOrUniformRoot
::
Module
(
module
))
=>
Some
(
module
.res
()
.unwrap
()),
PathResult
::
NonModule
(
path_res
)
if
path_res
.unresolved_segments
()
==
0
=>
{
Some
(
path_res
.base_res
())
...
...
@@ -2389,12 +2374,11 @@ fn resolve_main(&mut self) {
let
ident
=
Ident
::
with_dummy_span
(
sym
::
main
);
let
parent_scope
=
&
ParentScope
::
module
(
module
,
self
);
let
Ok
(
name_binding
)
=
self
.resolve_ident_in_module
(
let
Ok
(
name_binding
)
=
self
.
maybe_
resolve_ident_in_module
(
ModuleOrUniformRoot
::
Module
(
module
),
ident
,
ValueNS
,
parent_scope
,
None
)
else
{
return
;
};
...
...
compiler/rustc_resolve/src/macros.rs
浏览文件 @
24b37a73
...
...
@@ -412,7 +412,7 @@ fn cfg_accessible(
let
mut
indeterminate
=
false
;
for
ns
in
[
TypeNS
,
ValueNS
,
MacroNS
]
.iter
()
.copied
()
{
match
self
.
resolve_path
(
path
,
Some
(
ns
),
&
parent_scope
,
Finalize
::
No
)
{
match
self
.
maybe_resolve_path
(
path
,
Some
(
ns
),
&
parent_scope
)
{
PathResult
::
Module
(
ModuleOrUniformRoot
::
Module
(
_
))
=>
return
Ok
(
true
),
PathResult
::
NonModule
(
partial_res
)
if
partial_res
.unresolved_segments
()
==
0
=>
{
return
Ok
(
true
);
...
...
@@ -572,7 +572,7 @@ pub fn resolve_macro_path(
}
let
res
=
if
path
.len
()
>
1
{
let
res
=
match
self
.
resolve_path
(
&
path
,
Some
(
MacroNS
),
parent_scope
,
Finalize
::
No
)
{
let
res
=
match
self
.
maybe_resolve_path
(
&
path
,
Some
(
MacroNS
),
parent_scope
)
{
PathResult
::
NonModule
(
path_res
)
if
path_res
.unresolved_segments
()
==
0
=>
{
Ok
(
path_res
.base_res
())
}
...
...
@@ -604,6 +604,8 @@ pub fn resolve_macro_path(
parent_scope
,
None
,
force
,
false
,
None
,
);
if
let
Err
(
Determinacy
::
Undetermined
)
=
binding
{
return
Err
(
Determinacy
::
Undetermined
);
...
...
@@ -672,6 +674,7 @@ pub fn resolve_macro_path(
Some
(
MacroNS
),
&
parent_scope
,
Finalize
::
SimplePath
(
ast
::
CRATE_NODE_ID
,
path_span
),
None
,
)
{
PathResult
::
NonModule
(
path_res
)
if
path_res
.unresolved_segments
()
==
0
=>
{
let
res
=
path_res
.base_res
();
...
...
@@ -707,6 +710,8 @@ pub fn resolve_macro_path(
&
parent_scope
,
Some
(
ident
.span
),
true
,
false
,
None
,
)
{
Ok
(
binding
)
=>
{
let
initial_res
=
initial_binding
.map
(|
initial_binding
|
{
...
...
@@ -748,6 +753,8 @@ pub fn resolve_macro_path(
&
parent_scope
,
Some
(
ident
.span
),
true
,
false
,
None
,
);
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录