Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f1359c61
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,发现更多精彩内容 >>
提交
f1359c61
编写于
11月 23, 2019
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
expand: Fully preserve visibilities on unnamed fields with attributes
上级
37bb0c7f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
37 addition
and
4 deletion
+37
-4
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+3
-0
src/libsyntax_expand/expand.rs
src/libsyntax_expand/expand.rs
+20
-2
src/libsyntax_expand/placeholders.rs
src/libsyntax_expand/placeholders.rs
+3
-2
src/test/ui/attributes/unnamed-field-attributes-vis.rs
src/test/ui/attributes/unnamed-field-attributes-vis.rs
+11
-0
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
f1359c61
...
...
@@ -746,6 +746,9 @@ fn build_reduced_graph_for_item(&mut self, item: &'b Item) {
// Record field names for error reporting.
let
field_names
=
struct_def
.fields
()
.iter
()
.map
(|
field
|
{
// NOTE: The field may be an expansion placeholder, but expansion sets correct
// visibilities for unnamed field placeholders specifically, so the constructor
// visibility should still be determined correctly.
let
field_vis
=
self
.resolve_visibility
(
&
field
.vis
);
if
ctor_vis
.is_at_least
(
field_vis
,
&*
self
.r
)
{
ctor_vis
=
field_vis
;
...
...
src/libsyntax_expand/expand.rs
浏览文件 @
f1359c61
...
...
@@ -86,7 +86,7 @@ pub fn add_placeholders(&mut self, placeholders: &[NodeId]) {
// mention some macro variable from those arguments even if it's not used.
#[cfg_attr(bootstrap,
allow(unused_macros))]
macro
_
repeating
(
$flat_map_ast_elt
)
{}
placeholder
(
AstFragmentKind
::
$Kind
,
*
id
)
.
$make_ast
()
placeholder
(
AstFragmentKind
::
$Kind
,
*
id
,
None
)
.
$make_ast
()
})),)
?
)
*
_
=>
panic!
(
"unexpected AST fragment kind"
)
}
...
...
@@ -275,6 +275,23 @@ pub enum InvocationKind {
},
}
impl
InvocationKind
{
fn
placeholder_visibility
(
&
self
)
->
Option
<
ast
::
Visibility
>
{
// HACK: For unnamed fields placeholders should have the same visibility as the actual
// fields because for tuple structs/variants resolve determines visibilities of their
// constructor using these field visibilities before attributes on them are are expanded.
// The assumption is that the attribute expansion cannot change field visibilities,
// and it holds because only inert attributes are supported in this position.
match
self
{
InvocationKind
::
Attr
{
item
:
Annotatable
::
StructField
(
field
),
..
}
|
InvocationKind
::
Derive
{
item
:
Annotatable
::
StructField
(
field
),
..
}
|
InvocationKind
::
DeriveContainer
{
item
:
Annotatable
::
StructField
(
field
),
..
}
if
field
.ident
.is_none
()
=>
Some
(
field
.vis
.clone
()),
_
=>
None
,
}
}
}
impl
Invocation
{
pub
fn
span
(
&
self
)
->
Span
{
match
&
self
.kind
{
...
...
@@ -931,6 +948,7 @@ fn collect(&mut self, fragment_kind: AstFragmentKind, kind: InvocationKind) -> A
_
=>
None
,
};
let
expn_id
=
ExpnId
::
fresh
(
expn_data
);
let
vis
=
kind
.placeholder_visibility
();
self
.invocations
.push
(
Invocation
{
kind
,
fragment_kind
,
...
...
@@ -940,7 +958,7 @@ fn collect(&mut self, fragment_kind: AstFragmentKind, kind: InvocationKind) -> A
..
self
.cx.current_expansion
.clone
()
},
});
placeholder
(
fragment_kind
,
NodeId
::
placeholder_from_expn_id
(
expn_id
))
placeholder
(
fragment_kind
,
NodeId
::
placeholder_from_expn_id
(
expn_id
)
,
vis
)
}
fn
collect_bang
(
&
mut
self
,
mac
:
ast
::
Mac
,
span
:
Span
,
kind
:
AstFragmentKind
)
->
AstFragment
{
...
...
src/libsyntax_expand/placeholders.rs
浏览文件 @
f1359c61
...
...
@@ -12,7 +12,8 @@
use
rustc_data_structures
::
fx
::
FxHashMap
;
pub
fn
placeholder
(
kind
:
AstFragmentKind
,
id
:
ast
::
NodeId
)
->
AstFragment
{
pub
fn
placeholder
(
kind
:
AstFragmentKind
,
id
:
ast
::
NodeId
,
vis
:
Option
<
ast
::
Visibility
>
)
->
AstFragment
{
fn
mac_placeholder
()
->
ast
::
Mac
{
ast
::
Mac
{
path
:
ast
::
Path
{
span
:
DUMMY_SP
,
segments
:
Vec
::
new
()
},
...
...
@@ -26,7 +27,7 @@ fn mac_placeholder() -> ast::Mac {
let
ident
=
ast
::
Ident
::
invalid
();
let
attrs
=
Vec
::
new
();
let
generics
=
ast
::
Generics
::
default
();
let
vis
=
dummy_spanned
(
ast
::
VisibilityKind
::
Inherited
);
let
vis
=
vis
.unwrap_or_else
(||
dummy_spanned
(
ast
::
VisibilityKind
::
Inherited
)
);
let
span
=
DUMMY_SP
;
let
expr_placeholder
=
||
P
(
ast
::
Expr
{
id
,
span
,
...
...
src/test/ui/attributes/unnamed-field-attributes-vis.rs
0 → 100644
浏览文件 @
f1359c61
// Unnamed fields don't lose their visibility due to non-builtin attributes on them.
// check-pass
mod
m
{
pub
struct
S
(
#[rustfmt::skip]
pub
u8
);
}
fn
main
()
{
m
::
S
(
0
);
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录