Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
179ce18c
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,发现更多精彩内容 >>
提交
179ce18c
编写于
1月 24, 2022
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve/metadata: Stop encoding macros as reexports
上级
50568b8e
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
47 addition
and
23 deletion
+47
-23
compiler/rustc_metadata/src/rmeta/decoder.rs
compiler/rustc_metadata/src/rmeta/decoder.rs
+23
-8
compiler/rustc_middle/src/metadata.rs
compiler/rustc_middle/src/metadata.rs
+2
-0
compiler/rustc_resolve/src/access_levels.rs
compiler/rustc_resolve/src/access_levels.rs
+3
-2
compiler/rustc_resolve/src/build_reduced_graph.rs
compiler/rustc_resolve/src/build_reduced_graph.rs
+4
-2
compiler/rustc_resolve/src/imports.rs
compiler/rustc_resolve/src/imports.rs
+15
-7
compiler/rustc_resolve/src/lib.rs
compiler/rustc_resolve/src/lib.rs
+0
-4
未找到文件。
compiler/rustc_metadata/src/rmeta/decoder.rs
浏览文件 @
179ce18c
...
...
@@ -1077,6 +1077,7 @@ fn for_each_module_child(
res
,
vis
:
ty
::
Visibility
::
Public
,
span
:
ident
.span
,
macro_rules
:
false
,
});
}
}
...
...
@@ -1088,17 +1089,19 @@ fn for_each_module_child(
for
child_index
in
children
.decode
((
self
,
sess
))
{
if
let
Some
(
ident
)
=
self
.opt_item_ident
(
child_index
,
sess
)
{
let
kind
=
self
.def_kind
(
child_index
);
if
matches!
(
kind
,
DefKind
::
Macro
(
..
))
{
// FIXME: Macros are currently encoded twice, once as items and once as
// reexports. We ignore the items here and only use the reexports.
continue
;
}
let
def_id
=
self
.local_def_id
(
child_index
);
let
res
=
Res
::
Def
(
kind
,
def_id
);
let
vis
=
self
.get_visibility
(
child_index
);
let
span
=
self
.get_span
(
child_index
,
sess
);
let
macro_rules
=
match
kind
{
DefKind
::
Macro
(
..
)
=>
match
self
.kind
(
child_index
)
{
EntryKind
::
MacroDef
(
_
,
macro_rules
)
=>
macro_rules
,
_
=>
unreachable!
(),
},
_
=>
false
,
};
callback
(
ModChild
{
ident
,
res
,
vis
,
span
});
callback
(
ModChild
{
ident
,
res
,
vis
,
span
,
macro_rules
});
// For non-re-export structs and variants add their constructors to children.
// Re-export lists automatically contain constructors when necessary.
...
...
@@ -1110,7 +1113,13 @@ fn for_each_module_child(
let
ctor_res
=
Res
::
Def
(
DefKind
::
Ctor
(
CtorOf
::
Struct
,
ctor_kind
),
ctor_def_id
);
let
vis
=
self
.get_visibility
(
ctor_def_id
.index
);
callback
(
ModChild
{
ident
,
res
:
ctor_res
,
vis
,
span
});
callback
(
ModChild
{
ident
,
res
:
ctor_res
,
vis
,
span
,
macro_rules
:
false
,
});
}
}
DefKind
::
Variant
=>
{
...
...
@@ -1135,7 +1144,13 @@ fn for_each_module_child(
vis
=
ty
::
Visibility
::
Restricted
(
crate_def_id
);
}
}
callback
(
ModChild
{
ident
,
res
:
ctor_res
,
vis
,
span
});
callback
(
ModChild
{
ident
,
res
:
ctor_res
,
vis
,
span
,
macro_rules
:
false
,
});
}
_
=>
{}
}
...
...
compiler/rustc_middle/src/metadata.rs
浏览文件 @
179ce18c
...
...
@@ -21,4 +21,6 @@ pub struct ModChild {
pub
vis
:
ty
::
Visibility
,
/// Span of the item.
pub
span
:
Span
,
/// A proper `macro_rules` item (not a reexport).
pub
macro_rules
:
bool
,
}
compiler/rustc_resolve/src/access_levels.rs
浏览文件 @
179ce18c
...
...
@@ -133,7 +133,7 @@ fn visit_item(&mut self, item: &'ast ast::Item) {
ast
::
ItemKind
::
Impl
(
..
)
=>
return
,
// Only exported `macro_rules!` items are public, but they always are
ast
::
ItemKind
::
MacroDef
(
..
)
=>
{
ast
::
ItemKind
::
MacroDef
(
ref
macro_def
)
if
macro_def
.macro_rules
=>
{
let
is_macro_export
=
item
.attrs
.iter
()
.any
(|
attr
|
attr
.has_name
(
sym
::
macro_export
));
if
is_macro_export
{
Some
(
AccessLevel
::
Public
)
}
else
{
None
}
...
...
@@ -155,7 +155,8 @@ fn visit_item(&mut self, item: &'ast ast::Item) {
|
ast
::
ItemKind
::
Struct
(
..
)
|
ast
::
ItemKind
::
Union
(
..
)
|
ast
::
ItemKind
::
Trait
(
..
)
|
ast
::
ItemKind
::
TraitAlias
(
..
)
=>
{
|
ast
::
ItemKind
::
TraitAlias
(
..
)
|
ast
::
ItemKind
::
MacroDef
(
..
)
=>
{
if
item
.vis.kind
.is_pub
()
{
self
.prev_level
}
else
{
...
...
compiler/rustc_resolve/src/build_reduced_graph.rs
浏览文件 @
179ce18c
...
...
@@ -940,7 +940,7 @@ fn build_reduced_graph_for_block(&mut self, block: &Block) {
/// Builds the reduced graph for a single item in an external crate.
fn
build_reduced_graph_for_external_crate_res
(
&
mut
self
,
child
:
ModChild
)
{
let
parent
=
self
.parent_scope.module
;
let
ModChild
{
ident
,
res
,
vis
,
span
}
=
child
;
let
ModChild
{
ident
,
res
,
vis
,
span
,
macro_rules
}
=
child
;
let
res
=
res
.expect_non_local
();
let
expansion
=
self
.parent_scope.expansion
;
// Record primary definitions.
...
...
@@ -972,8 +972,10 @@ fn build_reduced_graph_for_external_crate_res(&mut self, child: ModChild) {
_
,
)
=>
self
.r
.define
(
parent
,
ident
,
ValueNS
,
(
res
,
vis
,
span
,
expansion
)),
Res
::
Def
(
DefKind
::
Macro
(
..
),
_
)
|
Res
::
NonMacroAttr
(
..
)
=>
{
if
!
macro_rules
{
self
.r
.define
(
parent
,
ident
,
MacroNS
,
(
res
,
vis
,
span
,
expansion
))
}
}
Res
::
Def
(
DefKind
::
TyParam
|
DefKind
::
ConstParam
...
...
compiler/rustc_resolve/src/imports.rs
浏览文件 @
179ce18c
...
...
@@ -1399,14 +1399,22 @@ fn finalize_resolutions_in(&mut self, module: Module<'b>) {
let
mut
reexports
=
Vec
::
new
();
module
.for_each_child
(
self
.r
,
|
_
,
ident
,
_
,
binding
|
{
// F
ilter away ambiguous imports and anything that has def-site hygiene.
//
FIXME: Implement actual cross-crate hygiene
.
let
is_good_import
=
binding
.is_import
()
&&
!
binding
.is_ambiguity
()
&&
!
ident
.span
.from_expansion
();
if
is_good_import
||
binding
.is_macro_def
()
{
// F
IXME: Consider changing the binding inserted by `#[macro_export] macro_rules`
//
into the crate root to actual `NameBindingKind::Import`
.
if
binding
.is_import
()
||
matches!
(
binding
.kind
,
NameBindingKind
::
Res
(
_
,
_
is_macro_export
@
true
))
{
let
res
=
binding
.res
()
.expect_non_local
();
if
res
!=
def
::
Res
::
Err
{
reexports
.push
(
ModChild
{
ident
,
res
,
vis
:
binding
.vis
,
span
:
binding
.span
});
// Ambiguous imports are treated as errors at this point and are
// not exposed to other crates (see #36837 for more details).
if
res
!=
def
::
Res
::
Err
&&
!
binding
.is_ambiguity
()
{
reexports
.push
(
ModChild
{
ident
,
res
,
vis
:
binding
.vis
,
span
:
binding
.span
,
macro_rules
:
false
,
});
}
}
});
...
...
compiler/rustc_resolve/src/lib.rs
浏览文件 @
179ce18c
...
...
@@ -845,10 +845,6 @@ fn is_importable(&self) -> bool {
)
}
fn
is_macro_def
(
&
self
)
->
bool
{
matches!
(
self
.kind
,
NameBindingKind
::
Res
(
Res
::
Def
(
DefKind
::
Macro
(
..
),
_
),
_
))
}
fn
macro_kind
(
&
self
)
->
Option
<
MacroKind
>
{
self
.res
()
.macro_kind
()
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录