Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1b6be5a1
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,发现更多精彩内容 >>
提交
1b6be5a1
编写于
9月 13, 2018
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve: Put different parent scopes into a single structure
上级
f2302dae
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
108 addition
and
72 deletion
+108
-72
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+10
-3
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+11
-10
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+81
-53
src/librustdoc/passes/collect_intra_doc_links.rs
src/librustdoc/passes/collect_intra_doc_links.rs
+3
-3
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+2
-2
src/libsyntax/ext/expand.rs
src/libsyntax/ext/expand.rs
+1
-1
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
1b6be5a1
...
...
@@ -13,7 +13,7 @@
//! Here we build the "reduced graph": the graph of the module tree without
//! any imports resolved.
use
macros
::{
InvocationData
,
LegacyScope
};
use
macros
::{
InvocationData
,
ParentScope
,
LegacyScope
};
use
resolve_imports
::
ImportDirective
;
use
resolve_imports
::
ImportDirectiveSubclass
::{
self
,
GlobImport
,
SingleImport
};
use
{
Module
,
ModuleData
,
ModuleKind
,
NameBinding
,
NameBindingKind
,
ToNameBinding
};
...
...
@@ -1061,8 +1061,15 @@ fn visit_token(&mut self, t: Token) {
fn
visit_attribute
(
&
mut
self
,
attr
:
&
'a
ast
::
Attribute
)
{
if
!
attr
.is_sugared_doc
&&
is_builtin_attr
(
attr
)
{
self
.resolver.current_module.builtin_attrs
.borrow_mut
()
.push
((
attr
.path.segments
[
0
]
.ident
,
self
.expansion
,
self
.current_legacy_scope
let
parent_scope
=
ParentScope
{
module
:
self
.resolver.current_module
.nearest_item_scope
(),
expansion
:
self
.expansion
,
legacy
:
self
.current_legacy_scope
,
// Let's hope discerning built-in attributes from derive helpers is not necessary
derives
:
Vec
::
new
(),
};
parent_scope
.module.builtin_attrs
.borrow_mut
()
.push
((
attr
.path.segments
[
0
]
.ident
,
parent_scope
));
}
visit
::
walk_attribute
(
self
,
attr
);
...
...
src/librustc_resolve/lib.rs
浏览文件 @
1b6be5a1
...
...
@@ -80,7 +80,7 @@
use
rustc_data_structures
::
sync
::
Lrc
;
use
resolve_imports
::{
ImportDirective
,
ImportDirectiveSubclass
,
NameResolution
,
ImportResolver
};
use
macros
::{
InvocationData
,
LegacyBinding
,
Legacy
Scope
};
use
macros
::{
InvocationData
,
LegacyBinding
,
Parent
Scope
};
// NB: This module needs to be declared first so diagnostics are
// registered before they are used.
...
...
@@ -1009,9 +1009,9 @@ pub struct ModuleData<'a> {
normal_ancestor_id
:
DefId
,
resolutions
:
RefCell
<
FxHashMap
<
(
Ident
,
Namespace
),
&
'a
RefCell
<
NameResolution
<
'a
>>>>
,
legacy_macro_resolutions
:
RefCell
<
Vec
<
(
Ident
,
MacroKind
,
Mark
,
Legacy
Scope
<
'a
>
,
Option
<
Def
>
)
>>
,
legacy_macro_resolutions
:
RefCell
<
Vec
<
(
Ident
,
MacroKind
,
Parent
Scope
<
'a
>
,
Option
<
Def
>
)
>>
,
macro_resolutions
:
RefCell
<
Vec
<
(
Box
<
[
Ident
]
>
,
Span
)
>>
,
builtin_attrs
:
RefCell
<
Vec
<
(
Ident
,
Mark
,
Legacy
Scope
<
'a
>
)
>>
,
builtin_attrs
:
RefCell
<
Vec
<
(
Ident
,
Parent
Scope
<
'a
>
)
>>
,
// Macro invocations that can expand into items in this module.
unresolved_invocations
:
RefCell
<
FxHashSet
<
Mark
>>
,
...
...
@@ -3494,16 +3494,17 @@ fn resolve_path(
path_span
:
Span
,
crate_lint
:
CrateLint
,
)
->
PathResult
<
'a
>
{
self
.resolve_path_with_parent_expansion
(
base_module
,
path
,
opt_ns
,
Mark
::
root
(),
record_used
,
path_span
,
crate_lint
)
let
parent_scope
=
ParentScope
{
module
:
self
.current_module
,
..
self
.dummy_parent_scope
()
};
self
.resolve_path_with_parent_scope
(
base_module
,
path
,
opt_ns
,
&
parent_scope
,
record_used
,
path_span
,
crate_lint
)
}
fn
resolve_path_with_parent_
expansion
(
fn
resolve_path_with_parent_
scope
(
&
mut
self
,
base_module
:
Option
<
ModuleOrUniformRoot
<
'a
>>
,
path
:
&
[
Ident
],
opt_ns
:
Option
<
Namespace
>
,
// `None` indicates a module path
parent_
expansion
:
Mark
,
parent_
scope
:
&
ParentScope
<
'a
>
,
record_used
:
bool
,
path_span
:
Span
,
crate_lint
:
CrateLint
,
...
...
@@ -3511,6 +3512,7 @@ fn resolve_path_with_parent_expansion(
let
mut
module
=
base_module
;
let
mut
allow_super
=
true
;
let
mut
second_binding
=
None
;
self
.current_module
=
parent_scope
.module
;
debug!
(
"resolve_path(path={:?}, opt_ns={:?}, record_used={:?},
\
...
...
@@ -3596,9 +3598,8 @@ fn resolve_path_with_parent_expansion(
self
.resolve_ident_in_module
(
module
,
ident
,
ns
,
record_used
,
path_span
)
}
else
if
opt_ns
==
Some
(
MacroNS
)
{
assert
!
(
ns
==
TypeNS
);
self
.resolve_lexical_macro_path_segment
(
ident
,
ns
,
None
,
parent_expansion
,
record_used
,
record_used
,
path_span
)
.map
(|(
binding
,
_
)|
binding
)
self
.resolve_lexical_macro_path_segment
(
ident
,
ns
,
None
,
parent_scope
,
record_used
,
record_used
,
path_span
)
.map
(|(
b
,
_
)|
b
)
}
else
{
let
record_used_id
=
if
record_used
{
crate_lint
.node_id
()
.or
(
Some
(
CRATE_NODE_ID
))
}
else
{
None
};
...
...
src/librustc_resolve/macros.rs
浏览文件 @
1b6be5a1
...
...
@@ -101,6 +101,15 @@ pub enum LegacyScope<'a> {
Invocation
(
&
'a
InvocationData
<
'a
>
),
}
/// Everything you need to resolve a macro path.
#[derive(Clone)]
pub
struct
ParentScope
<
'a
>
{
crate
module
:
Module
<
'a
>
,
crate
expansion
:
Mark
,
crate
legacy
:
LegacyScope
<
'a
>
,
crate
derives
:
Vec
<
ast
::
Path
>
,
}
pub
struct
ProcMacError
{
crate_name
:
Symbol
,
name
:
Symbol
,
...
...
@@ -326,14 +335,15 @@ fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force
InvocationKind
::
Attr
{
attr
:
None
,
..
}
=>
return
Ok
(
None
),
InvocationKind
::
Attr
{
attr
:
Some
(
ref
attr
),
ref
traits
,
..
}
=>
(
&
attr
.path
,
MacroKind
::
Attr
,
&
traits
[
..
]
),
(
&
attr
.path
,
MacroKind
::
Attr
,
traits
.clone
()
),
InvocationKind
::
Bang
{
ref
mac
,
..
}
=>
(
&
mac
.node.path
,
MacroKind
::
Bang
,
&
[][
..
]
),
(
&
mac
.node.path
,
MacroKind
::
Bang
,
Vec
::
new
()
),
InvocationKind
::
Derive
{
ref
path
,
..
}
=>
(
path
,
MacroKind
::
Derive
,
&
[][
..
]
),
(
path
,
MacroKind
::
Derive
,
Vec
::
new
()
),
};
let
(
def
,
ext
)
=
self
.resolve_macro_to_def
(
path
,
kind
,
invoc_id
,
derives_in_scope
,
force
)
?
;
let
parent_scope
=
self
.invoc_parent_scope
(
invoc_id
,
derives_in_scope
);
let
(
def
,
ext
)
=
self
.resolve_macro_to_def
(
path
,
kind
,
&
parent_scope
,
force
)
?
;
if
let
Def
::
Macro
(
def_id
,
_
)
=
def
{
self
.macro_defs
.insert
(
invoc
.expansion_data.mark
,
def_id
);
...
...
@@ -349,9 +359,10 @@ fn resolve_macro_invocation(&mut self, invoc: &Invocation, invoc_id: Mark, force
}
fn
resolve_macro_path
(
&
mut
self
,
path
:
&
ast
::
Path
,
kind
:
MacroKind
,
invoc_id
:
Mark
,
derives_in_scope
:
&
[
ast
::
Path
]
,
force
:
bool
)
derives_in_scope
:
Vec
<
ast
::
Path
>
,
force
:
bool
)
->
Result
<
Lrc
<
SyntaxExtension
>
,
Determinacy
>
{
Ok
(
self
.resolve_macro_to_def
(
path
,
kind
,
invoc_id
,
derives_in_scope
,
force
)
?
.1
)
let
parent_scope
=
self
.invoc_parent_scope
(
invoc_id
,
derives_in_scope
);
Ok
(
self
.resolve_macro_to_def
(
path
,
kind
,
&
parent_scope
,
force
)
?
.1
)
}
fn
check_unused_macros
(
&
self
)
{
...
...
@@ -373,10 +384,28 @@ fn check_unused_macros(&self) {
}
impl
<
'a
,
'cl
>
Resolver
<
'a
,
'cl
>
{
fn
resolve_macro_to_def
(
&
mut
self
,
path
:
&
ast
::
Path
,
kind
:
MacroKind
,
invoc_id
:
Mark
,
derives_in_scope
:
&
[
ast
::
Path
],
force
:
bool
)
->
Result
<
(
Def
,
Lrc
<
SyntaxExtension
>
),
Determinacy
>
{
let
def
=
self
.resolve_macro_to_def_inner
(
path
,
kind
,
invoc_id
,
derives_in_scope
,
force
);
pub
fn
dummy_parent_scope
(
&
mut
self
)
->
ParentScope
<
'a
>
{
self
.invoc_parent_scope
(
Mark
::
root
(),
Vec
::
new
())
}
fn
invoc_parent_scope
(
&
mut
self
,
invoc_id
:
Mark
,
derives
:
Vec
<
ast
::
Path
>
)
->
ParentScope
<
'a
>
{
let
invoc
=
self
.invocations
[
&
invoc_id
];
ParentScope
{
module
:
invoc
.module
.get
()
.nearest_item_scope
(),
expansion
:
invoc_id
.parent
(),
legacy
:
invoc
.parent_legacy_scope
.get
(),
derives
,
}
}
fn
resolve_macro_to_def
(
&
mut
self
,
path
:
&
ast
::
Path
,
kind
:
MacroKind
,
parent_scope
:
&
ParentScope
<
'a
>
,
force
:
bool
,
)
->
Result
<
(
Def
,
Lrc
<
SyntaxExtension
>
),
Determinacy
>
{
let
def
=
self
.resolve_macro_to_def_inner
(
path
,
kind
,
parent_scope
,
force
);
// Report errors and enforce feature gates for the resolved macro.
if
def
!=
Err
(
Determinacy
::
Undetermined
)
{
...
...
@@ -440,15 +469,15 @@ fn resolve_macro_to_def(&mut self, path: &ast::Path, kind: MacroKind, invoc_id:
Ok
((
def
,
self
.get_macro
(
def
)))
}
pub
fn
resolve_macro_to_def_inner
(
&
mut
self
,
path
:
&
ast
::
Path
,
kind
:
MacroKind
,
invoc_id
:
Mark
,
derives_in_scope
:
&
[
ast
::
Path
],
force
:
bool
)
->
Result
<
Def
,
Determinacy
>
{
pub
fn
resolve_macro_to_def_inner
(
&
mut
self
,
path
:
&
ast
::
Path
,
kind
:
MacroKind
,
parent_scope
:
&
ParentScope
<
'a
>
,
force
:
bool
,
)
->
Result
<
Def
,
Determinacy
>
{
let
ast
::
Path
{
ref
segments
,
span
}
=
*
path
;
let
mut
path
:
Vec
<
_
>
=
segments
.iter
()
.map
(|
seg
|
seg
.ident
)
.collect
();
let
invocation
=
self
.invocations
[
&
invoc_id
];
let
parent_expansion
=
invoc_id
.parent
();
let
parent_legacy_scope
=
invocation
.parent_legacy_scope
.get
();
self
.current_module
=
invocation
.module
.get
()
.nearest_item_scope
();
// Possibly apply the macro helper hack
if
kind
==
MacroKind
::
Bang
&&
path
.len
()
==
1
&&
...
...
@@ -458,9 +487,9 @@ pub fn resolve_macro_to_def_inner(&mut self, path: &ast::Path, kind: MacroKind,
}
if
path
.len
()
>
1
{
let
def
=
match
self
.resolve_path_with_parent_
expansion
(
None
,
&
path
,
Some
(
MacroNS
),
parent_expansion
,
false
,
span
,
CrateLint
::
No
)
{
let
def
=
match
self
.resolve_path_with_parent_
scope
(
None
,
&
path
,
Some
(
MacroNS
),
parent_scope
,
false
,
span
,
CrateLint
::
No
)
{
PathResult
::
NonModule
(
path_res
)
=>
match
path_res
.base_def
()
{
Def
::
Err
=>
Err
(
Determinacy
::
Determined
),
def
@
_
=>
{
...
...
@@ -480,19 +509,17 @@ pub fn resolve_macro_to_def_inner(&mut self, path: &ast::Path, kind: MacroKind,
Err
(
Determinacy
::
Determined
)
},
};
self
.current_
module.macro_resolutions
.borrow_mut
()
parent_scope
.
module.macro_resolutions
.borrow_mut
()
.push
((
path
.into_boxed_slice
(),
span
));
return
def
;
}
let
legacy_resolution
=
self
.resolve_legacy_scope
(
path
[
0
],
Some
(
kind
),
parent_expansion
,
parent_legacy_scope
,
false
);
let
result
=
if
let
Some
(
legacy_binding
)
=
legacy_resolution
{
let
result
=
if
let
Some
(
legacy_binding
)
=
self
.resolve_legacy_scope
(
path
[
0
],
Some
(
kind
),
parent_scope
,
false
)
{
Ok
(
legacy_binding
.def
())
}
else
{
match
self
.resolve_lexical_macro_path_segment
(
path
[
0
],
MacroNS
,
Some
(
kind
),
parent_
expansion
,
false
,
force
,
span
)
{
parent_
scope
,
false
,
force
,
span
)
{
Ok
((
binding
,
_
))
=>
Ok
(
binding
.def_ignoring_ambiguity
()),
Err
(
Determinacy
::
Undetermined
)
=>
return
Err
(
Determinacy
::
Undetermined
),
Err
(
Determinacy
::
Determined
)
=>
{
...
...
@@ -502,8 +529,8 @@ pub fn resolve_macro_to_def_inner(&mut self, path: &ast::Path, kind: MacroKind,
}
};
self
.current_
module.legacy_macro_resolutions
.borrow_mut
()
.push
((
path
[
0
],
kind
,
parent_
expansion
,
parent_legacy_scope
,
result
.ok
()));
parent_scope
.
module.legacy_macro_resolutions
.borrow_mut
()
.push
((
path
[
0
],
kind
,
parent_
scope
.clone
()
,
result
.ok
()));
if
let
Ok
(
Def
::
NonMacroAttr
(
NonMacroAttrKind
::
Custom
))
=
result
{}
else
{
return
result
;
...
...
@@ -521,9 +548,9 @@ pub fn resolve_macro_to_def_inner(&mut self, path: &ast::Path, kind: MacroKind,
assert
!
(
kind
==
MacroKind
::
Attr
);
enum
ConvertToDeriveHelper
{
Yes
,
No
,
DontKnow
}
let
mut
convert_to_derive_helper
=
ConvertToDeriveHelper
::
No
;
for
derive
in
derives_in_scope
{
match
self
.resolve_macro_
path
(
derive
,
MacroKind
::
Derive
,
invoc_id
,
&
[]
,
force
)
{
Ok
(
ext
)
=>
if
let
SyntaxExtension
::
ProcMacroDerive
(
_
,
ref
inert_attrs
,
_
)
=
*
ext
{
for
derive
in
&
parent_scope
.derives
{
match
self
.resolve_macro_
to_def
(
derive
,
MacroKind
::
Derive
,
parent_scope
,
force
)
{
Ok
(
(
_
,
ext
))
=>
if
let
SyntaxExtension
::
ProcMacroDerive
(
_
,
inert_attrs
,
_
)
=
&
*
ext
{
if
inert_attrs
.contains
(
&
path
[
0
]
.name
)
{
convert_to_derive_helper
=
ConvertToDeriveHelper
::
Yes
;
break
...
...
@@ -551,7 +578,7 @@ enum ConvertToDeriveHelper { Yes, No, DontKnow }
mut
ident
:
Ident
,
ns
:
Namespace
,
kind
:
Option
<
MacroKind
>
,
parent_
expansion
:
Mark
,
parent_
scope
:
&
ParentScope
<
'a
>
,
record_used
:
bool
,
force
:
bool
,
path_span
:
Span
,
...
...
@@ -610,8 +637,8 @@ enum WhereToResolve<'a> {
}
// Go through all the scopes and try to resolve the name.
let
mut
where_to_resolve
=
WhereToResolve
::
Module
(
self
.current_
module
);
let
mut
use_prelude
=
!
self
.current_
module.no_implicit_prelude
;
let
mut
where_to_resolve
=
WhereToResolve
::
Module
(
parent_scope
.
module
);
let
mut
use_prelude
=
!
parent_scope
.
module.no_implicit_prelude
;
loop
{
let
result
=
match
where_to_resolve
{
WhereToResolve
::
Module
(
module
)
=>
{
...
...
@@ -755,7 +782,7 @@ enum WhereToResolve<'a> {
// Found another solution, if the first one was "weak", report an error.
if
result
.0
.def
()
!=
innermost_result
.0
.def
()
&&
(
innermost_result
.0
.is_glob_import
()
||
innermost_result
.0
.may_appear_after
(
parent_expansion
,
result
.0
))
{
innermost_result
.0
.may_appear_after
(
parent_
scope
.
expansion
,
result
.0
))
{
self
.ambiguity_errors
.push
(
AmbiguityError
{
ident
,
b1
:
innermost_result
.0
,
...
...
@@ -797,13 +824,13 @@ enum WhereToResolve<'a> {
}
}
fn
resolve_legacy_scope
(
&
mut
self
,
ident
:
Ident
,
kind
:
Option
<
MacroKind
>
,
parent_expansion
:
Mark
,
parent_legacy_scope
:
Legacy
Scope
<
'a
>
,
record_used
:
bool
)
->
Option
<&
'a
NameBinding
<
'a
>>
{
fn
resolve_legacy_scope
(
&
mut
self
,
ident
:
Ident
,
kind
:
Option
<
MacroKind
>
,
parent_scope
:
&
Parent
Scope
<
'a
>
,
record_used
:
bool
,
)
->
Option
<&
'a
NameBinding
<
'a
>>
{
if
macro_kind_mismatch
(
ident
.name
,
kind
,
Some
(
MacroKind
::
Bang
))
{
return
None
;
}
...
...
@@ -824,7 +851,7 @@ fn resolve_legacy_scope(&mut self,
let
mut
innermost_result
:
Option
<&
NameBinding
>
=
None
;
// Go through all the scopes and try to resolve the name.
let
mut
where_to_resolve
=
parent_
legacy_scope
;
let
mut
where_to_resolve
=
parent_
scope
.legacy
;
loop
{
let
result
=
match
where_to_resolve
{
LegacyScope
::
Binding
(
legacy_binding
)
if
ident
==
legacy_binding
.ident
=>
...
...
@@ -852,7 +879,7 @@ fn resolve_legacy_scope(&mut self,
if
let
Some
(
innermost_result
)
=
innermost_result
{
// Found another solution, if the first one was "weak", report an error.
if
result
.def
()
!=
innermost_result
.def
()
&&
innermost_result
.may_appear_after
(
parent_expansion
,
result
)
{
innermost_result
.may_appear_after
(
parent_
scope
.
expansion
,
result
)
{
self
.ambiguity_errors
.push
(
AmbiguityError
{
ident
,
b1
:
innermost_result
,
...
...
@@ -889,14 +916,15 @@ pub fn finalize_current_module_macro_resolutions(&mut self) {
}
}
for
&
(
ident
,
kind
,
parent_expansion
,
parent_legacy_scope
,
def
)
in
module
.legacy_macro_resolutions
.borrow
()
.iter
()
{
let
legacy_macro_resolutions
=
mem
::
replace
(
&
mut
*
module
.legacy_macro_resolutions
.borrow_mut
(),
Vec
::
new
());
for
(
ident
,
kind
,
parent_scope
,
def
)
in
legacy_macro_resolutions
{
let
span
=
ident
.span
;
let
legacy_resolution
=
self
.resolve_legacy_scope
(
ident
,
Some
(
kind
),
parent_expansion
,
parent_legacy
_scope
,
true
ident
,
Some
(
kind
),
&
parent
_scope
,
true
);
let
resolution
=
self
.resolve_lexical_macro_path_segment
(
ident
,
MacroNS
,
Some
(
kind
),
parent_expansion
,
true
,
true
,
span
ident
,
MacroNS
,
Some
(
kind
),
&
parent_scope
,
true
,
true
,
span
);
let
check_consistency
=
|
this
:
&
Self
,
new_def
:
Def
|
{
...
...
@@ -932,7 +960,7 @@ pub fn finalize_current_module_macro_resolutions(&mut self) {
(
Some
(
legacy_binding
),
Ok
((
binding
,
FromPrelude
(
from_prelude
))))
if
legacy_binding
.def
()
!=
binding
.def_ignoring_ambiguity
()
&&
(
!
from_prelude
||
legacy_binding
.may_appear_after
(
parent_expansion
,
binding
))
=>
{
legacy_binding
.may_appear_after
(
parent_
scope
.
expansion
,
binding
))
=>
{
self
.report_ambiguity_error
(
ident
,
legacy_binding
,
binding
);
},
// OK, non-macro-expanded legacy wins over prelude even if defs are different
...
...
@@ -953,13 +981,13 @@ pub fn finalize_current_module_macro_resolutions(&mut self) {
};
}
for
&
(
ident
,
parent_expansion
,
parent_legacy_scope
)
in
module
.builtin_attrs
.borrow
()
.iter
()
{
let
builtin_attrs
=
mem
::
replace
(
&
mut
*
module
.builtin_attrs
.borrow_mut
(),
Vec
::
new
());
for
(
ident
,
parent_scope
)
in
builtin_attrs
{
let
resolve_legacy
=
|
this
:
&
mut
Self
|
this
.resolve_legacy_scope
(
ident
,
Some
(
MacroKind
::
Attr
),
parent_expansion
,
parent_legacy
_scope
,
true
ident
,
Some
(
MacroKind
::
Attr
),
&
parent
_scope
,
true
);
let
resolve_modern
=
|
this
:
&
mut
Self
|
this
.resolve_lexical_macro_path_segment
(
ident
,
MacroNS
,
Some
(
MacroKind
::
Attr
),
parent_expansion
,
true
,
true
,
ident
.span
ident
,
MacroNS
,
Some
(
MacroKind
::
Attr
),
&
parent_scope
,
true
,
true
,
ident
.span
)
.map
(|(
binding
,
_
)|
binding
)
.ok
();
if
let
Some
(
binding
)
=
resolve_legacy
(
self
)
.or_else
(||
resolve_modern
(
self
))
{
...
...
src/librustdoc/passes/collect_intra_doc_links.rs
浏览文件 @
1b6be5a1
...
...
@@ -398,12 +398,12 @@ fn fold_item(&mut self, mut item: Item) -> Option<Item> {
/// Resolve a string as a macro
fn
macro_resolve
(
cx
:
&
DocContext
,
path_str
:
&
str
)
->
Option
<
Def
>
{
use
syntax
::
ext
::
base
::{
MacroKind
,
SyntaxExtension
};
use
syntax
::
ext
::
hygiene
::
Mark
;
let
segment
=
ast
::
PathSegment
::
from_ident
(
Ident
::
from_str
(
path_str
));
let
path
=
ast
::
Path
{
segments
:
vec!
[
segment
],
span
:
DUMMY_SP
};
let
mut
resolver
=
cx
.resolver
.borrow_mut
();
let
mark
=
Mark
::
root
();
if
let
Ok
(
def
)
=
resolver
.resolve_macro_to_def_inner
(
&
path
,
MacroKind
::
Bang
,
mark
,
&
[],
false
)
{
let
parent_scope
=
resolver
.dummy_parent_scope
();
if
let
Ok
(
def
)
=
resolver
.resolve_macro_to_def_inner
(
&
path
,
MacroKind
::
Bang
,
&
parent_scope
,
false
)
{
if
let
SyntaxExtension
::
DeclMacro
{
..
}
=
*
resolver
.get_macro
(
def
)
{
return
Some
(
def
);
}
...
...
src/libsyntax/ext/base.rs
浏览文件 @
1b6be5a1
...
...
@@ -730,7 +730,7 @@ fn find_legacy_attr_invoc(&mut self, attrs: &mut Vec<Attribute>, allow_derive: b
fn
resolve_macro_invocation
(
&
mut
self
,
invoc
:
&
Invocation
,
invoc_id
:
Mark
,
force
:
bool
)
->
Result
<
Option
<
Lrc
<
SyntaxExtension
>>
,
Determinacy
>
;
fn
resolve_macro_path
(
&
mut
self
,
path
:
&
ast
::
Path
,
kind
:
MacroKind
,
invoc_id
:
Mark
,
derives_in_scope
:
&
[
ast
::
Path
]
,
force
:
bool
)
derives_in_scope
:
Vec
<
ast
::
Path
>
,
force
:
bool
)
->
Result
<
Lrc
<
SyntaxExtension
>
,
Determinacy
>
;
fn
check_unused_macros
(
&
self
);
...
...
@@ -768,7 +768,7 @@ fn resolve_macro_invocation(&mut self, _invoc: &Invocation, _invoc_id: Mark, _fo
Err
(
Determinacy
::
Determined
)
}
fn
resolve_macro_path
(
&
mut
self
,
_
path
:
&
ast
::
Path
,
_
kind
:
MacroKind
,
_
invoc_id
:
Mark
,
_
derives_in_scope
:
&
[
ast
::
Path
]
,
_
force
:
bool
)
_
derives_in_scope
:
Vec
<
ast
::
Path
>
,
_
force
:
bool
)
->
Result
<
Lrc
<
SyntaxExtension
>
,
Determinacy
>
{
Err
(
Determinacy
::
Determined
)
}
...
...
src/libsyntax/ext/expand.rs
浏览文件 @
1b6be5a1
...
...
@@ -384,7 +384,7 @@ fn expand_fragment(&mut self, input_fragment: AstFragment) -> AstFragment {
let
mark
=
Mark
::
fresh
(
self
.cx.current_expansion.mark
);
derives
.push
(
mark
);
let
item
=
match
self
.cx.resolver
.resolve_macro_path
(
path
,
MacroKind
::
Derive
,
Mark
::
root
(),
&
[]
,
false
)
{
path
,
MacroKind
::
Derive
,
Mark
::
root
(),
Vec
::
new
()
,
false
)
{
Ok
(
ext
)
=>
match
*
ext
{
BuiltinDerive
(
..
)
=>
item_with_markers
.clone
(),
_
=>
item
.clone
(),
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录