Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8b60b948
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,发现更多精彩内容 >>
提交
8b60b948
编写于
2月 26, 2016
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get rid of hir::StructFieldKind
上级
0400d929
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
80 addition
and
119 deletion
+80
-119
src/librustc/front/map/collector.rs
src/librustc/front/map/collector.rs
+2
-2
src/librustc/front/map/definitions.rs
src/librustc/front/map/definitions.rs
+4
-10
src/librustc/middle/dead.rs
src/librustc/middle/dead.rs
+3
-6
src/librustc_front/fold.rs
src/librustc_front/fold.rs
+3
-2
src/librustc_front/hir.rs
src/librustc_front/hir.rs
+31
-31
src/librustc_front/intravisit.rs
src/librustc_front/intravisit.rs
+1
-1
src/librustc_front/lowering.rs
src/librustc_front/lowering.rs
+2
-10
src/librustc_front/print/pprust.rs
src/librustc_front/print/pprust.rs
+11
-21
src/librustc_lint/bad_style.rs
src/librustc_lint/bad_style.rs
+1
-1
src/librustc_lint/builtin.rs
src/librustc_lint/builtin.rs
+2
-2
src/librustc_privacy/lib.rs
src/librustc_privacy/lib.rs
+4
-7
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+2
-9
src/librustc_typeck/collect.rs
src/librustc_typeck/collect.rs
+14
-17
未找到文件。
src/librustc/front/map/collector.rs
浏览文件 @
8b60b948
...
@@ -151,7 +151,7 @@ fn visit_item(&mut self, i: &'ast Item) {
...
@@ -151,7 +151,7 @@ fn visit_item(&mut self, i: &'ast Item) {
self
.create_def_with_parent
(
self
.create_def_with_parent
(
Some
(
variant_def_index
),
Some
(
variant_def_index
),
field
.node.id
,
field
.node.id
,
DefPathData
::
Field
(
field
.node.
kind
));
DefPathData
::
Field
(
field
.node.
name
));
}
}
}
}
}
}
...
@@ -166,7 +166,7 @@ fn visit_item(&mut self, i: &'ast Item) {
...
@@ -166,7 +166,7 @@ fn visit_item(&mut self, i: &'ast Item) {
}
}
for
field
in
struct_def
.fields
()
{
for
field
in
struct_def
.fields
()
{
self
.create_def
(
field
.node.id
,
DefPathData
::
Field
(
field
.node.
kind
));
self
.create_def
(
field
.node.id
,
DefPathData
::
Field
(
field
.node.
name
));
}
}
}
}
ItemTrait
(
_
,
_
,
ref
bounds
,
_
)
=>
{
ItemTrait
(
_
,
_
,
ref
bounds
,
_
)
=>
{
...
...
src/librustc/front/map/definitions.rs
浏览文件 @
8b60b948
...
@@ -11,7 +11,6 @@
...
@@ -11,7 +11,6 @@
use
middle
::
cstore
::
LOCAL_CRATE
;
use
middle
::
cstore
::
LOCAL_CRATE
;
use
middle
::
def_id
::{
DefId
,
DefIndex
};
use
middle
::
def_id
::{
DefId
,
DefIndex
};
use
rustc_data_structures
::
fnv
::
FnvHashMap
;
use
rustc_data_structures
::
fnv
::
FnvHashMap
;
use
rustc_front
::
hir
;
use
syntax
::
ast
;
use
syntax
::
ast
;
use
syntax
::
parse
::
token
::
InternedString
;
use
syntax
::
parse
::
token
::
InternedString
;
use
util
::
nodemap
::
NodeMap
;
use
util
::
nodemap
::
NodeMap
;
...
@@ -84,8 +83,7 @@ pub enum DefPathData {
...
@@ -84,8 +83,7 @@ pub enum DefPathData {
TypeParam
(
ast
::
Name
),
TypeParam
(
ast
::
Name
),
LifetimeDef
(
ast
::
Name
),
LifetimeDef
(
ast
::
Name
),
EnumVariant
(
ast
::
Name
),
EnumVariant
(
ast
::
Name
),
PositionalField
,
Field
(
Option
<
ast
::
Name
>
),
Field
(
hir
::
StructFieldKind
),
StructCtor
,
// implicit ctor for a tuple-like struct
StructCtor
,
// implicit ctor for a tuple-like struct
Initializer
,
// initializer for a const
Initializer
,
// initializer for a const
Binding
(
ast
::
Name
),
// pattern binding
Binding
(
ast
::
Name
),
// pattern binding
...
@@ -186,16 +184,12 @@ pub fn as_interned_str(&self) -> InternedString {
...
@@ -186,16 +184,12 @@ pub fn as_interned_str(&self) -> InternedString {
LifetimeDef
(
name
)
|
LifetimeDef
(
name
)
|
EnumVariant
(
name
)
|
EnumVariant
(
name
)
|
DetachedCrate
(
name
)
|
DetachedCrate
(
name
)
|
Binding
(
name
)
=>
{
Binding
(
name
)
|
Field
(
Some
(
name
))
=>
{
name
.as_str
()
name
.as_str
()
}
}
Field
(
hir
::
StructFieldKind
::
NamedField
(
name
,
_
))
=>
{
Field
(
None
)
=>
{
name
.as_str
()
}
PositionalField
|
Field
(
hir
::
StructFieldKind
::
UnnamedField
(
_
))
=>
{
InternedString
::
new
(
"{{field}}"
)
InternedString
::
new
(
"{{field}}"
)
}
}
...
...
src/librustc/middle/dead.rs
浏览文件 @
8b60b948
...
@@ -221,10 +221,7 @@ fn visit_variant_data(&mut self, def: &hir::VariantData, _: ast::Name,
...
@@ -221,10 +221,7 @@ fn visit_variant_data(&mut self, def: &hir::VariantData, _: ast::Name,
let
has_extern_repr
=
self
.struct_has_extern_repr
;
let
has_extern_repr
=
self
.struct_has_extern_repr
;
let
inherited_pub_visibility
=
self
.inherited_pub_visibility
;
let
inherited_pub_visibility
=
self
.inherited_pub_visibility
;
let
live_fields
=
def
.fields
()
.iter
()
.filter
(|
f
|
{
let
live_fields
=
def
.fields
()
.iter
()
.filter
(|
f
|
{
has_extern_repr
||
inherited_pub_visibility
||
match
f
.node.kind
{
has_extern_repr
||
inherited_pub_visibility
||
f
.node.vis
==
hir
::
Public
hir
::
NamedField
(
_
,
hir
::
Public
)
=>
true
,
_
=>
false
}
});
});
self
.live_symbols
.extend
(
live_fields
.map
(|
f
|
f
.node.id
));
self
.live_symbols
.extend
(
live_fields
.map
(|
f
|
f
.node.id
));
...
@@ -432,7 +429,7 @@ fn should_warn_about_item(&mut self, item: &hir::Item) -> bool {
...
@@ -432,7 +429,7 @@ fn should_warn_about_item(&mut self, item: &hir::Item) -> bool {
}
}
fn
should_warn_about_field
(
&
mut
self
,
node
:
&
hir
::
StructField_
)
->
bool
{
fn
should_warn_about_field
(
&
mut
self
,
node
:
&
hir
::
StructField_
)
->
bool
{
let
is_named
=
node
.name
()
.is_some
();
let
is_named
=
node
.name
.is_some
();
let
field_type
=
self
.tcx
.node_id_to_type
(
node
.id
);
let
field_type
=
self
.tcx
.node_id_to_type
(
node
.id
);
let
is_marker_field
=
match
field_type
.ty_to_def_id
()
{
let
is_marker_field
=
match
field_type
.ty_to_def_id
()
{
Some
(
def_id
)
=>
self
.tcx.lang_items
.items
()
.iter
()
.any
(|
item
|
*
item
==
Some
(
def_id
)),
Some
(
def_id
)
=>
self
.tcx.lang_items
.items
()
.iter
()
.any
(|
item
|
*
item
==
Some
(
def_id
)),
...
@@ -549,7 +546,7 @@ fn visit_foreign_item(&mut self, fi: &hir::ForeignItem) {
...
@@ -549,7 +546,7 @@ fn visit_foreign_item(&mut self, fi: &hir::ForeignItem) {
fn
visit_struct_field
(
&
mut
self
,
field
:
&
hir
::
StructField
)
{
fn
visit_struct_field
(
&
mut
self
,
field
:
&
hir
::
StructField
)
{
if
self
.should_warn_about_field
(
&
field
.node
)
{
if
self
.should_warn_about_field
(
&
field
.node
)
{
self
.warn_dead_code
(
field
.node.id
,
field
.span
,
self
.warn_dead_code
(
field
.node.id
,
field
.span
,
field
.node
.name
()
.unwrap
(),
"struct field"
);
field
.node.name
.unwrap
(),
"struct field"
);
}
}
intravisit
::
walk_struct_field
(
self
,
field
);
intravisit
::
walk_struct_field
(
self
,
field
);
...
...
src/librustc_front/fold.rs
浏览文件 @
8b60b948
...
@@ -700,11 +700,12 @@ pub fn noop_fold_poly_trait_ref<T: Folder>(p: PolyTraitRef, fld: &mut T) -> Poly
...
@@ -700,11 +700,12 @@ pub fn noop_fold_poly_trait_ref<T: Folder>(p: PolyTraitRef, fld: &mut T) -> Poly
}
}
pub
fn
noop_fold_struct_field
<
T
:
Folder
>
(
f
:
StructField
,
fld
:
&
mut
T
)
->
StructField
{
pub
fn
noop_fold_struct_field
<
T
:
Folder
>
(
f
:
StructField
,
fld
:
&
mut
T
)
->
StructField
{
let
StructField
{
node
:
StructField_
{
id
,
kind
,
ty
,
attrs
},
span
}
=
f
;
let
StructField
{
node
:
StructField_
{
id
,
name
,
vis
,
ty
,
attrs
},
span
}
=
f
;
Spanned
{
Spanned
{
node
:
StructField_
{
node
:
StructField_
{
id
:
fld
.new_id
(
id
),
id
:
fld
.new_id
(
id
),
kind
:
kind
,
name
:
name
,
vis
:
vis
,
ty
:
fld
.fold_ty
(
ty
),
ty
:
fld
.fold_ty
(
ty
),
attrs
:
fold_attrs
(
attrs
,
fld
),
attrs
:
fold_attrs
(
attrs
,
fld
),
},
},
...
...
src/librustc_front/hir.rs
浏览文件 @
8b60b948
...
@@ -24,7 +24,6 @@
...
@@ -24,7 +24,6 @@
pub
use
self
::
PathListItem_
::
*
;
pub
use
self
::
PathListItem_
::
*
;
pub
use
self
::
PrimTy
::
*
;
pub
use
self
::
PrimTy
::
*
;
pub
use
self
::
Stmt_
::
*
;
pub
use
self
::
Stmt_
::
*
;
pub
use
self
::
StructFieldKind
::
*
;
pub
use
self
::
TraitItem_
::
*
;
pub
use
self
::
TraitItem_
::
*
;
pub
use
self
::
Ty_
::
*
;
pub
use
self
::
Ty_
::
*
;
pub
use
self
::
TyParamBound
::
*
;
pub
use
self
::
TyParamBound
::
*
;
...
@@ -1243,44 +1242,45 @@ pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
...
@@ -1243,44 +1242,45 @@ pub fn inherit_from(&self, parent_visibility: Visibility) -> Visibility {
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug)]
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug)]
pub
struct
StructField_
{
pub
struct
StructField_
{
pub
kind
:
StructFieldKind
,
pub
name
:
Option
<
Name
>
,
pub
vis
:
Visibility
,
pub
id
:
NodeId
,
pub
id
:
NodeId
,
pub
ty
:
P
<
Ty
>
,
pub
ty
:
P
<
Ty
>
,
pub
attrs
:
HirVec
<
Attribute
>
,
pub
attrs
:
HirVec
<
Attribute
>
,
}
}
impl
StructField_
{
//
impl StructField_ {
pub
fn
name
(
&
self
)
->
Option
<
Name
>
{
//
pub fn name(&self) -> Option<Name> {
match
self
.kind
{
//
match self.kind {
NamedField
(
name
,
_
)
=>
Some
(
name
),
//
NamedField(name, _) => Some(name),
UnnamedField
(
_
)
=>
None
,
//
UnnamedField(_) => None,
}
//
}
}
//
}
}
//
}
pub
type
StructField
=
Spanned
<
StructField_
>
;
pub
type
StructField
=
Spanned
<
StructField_
>
;
#[derive(Clone,
PartialEq,
Eq,
RustcEncodable,
RustcDecodable,
Hash,
Debug,
Copy)]
//
#[derive(Clone, PartialEq, Eq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
pub
enum
StructFieldKind
{
//
pub enum StructFieldKind {
NamedField
(
Name
,
Visibility
),
//
NamedField(Name, Visibility),
/// Element of a tuple-like struct
//
/// Element of a tuple-like struct
UnnamedField
(
Visibility
),
//
UnnamedField(Visibility),
}
//
}
impl
StructFieldKind
{
//
impl StructFieldKind {
pub
fn
is_unnamed
(
&
self
)
->
bool
{
//
pub fn is_unnamed(&self) -> bool {
match
*
self
{
//
match *self {
UnnamedField
(
..
)
=>
true
,
//
UnnamedField(..) => true,
NamedField
(
..
)
=>
false
,
//
NamedField(..) => false,
}
//
}
}
//
}
pub
fn
visibility
(
&
self
)
->
Visibility
{
//
pub fn visibility(&self) -> Visibility {
match
*
self
{
//
match *self {
NamedField
(
_
,
vis
)
|
UnnamedField
(
vis
)
=>
vis
,
//
NamedField(_, vis) | UnnamedField(vis) => vis,
}
//
}
}
//
}
}
//
}
/// Fields and Ids of enum variants and structs
/// Fields and Ids of enum variants and structs
///
///
...
...
src/librustc_front/intravisit.rs
浏览文件 @
8b60b948
...
@@ -669,7 +669,7 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &
...
@@ -669,7 +669,7 @@ pub fn walk_struct_def<'v, V: Visitor<'v>>(visitor: &mut V, struct_definition: &
}
}
pub
fn
walk_struct_field
<
'v
,
V
:
Visitor
<
'v
>>
(
visitor
:
&
mut
V
,
struct_field
:
&
'v
StructField
)
{
pub
fn
walk_struct_field
<
'v
,
V
:
Visitor
<
'v
>>
(
visitor
:
&
mut
V
,
struct_field
:
&
'v
StructField
)
{
walk_opt_name
(
visitor
,
struct_field
.span
,
struct_field
.node
.name
()
);
walk_opt_name
(
visitor
,
struct_field
.span
,
struct_field
.node.name
);
visitor
.visit_ty
(
&
struct_field
.node.ty
);
visitor
.visit_ty
(
&
struct_field
.node.ty
);
walk_list!
(
visitor
,
visit_attribute
,
&
struct_field
.node.attrs
);
walk_list!
(
visitor
,
visit_attribute
,
&
struct_field
.node.attrs
);
}
}
...
...
src/librustc_front/lowering.rs
浏览文件 @
8b60b948
...
@@ -611,7 +611,8 @@ pub fn lower_struct_field(lctx: &LoweringContext, f: &StructField) -> hir::Struc
...
@@ -611,7 +611,8 @@ pub fn lower_struct_field(lctx: &LoweringContext, f: &StructField) -> hir::Struc
Spanned
{
Spanned
{
node
:
hir
::
StructField_
{
node
:
hir
::
StructField_
{
id
:
f
.node.id
,
id
:
f
.node.id
,
kind
:
lower_struct_field_kind
(
lctx
,
&
f
.node.kind
),
name
:
f
.node
.ident
()
.map
(|
ident
|
ident
.name
),
vis
:
lower_visibility
(
lctx
,
f
.node.kind
.visibility
()),
ty
:
lower_ty
(
lctx
,
&
f
.node.ty
),
ty
:
lower_ty
(
lctx
,
&
f
.node.ty
),
attrs
:
lower_attrs
(
lctx
,
&
f
.node.attrs
),
attrs
:
lower_attrs
(
lctx
,
&
f
.node.attrs
),
},
},
...
@@ -1589,15 +1590,6 @@ pub fn lower_binding_mode(lctx: &LoweringContext, b: &BindingMode) -> hir::Bindi
...
@@ -1589,15 +1590,6 @@ pub fn lower_binding_mode(lctx: &LoweringContext, b: &BindingMode) -> hir::Bindi
}
}
}
}
pub
fn
lower_struct_field_kind
(
lctx
:
&
LoweringContext
,
s
:
&
StructFieldKind
)
->
hir
::
StructFieldKind
{
match
*
s
{
NamedField
(
ident
,
vis
)
=>
hir
::
NamedField
(
ident
.name
,
lower_visibility
(
lctx
,
vis
)),
UnnamedField
(
vis
)
=>
hir
::
UnnamedField
(
lower_visibility
(
lctx
,
vis
)),
}
}
pub
fn
lower_unsafe_source
(
_
lctx
:
&
LoweringContext
,
u
:
UnsafeSource
)
->
hir
::
UnsafeSource
{
pub
fn
lower_unsafe_source
(
_
lctx
:
&
LoweringContext
,
u
:
UnsafeSource
)
->
hir
::
UnsafeSource
{
match
u
{
match
u
{
CompilerGenerated
=>
hir
::
CompilerGenerated
,
CompilerGenerated
=>
hir
::
CompilerGenerated
,
...
...
src/librustc_front/print/pprust.rs
浏览文件 @
8b60b948
...
@@ -915,14 +915,9 @@ pub fn print_struct(&mut self,
...
@@ -915,14 +915,9 @@ pub fn print_struct(&mut self,
if
struct_def
.is_tuple
()
{
if
struct_def
.is_tuple
()
{
try!
(
self
.popen
());
try!
(
self
.popen
());
try!
(
self
.commasep
(
Inconsistent
,
struct_def
.fields
(),
|
s
,
field
|
{
try!
(
self
.commasep
(
Inconsistent
,
struct_def
.fields
(),
|
s
,
field
|
{
match
field
.node.kind
{
try!
(
s
.print_visibility
(
field
.node.vis
));
hir
::
NamedField
(
..
)
=>
panic!
(
"unexpected named field"
),
try!
(
s
.maybe_print_comment
(
field
.span.lo
));
hir
::
UnnamedField
(
vis
)
=>
{
s
.print_type
(
&
field
.node.ty
)
try!
(
s
.print_visibility
(
vis
));
try!
(
s
.maybe_print_comment
(
field
.span.lo
));
s
.print_type
(
&
field
.node.ty
)
}
}
}));
}));
try!
(
self
.pclose
());
try!
(
self
.pclose
());
}
}
...
@@ -939,19 +934,14 @@ pub fn print_struct(&mut self,
...
@@ -939,19 +934,14 @@ pub fn print_struct(&mut self,
try!
(
self
.hardbreak_if_not_bol
());
try!
(
self
.hardbreak_if_not_bol
());
for
field
in
struct_def
.fields
()
{
for
field
in
struct_def
.fields
()
{
match
field
.node.kind
{
try!
(
self
.hardbreak_if_not_bol
());
hir
::
UnnamedField
(
..
)
=>
panic!
(
"unexpected unnamed field"
),
try!
(
self
.maybe_print_comment
(
field
.span.lo
));
hir
::
NamedField
(
name
,
visibility
)
=>
{
try!
(
self
.print_outer_attributes
(
&
field
.node.attrs
));
try!
(
self
.hardbreak_if_not_bol
());
try!
(
self
.print_visibility
(
field
.node.vis
));
try!
(
self
.maybe_print_comment
(
field
.span.lo
));
try!
(
self
.print_name
(
field
.node.name
.unwrap
()));
try!
(
self
.print_outer_attributes
(
&
field
.node.attrs
));
try!
(
self
.word_nbsp
(
":"
));
try!
(
self
.print_visibility
(
visibility
));
try!
(
self
.print_type
(
&
field
.node.ty
));
try!
(
self
.print_name
(
name
));
try!
(
word
(
&
mut
self
.s
,
","
));
try!
(
self
.word_nbsp
(
":"
));
try!
(
self
.print_type
(
&
field
.node.ty
));
try!
(
word
(
&
mut
self
.s
,
","
));
}
}
}
}
self
.bclose
(
span
)
self
.bclose
(
span
)
...
...
src/librustc_lint/bad_style.rs
浏览文件 @
8b60b948
...
@@ -283,7 +283,7 @@ fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
...
@@ -283,7 +283,7 @@ fn check_pat(&mut self, cx: &LateContext, p: &hir::Pat) {
fn
check_struct_def
(
&
mut
self
,
cx
:
&
LateContext
,
s
:
&
hir
::
VariantData
,
fn
check_struct_def
(
&
mut
self
,
cx
:
&
LateContext
,
s
:
&
hir
::
VariantData
,
_
:
ast
::
Name
,
_
:
&
hir
::
Generics
,
_
:
ast
::
NodeId
)
{
_
:
ast
::
Name
,
_
:
&
hir
::
Generics
,
_
:
ast
::
NodeId
)
{
for
sf
in
s
.fields
()
{
for
sf
in
s
.fields
()
{
if
let
hir
::
StructField_
{
kind
:
hir
::
NamedField
(
name
,
_
),
..
}
=
sf
.nod
e
{
if
let
Some
(
name
)
=
sf
.node.nam
e
{
self
.check_snake_case
(
cx
,
"structure field"
,
&
name
.as_str
(),
self
.check_snake_case
(
cx
,
"structure field"
,
&
name
.as_str
(),
Some
(
sf
.span
));
Some
(
sf
.span
));
}
}
...
...
src/librustc_lint/builtin.rs
浏览文件 @
8b60b948
...
@@ -428,8 +428,8 @@ fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) {
...
@@ -428,8 +428,8 @@ fn check_impl_item(&mut self, cx: &LateContext, impl_item: &hir::ImplItem) {
}
}
fn
check_struct_field
(
&
mut
self
,
cx
:
&
LateContext
,
sf
:
&
hir
::
StructField
)
{
fn
check_struct_field
(
&
mut
self
,
cx
:
&
LateContext
,
sf
:
&
hir
::
StructField
)
{
if
let
hir
::
NamedField
(
_
,
vis
)
=
sf
.node.kind
{
if
sf
.node.name
.is_some
()
{
if
vis
==
hir
::
Public
||
self
.in_variant
{
if
sf
.node.
vis
==
hir
::
Public
||
self
.in_variant
{
let
cur_struct_def
=
*
self
.struct_def_stack
.last
()
let
cur_struct_def
=
*
self
.struct_def_stack
.last
()
.expect
(
"empty struct_def_stack"
);
.expect
(
"empty struct_def_stack"
);
self
.check_missing_docs_attrs
(
cx
,
Some
(
cur_struct_def
),
self
.check_missing_docs_attrs
(
cx
,
Some
(
cur_struct_def
),
...
...
src/librustc_privacy/lib.rs
浏览文件 @
8b60b948
...
@@ -288,7 +288,7 @@ fn visit_item(&mut self, item: &hir::Item) {
...
@@ -288,7 +288,7 @@ fn visit_item(&mut self, item: &hir::Item) {
self
.update
(
def
.id
(),
item_level
);
self
.update
(
def
.id
(),
item_level
);
}
}
for
field
in
def
.fields
()
{
for
field
in
def
.fields
()
{
if
field
.node.
kind
.visibility
()
==
hir
::
Public
{
if
field
.node.
vis
==
hir
::
Public
{
self
.update
(
field
.node.id
,
item_level
);
self
.update
(
field
.node.id
,
item_level
);
}
}
}
}
...
@@ -1178,7 +1178,7 @@ fn check_sane_privacy(&self, item: &hir::Item) {
...
@@ -1178,7 +1178,7 @@ fn check_sane_privacy(&self, item: &hir::Item) {
hir
::
ItemEnum
(
ref
def
,
_
)
=>
{
hir
::
ItemEnum
(
ref
def
,
_
)
=>
{
for
variant
in
&
def
.variants
{
for
variant
in
&
def
.variants
{
for
field
in
variant
.node.data
.fields
()
{
for
field
in
variant
.node.data
.fields
()
{
check_inherited
(
field
.span
,
field
.
node.kind
.visibility
()
,
check_inherited
(
field
.span
,
field
.
vis
,
"visibility qualifiers have no effect on variant fields"
);
"visibility qualifiers have no effect on variant fields"
);
}
}
}
}
...
@@ -1514,10 +1514,7 @@ fn visit_variant(&mut self, v: &hir::Variant, g: &hir::Generics, item_id: ast::N
...
@@ -1514,10 +1514,7 @@ fn visit_variant(&mut self, v: &hir::Variant, g: &hir::Generics, item_id: ast::N
}
}
fn
visit_struct_field
(
&
mut
self
,
s
:
&
hir
::
StructField
)
{
fn
visit_struct_field
(
&
mut
self
,
s
:
&
hir
::
StructField
)
{
let
vis
=
match
s
.node.kind
{
if
s
.node.vis
==
hir
::
Public
||
self
.in_variant
{
hir
::
NamedField
(
_
,
vis
)
|
hir
::
UnnamedField
(
vis
)
=>
vis
};
if
vis
==
hir
::
Public
||
self
.in_variant
{
intravisit
::
walk_struct_field
(
self
,
s
);
intravisit
::
walk_struct_field
(
self
,
s
);
}
}
}
}
...
@@ -1728,7 +1725,7 @@ fn visit_item(&mut self, item: &hir::Item) {
...
@@ -1728,7 +1725,7 @@ fn visit_item(&mut self, item: &hir::Item) {
if
item
.vis
==
hir
::
Public
{
if
item
.vis
==
hir
::
Public
{
check
.visit_generics
(
generics
);
check
.visit_generics
(
generics
);
for
field
in
struct_def
.fields
()
{
for
field
in
struct_def
.fields
()
{
if
field
.node.
kind
.visibility
()
==
hir
::
Public
{
if
field
.node.
vis
==
hir
::
Public
{
check
.visit_struct_field
(
field
);
check
.visit_struct_field
(
field
);
}
}
}
}
...
...
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
8b60b948
...
@@ -41,9 +41,7 @@
...
@@ -41,9 +41,7 @@
use
rustc_front
::
hir
::{
Item
,
ItemConst
,
ItemEnum
,
ItemExternCrate
,
ItemFn
};
use
rustc_front
::
hir
::{
Item
,
ItemConst
,
ItemEnum
,
ItemExternCrate
,
ItemFn
};
use
rustc_front
::
hir
::{
ItemForeignMod
,
ItemImpl
,
ItemMod
,
ItemStatic
,
ItemDefaultImpl
};
use
rustc_front
::
hir
::{
ItemForeignMod
,
ItemImpl
,
ItemMod
,
ItemStatic
,
ItemDefaultImpl
};
use
rustc_front
::
hir
::{
ItemStruct
,
ItemTrait
,
ItemTy
,
ItemUse
};
use
rustc_front
::
hir
::{
ItemStruct
,
ItemTrait
,
ItemTy
,
ItemUse
};
use
rustc_front
::
hir
::{
NamedField
,
PathListIdent
,
PathListMod
};
use
rustc_front
::
hir
::{
PathListIdent
,
PathListMod
,
StmtDecl
};
use
rustc_front
::
hir
::
StmtDecl
;
use
rustc_front
::
hir
::
UnnamedField
;
use
rustc_front
::
hir
::{
Variant
,
ViewPathGlob
,
ViewPathList
,
ViewPathSimple
};
use
rustc_front
::
hir
::{
Variant
,
ViewPathGlob
,
ViewPathList
,
ViewPathSimple
};
use
rustc_front
::
hir
::
Visibility
;
use
rustc_front
::
hir
::
Visibility
;
use
rustc_front
::
intravisit
::{
self
,
Visitor
};
use
rustc_front
::
intravisit
::{
self
,
Visitor
};
...
@@ -384,12 +382,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
...
@@ -384,12 +382,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent: Module<'b>) -> M
// Record the def ID and fields of this struct.
// Record the def ID and fields of this struct.
let
named_fields
=
struct_def
.fields
()
let
named_fields
=
struct_def
.fields
()
.iter
()
.iter
()
.filter_map
(|
f
|
{
.filter_map
(|
f
|
f
.node.name
)
match
f
.node.kind
{
NamedField
(
name
,
_
)
=>
Some
(
name
),
UnnamedField
(
_
)
=>
None
,
}
})
.collect
();
.collect
();
let
item_def_id
=
self
.ast_map
.local_def_id
(
item
.id
);
let
item_def_id
=
self
.ast_map
.local_def_id
(
item
.id
);
self
.structs
.insert
(
item_def_id
,
named_fields
);
self
.structs
.insert
(
item_def_id
,
named_fields
);
...
...
src/librustc_typeck/collect.rs
浏览文件 @
8b60b948
...
@@ -978,24 +978,21 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
...
@@ -978,24 +978,21 @@ fn convert_struct_variant<'tcx>(tcx: &ty::ctxt<'tcx>,
let
mut
seen_fields
:
FnvHashMap
<
ast
::
Name
,
Span
>
=
FnvHashMap
();
let
mut
seen_fields
:
FnvHashMap
<
ast
::
Name
,
Span
>
=
FnvHashMap
();
let
fields
=
def
.fields
()
.iter
()
.map
(|
f
|
{
let
fields
=
def
.fields
()
.iter
()
.map
(|
f
|
{
let
fid
=
tcx
.map
.local_def_id
(
f
.node.id
);
let
fid
=
tcx
.map
.local_def_id
(
f
.node.id
);
match
f
.node.kind
{
if
let
Some
(
name
)
=
f
.node.name
{
hir
::
NamedField
(
name
,
vis
)
=>
{
let
dup_span
=
seen_fields
.get
(
&
name
)
.cloned
();
let
dup_span
=
seen_fields
.get
(
&
name
)
.cloned
();
if
let
Some
(
prev_span
)
=
dup_span
{
if
let
Some
(
prev_span
)
=
dup_span
{
let
mut
err
=
struct_span_err!
(
tcx
.sess
,
f
.span
,
E0124
,
let
mut
err
=
struct_span_err!
(
tcx
.sess
,
f
.span
,
E0124
,
"field `{}` is already declared"
,
"field `{}` is already declared"
,
name
);
name
);
span_note!
(
&
mut
err
,
prev_span
,
"previously declared here"
);
span_note!
(
&
mut
err
,
prev_span
,
"previously declared here"
);
err
.emit
();
err
.emit
();
}
else
{
}
else
{
seen_fields
.insert
(
name
,
f
.span
);
seen_fields
.insert
(
name
,
f
.span
);
}
ty
::
FieldDefData
::
new
(
fid
,
name
,
vis
)
},
hir
::
UnnamedField
(
vis
)
=>
{
ty
::
FieldDefData
::
new
(
fid
,
special_idents
::
unnamed_field
.name
,
vis
)
}
}
ty
::
FieldDefData
::
new
(
fid
,
name
,
f
.node.vis
)
}
else
{
ty
::
FieldDefData
::
new
(
fid
,
special_idents
::
unnamed_field
.name
,
f
.node.vis
)
}
}
})
.collect
();
})
.collect
();
ty
::
VariantDefData
{
ty
::
VariantDefData
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录