Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
cf3fefe9
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,发现更多精彩内容 >>
提交
cf3fefe9
编写于
1月 07, 2018
作者:
R
Robin Kruppe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
rustc::ty: Rename `struct_variant` to `non_enum_variant`
It is also intended for use with unions.
上级
6828cf90
变更
22
隐藏空白更改
内联
并排
Showing
22 changed file
with
55 addition
and
54 deletion
+55
-54
src/librustc/middle/dead.rs
src/librustc/middle/dead.rs
+2
-2
src/librustc/middle/expr_use_visitor.rs
src/librustc/middle/expr_use_visitor.rs
+1
-1
src/librustc/middle/mem_categorization.rs
src/librustc/middle/mem_categorization.rs
+1
-1
src/librustc/ty/mod.rs
src/librustc/ty/mod.rs
+6
-7
src/librustc/ty/sty.rs
src/librustc/ty/sty.rs
+2
-2
src/librustc/ty/util.rs
src/librustc/ty/util.rs
+4
-4
src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
+1
-1
src/librustc_borrowck/borrowck/move_data.rs
src/librustc_borrowck/borrowck/move_data.rs
+2
-2
src/librustc_lint/types.rs
src/librustc_lint/types.rs
+4
-4
src/librustc_metadata/encoder.rs
src/librustc_metadata/encoder.rs
+4
-4
src/librustc_mir/borrow_check/error_reporting.rs
src/librustc_mir/borrow_check/error_reporting.rs
+1
-1
src/librustc_mir/interpret/const_eval.rs
src/librustc_mir/interpret/const_eval.rs
+1
-1
src/librustc_mir/monomorphize/collector.rs
src/librustc_mir/monomorphize/collector.rs
+2
-2
src/librustc_save_analysis/dump_visitor.rs
src/librustc_save_analysis/dump_visitor.rs
+3
-1
src/librustc_save_analysis/lib.rs
src/librustc_save_analysis/lib.rs
+1
-1
src/librustc_trans/debuginfo/metadata.rs
src/librustc_trans/debuginfo/metadata.rs
+2
-2
src/librustc_typeck/check/cast.rs
src/librustc_typeck/check/cast.rs
+1
-1
src/librustc_typeck/check/method/suggest.rs
src/librustc_typeck/check/method/suggest.rs
+1
-1
src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/mod.rs
+9
-9
src/librustc_typeck/check/wfcheck.rs
src/librustc_typeck/check/wfcheck.rs
+4
-4
src/librustc_typeck/coherence/builtin.rs
src/librustc_typeck/coherence/builtin.rs
+1
-1
src/librustdoc/clean/inline.rs
src/librustdoc/clean/inline.rs
+2
-2
未找到文件。
src/librustc/middle/dead.rs
浏览文件 @
cf3fefe9
...
...
@@ -102,7 +102,7 @@ fn lookup_and_handle_method(&mut self, id: hir::HirId) {
fn
handle_field_access
(
&
mut
self
,
lhs
:
&
hir
::
Expr
,
name
:
ast
::
Name
)
{
match
self
.tables
.expr_ty_adjusted
(
lhs
)
.sty
{
ty
::
TyAdt
(
def
,
_
)
=>
{
self
.insert_def_id
(
def
.
struct
_variant
()
.field_named
(
name
)
.did
);
self
.insert_def_id
(
def
.
non_enum
_variant
()
.field_named
(
name
)
.did
);
}
_
=>
span_bug!
(
lhs
.span
,
"named field access on non-ADT"
),
}
...
...
@@ -111,7 +111,7 @@ fn handle_field_access(&mut self, lhs: &hir::Expr, name: ast::Name) {
fn
handle_tup_field_access
(
&
mut
self
,
lhs
:
&
hir
::
Expr
,
idx
:
usize
)
{
match
self
.tables
.expr_ty_adjusted
(
lhs
)
.sty
{
ty
::
TyAdt
(
def
,
_
)
=>
{
self
.insert_def_id
(
def
.
struct
_variant
()
.fields
[
idx
]
.did
);
self
.insert_def_id
(
def
.
non_enum
_variant
()
.fields
[
idx
]
.did
);
}
ty
::
TyTuple
(
..
)
=>
{}
_
=>
span_bug!
(
lhs
.span
,
"numeric field access on non-ADT"
),
...
...
src/librustc/middle/expr_use_visitor.rs
浏览文件 @
cf3fefe9
...
...
@@ -663,7 +663,7 @@ fn walk_struct_expr(&mut self,
match
with_cmt
.ty.sty
{
ty
::
TyAdt
(
adt
,
substs
)
if
adt
.is_struct
()
=>
{
// Consume those fields of the with expression that are needed.
for
with_field
in
&
adt
.
struct
_variant
()
.fields
{
for
with_field
in
&
adt
.
non_enum
_variant
()
.fields
{
if
!
contains_field_named
(
with_field
,
fields
)
{
let
cmt_field
=
self
.mc
.cat_field
(
&*
with_expr
,
...
...
src/librustc/middle/mem_categorization.rs
浏览文件 @
cf3fefe9
...
...
@@ -1248,7 +1248,7 @@ fn cat_pattern_<F>(&self, mut cmt: cmt<'tcx>, pat: &hir::Pat, op: &mut F) -> McR
Def
::
StructCtor
(
_
,
CtorKind
::
Fn
)
=>
{
match
self
.pat_ty
(
&
pat
)
?
.sty
{
ty
::
TyAdt
(
adt_def
,
_
)
=>
{
(
cmt
,
adt_def
.
struct
_variant
()
.fields
.len
())
(
cmt
,
adt_def
.
non_enum
_variant
()
.fields
.len
())
}
ref
ty
=>
{
span_bug!
(
pat
.span
,
"tuple struct pattern unexpected type {:?}"
,
ty
);
...
...
src/librustc/ty/mod.rs
浏览文件 @
cf3fefe9
...
...
@@ -1691,10 +1691,9 @@ pub fn has_dtor(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> bool {
self
.destructor
(
tcx
)
.is_some
()
}
/// Asserts this is a struct and returns the struct's unique
/// variant.
pub
fn
struct_variant
(
&
self
)
->
&
VariantDef
{
assert
!
(
!
self
.is_enum
());
/// Asserts this is a struct or union and returns its unique variant.
pub
fn
non_enum_variant
(
&
self
)
->
&
VariantDef
{
assert
!
(
self
.is_struct
()
||
self
.is_union
());
&
self
.variants
[
0
]
}
...
...
@@ -1733,7 +1732,7 @@ pub fn variant_of_def(&self, def: Def) -> &VariantDef {
match
def
{
Def
::
Variant
(
vid
)
|
Def
::
VariantCtor
(
vid
,
..
)
=>
self
.variant_with_id
(
vid
),
Def
::
Struct
(
..
)
|
Def
::
StructCtor
(
..
)
|
Def
::
Union
(
..
)
|
Def
::
TyAlias
(
..
)
|
Def
::
AssociatedTy
(
..
)
|
Def
::
SelfTy
(
..
)
=>
self
.
struct
_variant
(),
Def
::
TyAlias
(
..
)
|
Def
::
AssociatedTy
(
..
)
|
Def
::
SelfTy
(
..
)
=>
self
.
non_enum
_variant
(),
_
=>
bug!
(
"unexpected def {:?} in variant_of_def"
,
def
)
}
}
...
...
@@ -2319,11 +2318,11 @@ pub fn expect_variant_def(self, def: Def) -> &'tcx VariantDef {
self
.adt_def
(
enum_did
)
.variant_with_id
(
did
)
}
Def
::
Struct
(
did
)
|
Def
::
Union
(
did
)
=>
{
self
.adt_def
(
did
)
.
struct
_variant
()
self
.adt_def
(
did
)
.
non_enum
_variant
()
}
Def
::
StructCtor
(
ctor_did
,
..
)
=>
{
let
did
=
self
.parent_def_id
(
ctor_did
)
.expect
(
"struct ctor has no parent"
);
self
.adt_def
(
did
)
.
struct
_variant
()
self
.adt_def
(
did
)
.
non_enum
_variant
()
}
_
=>
bug!
(
"expect_variant_def used with unexpected def {:?}"
,
def
)
}
...
...
src/librustc/ty/sty.rs
浏览文件 @
cf3fefe9
...
...
@@ -1351,7 +1351,7 @@ pub fn sequence_element_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
pub
fn
simd_type
(
&
self
,
tcx
:
TyCtxt
<
'a
,
'gcx
,
'tcx
>
)
->
Ty
<
'tcx
>
{
match
self
.sty
{
TyAdt
(
def
,
substs
)
=>
{
def
.
struct
_variant
()
.fields
[
0
]
.ty
(
tcx
,
substs
)
def
.
non_enum
_variant
()
.fields
[
0
]
.ty
(
tcx
,
substs
)
}
_
=>
bug!
(
"simd_type called on invalid type"
)
}
...
...
@@ -1359,7 +1359,7 @@ pub fn simd_type(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Ty<'tcx> {
pub
fn
simd_size
(
&
self
,
_
cx
:
TyCtxt
)
->
usize
{
match
self
.sty
{
TyAdt
(
def
,
_
)
=>
def
.
struct
_variant
()
.fields
.len
(),
TyAdt
(
def
,
_
)
=>
def
.
non_enum
_variant
()
.fields
.len
(),
_
=>
bug!
(
"simd_size called on invalid type"
)
}
}
...
...
src/librustc/ty/util.rs
浏览文件 @
cf3fefe9
...
...
@@ -258,7 +258,7 @@ pub fn positional_element_ty(self,
adt
.variant_with_id
(
vid
)
.fields
.get
(
i
)
.map
(|
f
|
f
.ty
(
self
,
substs
))
}
(
&
TyAdt
(
adt
,
substs
),
None
)
=>
{
// Don't use `
struct
_variant`, this may be a univariant enum.
// Don't use `
non_enum
_variant`, this may be a univariant enum.
adt
.variants
[
0
]
.fields
.get
(
i
)
.map
(|
f
|
f
.ty
(
self
,
substs
))
}
(
&
TyTuple
(
ref
v
,
_
),
None
)
=>
v
.get
(
i
)
.cloned
(),
...
...
@@ -277,7 +277,7 @@ pub fn named_element_ty(self,
adt
.variant_with_id
(
vid
)
.find_field_named
(
n
)
.map
(|
f
|
f
.ty
(
self
,
substs
))
}
(
&
TyAdt
(
adt
,
substs
),
None
)
=>
{
adt
.
struct
_variant
()
.find_field_named
(
n
)
.map
(|
f
|
f
.ty
(
self
,
substs
))
adt
.
non_enum
_variant
()
.find_field_named
(
n
)
.map
(|
f
|
f
.ty
(
self
,
substs
))
}
_
=>
return
None
}
...
...
@@ -293,7 +293,7 @@ pub fn struct_tail(self, mut ty: Ty<'tcx>) -> Ty<'tcx> {
if
!
def
.is_struct
()
{
break
;
}
match
def
.
struct
_variant
()
.fields
.last
()
{
match
def
.
non_enum
_variant
()
.fields
.last
()
{
Some
(
f
)
=>
ty
=
f
.ty
(
self
,
substs
),
None
=>
break
,
}
...
...
@@ -329,7 +329,7 @@ pub fn struct_lockstep_tails(self,
match
(
&
a
.sty
,
&
b
.sty
)
{
(
&
TyAdt
(
a_def
,
a_substs
),
&
TyAdt
(
b_def
,
b_substs
))
if
a_def
==
b_def
&&
a_def
.is_struct
()
=>
{
if
let
Some
(
f
)
=
a_def
.
struct
_variant
()
.fields
.last
()
{
if
let
Some
(
f
)
=
a_def
.
non_enum
_variant
()
.fields
.last
()
{
a
=
f
.ty
(
self
,
a_substs
);
b
=
f
.ty
(
self
,
b_substs
);
}
else
{
...
...
src/librustc_borrowck/borrowck/gather_loans/restrictions.rs
浏览文件 @
cf3fefe9
...
...
@@ -107,7 +107,7 @@ fn restrict(&self,
ty
::
TyAdt
(
adt_def
,
_
)
if
adt_def
.is_union
()
=>
match
result
{
RestrictionResult
::
Safe
=>
RestrictionResult
::
Safe
,
RestrictionResult
::
SafeIf
(
base_lp
,
mut
base_vec
)
=>
{
for
field
in
&
adt_def
.
struct
_variant
()
.fields
{
for
field
in
&
adt_def
.
non_enum
_variant
()
.fields
{
let
field
=
InteriorKind
::
InteriorField
(
mc
::
NamedField
(
field
.name
));
let
field_ty
=
if
field
==
interior
{
cmt
.ty
...
...
src/librustc_borrowck/borrowck/move_data.rs
浏览文件 @
cf3fefe9
...
...
@@ -343,7 +343,7 @@ pub fn add_move(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
if
let
(
&
ty
::
TyAdt
(
adt_def
,
_
),
LpInterior
(
opt_variant_id
,
interior
))
=
(
&
base_lp
.ty.sty
,
lp_elem
)
{
if
adt_def
.is_union
()
{
for
field
in
&
adt_def
.
struct
_variant
()
.fields
{
for
field
in
&
adt_def
.
non_enum
_variant
()
.fields
{
let
field
=
InteriorKind
::
InteriorField
(
mc
::
NamedField
(
field
.name
));
if
field
!=
interior
{
let
sibling_lp_kind
=
...
...
@@ -395,7 +395,7 @@ pub fn add_assignment(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
if
let
LpExtend
(
ref
base_lp
,
mutbl
,
LpInterior
(
opt_variant_id
,
interior
))
=
lp
.kind
{
if
let
ty
::
TyAdt
(
adt_def
,
_
)
=
base_lp
.ty.sty
{
if
adt_def
.is_union
()
{
for
field
in
&
adt_def
.
struct
_variant
()
.fields
{
for
field
in
&
adt_def
.
non_enum
_variant
()
.fields
{
let
field
=
InteriorKind
::
InteriorField
(
mc
::
NamedField
(
field
.name
));
let
field_ty
=
if
field
==
interior
{
lp
.ty
...
...
src/librustc_lint/types.rs
浏览文件 @
cf3fefe9
...
...
@@ -422,7 +422,7 @@ fn check_type_for_ffi(&self,
consider adding a #[repr(C)] attribute to the type"
);
}
if
def
.
struct
_variant
()
.fields
.is_empty
()
{
if
def
.
non_enum
_variant
()
.fields
.is_empty
()
{
return
FfiUnsafe
(
"found zero-size struct in foreign module, consider
\
adding a member to this struct"
);
}
...
...
@@ -430,7 +430,7 @@ fn check_type_for_ffi(&self,
// We can't completely trust repr(C) markings; make sure the
// fields are actually safe.
let
mut
all_phantom
=
true
;
for
field
in
&
def
.
struct
_variant
()
.fields
{
for
field
in
&
def
.
non_enum
_variant
()
.fields
{
let
field_ty
=
cx
.fully_normalize_associated_types_in
(
&
field
.ty
(
cx
,
substs
)
);
...
...
@@ -458,13 +458,13 @@ fn check_type_for_ffi(&self,
consider adding a #[repr(C)] attribute to the type"
);
}
if
def
.
struct
_variant
()
.fields
.is_empty
()
{
if
def
.
non_enum
_variant
()
.fields
.is_empty
()
{
return
FfiUnsafe
(
"found zero-size union in foreign module, consider
\
adding a member to this union"
);
}
let
mut
all_phantom
=
true
;
for
field
in
&
def
.
struct
_variant
()
.fields
{
for
field
in
&
def
.
non_enum
_variant
()
.fields
{
let
field_ty
=
cx
.fully_normalize_associated_types_in
(
&
field
.ty
(
cx
,
substs
)
);
...
...
src/librustc_metadata/encoder.rs
浏览文件 @
cf3fefe9
...
...
@@ -587,7 +587,7 @@ fn encode_struct_ctor(&mut self, (adt_def_id, def_id): (DefId, DefId)) -> Entry<
debug!
(
"IsolatedEncoder::encode_struct_ctor({:?})"
,
def_id
);
let
tcx
=
self
.tcx
;
let
adt_def
=
tcx
.adt_def
(
adt_def_id
);
let
variant
=
adt_def
.
struct
_variant
();
let
variant
=
adt_def
.
non_enum
_variant
();
let
data
=
VariantData
{
ctor_kind
:
variant
.ctor_kind
,
...
...
@@ -897,7 +897,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
hir
::
ItemTy
(
..
)
=>
EntryKind
::
Type
,
hir
::
ItemEnum
(
..
)
=>
EntryKind
::
Enum
(
get_repr_options
(
&
tcx
,
def_id
)),
hir
::
ItemStruct
(
ref
struct_def
,
_
)
=>
{
let
variant
=
tcx
.adt_def
(
def_id
)
.
struct
_variant
();
let
variant
=
tcx
.adt_def
(
def_id
)
.
non_enum
_variant
();
// Encode def_ids for each field and method
// for methods, write all the stuff get_trait_method
...
...
@@ -918,7 +918,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
}),
repr_options
)
}
hir
::
ItemUnion
(
..
)
=>
{
let
variant
=
tcx
.adt_def
(
def_id
)
.
struct
_variant
();
let
variant
=
tcx
.adt_def
(
def_id
)
.
non_enum
_variant
();
let
repr_options
=
get_repr_options
(
&
tcx
,
def_id
);
EntryKind
::
Union
(
self
.lazy
(
&
VariantData
{
...
...
@@ -1011,7 +1011,7 @@ fn encode_info_for_item(&mut self, (def_id, item): (DefId, &'tcx hir::Item)) ->
hir
::
ItemStruct
(
..
)
|
hir
::
ItemUnion
(
..
)
=>
{
let
def
=
self
.tcx
.adt_def
(
def_id
);
self
.lazy_seq
(
def
.
struct
_variant
()
.fields
.iter
()
.map
(|
f
|
{
self
.lazy_seq
(
def
.
non_enum
_variant
()
.fields
.iter
()
.map
(|
f
|
{
assert
!
(
f
.did
.is_local
());
f
.did.index
}))
...
...
src/librustc_mir/borrow_check/error_reporting.rs
浏览文件 @
cf3fefe9
...
...
@@ -719,7 +719,7 @@ fn describe_field_from_ty(&self, ty: &ty::Ty, field: Field) -> String {
ty
::
TyAdt
(
def
,
_
)
=>
if
def
.is_enum
()
{
format!
(
"{}"
,
field
.index
())
}
else
{
format!
(
"{}"
,
def
.
struct
_variant
()
.fields
[
field
.index
()]
.name
)
format!
(
"{}"
,
def
.
non_enum
_variant
()
.fields
[
field
.index
()]
.name
)
},
ty
::
TyTuple
(
_
,
_
)
=>
format!
(
"{}"
,
field
.index
()),
ty
::
TyRef
(
_
,
tnm
)
|
ty
::
TyRawPtr
(
tnm
)
=>
{
...
...
src/librustc_mir/interpret/const_eval.rs
浏览文件 @
cf3fefe9
...
...
@@ -488,7 +488,7 @@ fn check_ctfe_against_miri<'a, 'tcx>(
miri_place
=
ecx
.place_downcast
(
miri_place
,
variant
)
.unwrap
();
&
def
.variants
[
variant
]
}
else
{
def
.
struct
_variant
()
def
.
non_enum
_variant
()
};
let
vec
=
match
ctfe
{
ConstVal
::
Aggregate
(
Struct
(
v
))
=>
v
,
...
...
src/librustc_mir/monomorphize/collector.rs
浏览文件 @
cf3fefe9
...
...
@@ -838,8 +838,8 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
CustomCoerceUnsized
::
Struct
(
i
)
=>
i
};
let
source_fields
=
&
source_adt_def
.
struct
_variant
()
.fields
;
let
target_fields
=
&
target_adt_def
.
struct
_variant
()
.fields
;
let
source_fields
=
&
source_adt_def
.
non_enum
_variant
()
.fields
;
let
target_fields
=
&
target_adt_def
.
non_enum
_variant
()
.fields
;
assert
!
(
coerce_index
<
source_fields
.len
()
&&
source_fields
.len
()
==
target_fields
.len
());
...
...
src/librustc_save_analysis/dump_visitor.rs
浏览文件 @
cf3fefe9
...
...
@@ -1583,10 +1583,12 @@ fn visit_expr(&mut self, ex: &'l ast::Expr) {
if
!
self
.span
.filter_generated
(
sub_span
,
ex
.span
)
{
let
span
=
self
.span_from_span
(
sub_span
.expect
(
"No span found for var ref"
));
let
ref_id
=
::
id_from_def_id
(
def
.non_enum_variant
()
.fields
[
idx
.node
]
.did
);
self
.dumper
.dump_ref
(
Ref
{
kind
:
RefKind
::
Variable
,
span
,
ref_id
:
::
id_from_def_id
(
def
.struct_variant
()
.fields
[
idx
.node
]
.did
)
,
ref_id
,
});
}
}
...
...
src/librustc_save_analysis/lib.rs
浏览文件 @
cf3fefe9
...
...
@@ -528,7 +528,7 @@ pub fn get_expr_data(&self, expr: &ast::Expr) -> Option<Data> {
};
match
self
.tables
.expr_ty_adjusted
(
&
hir_node
)
.sty
{
ty
::
TyAdt
(
def
,
_
)
if
!
def
.is_enum
()
=>
{
let
f
=
def
.
struct
_variant
()
.field_named
(
ident
.node.name
);
let
f
=
def
.
non_enum
_variant
()
.field_named
(
ident
.node.name
);
let
sub_span
=
self
.span_utils
.span_for_last_ident
(
expr
.span
);
filter!
(
self
.span_utils
,
sub_span
,
expr
.span
,
None
);
let
span
=
self
.span_from_span
(
sub_span
.unwrap
());
...
...
src/librustc_trans/debuginfo/metadata.rs
浏览文件 @
cf3fefe9
...
...
@@ -969,7 +969,7 @@ fn prepare_struct_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let
struct_name
=
compute_debuginfo_type_name
(
cx
,
struct_type
,
false
);
let
(
struct_def_id
,
variant
)
=
match
struct_type
.sty
{
ty
::
TyAdt
(
def
,
_
)
=>
(
def
.did
,
def
.
struct
_variant
()),
ty
::
TyAdt
(
def
,
_
)
=>
(
def
.did
,
def
.
non_enum
_variant
()),
_
=>
bug!
(
"prepare_struct_metadata on a non-ADT"
)
};
...
...
@@ -1084,7 +1084,7 @@ fn prepare_union_metadata<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
let
union_name
=
compute_debuginfo_type_name
(
cx
,
union_type
,
false
);
let
(
union_def_id
,
variant
)
=
match
union_type
.sty
{
ty
::
TyAdt
(
def
,
_
)
=>
(
def
.did
,
def
.
struct
_variant
()),
ty
::
TyAdt
(
def
,
_
)
=>
(
def
.did
,
def
.
non_enum
_variant
()),
_
=>
bug!
(
"prepare_union_metadata on a non-ADT"
)
};
...
...
src/librustc_typeck/check/cast.rs
浏览文件 @
cf3fefe9
...
...
@@ -107,7 +107,7 @@ fn pointer_kind(&self, t: Ty<'tcx>, span: Span) ->
ty
::
TyDynamic
(
ref
tty
,
..
)
=>
Some
(
PointerKind
::
Vtable
(
tty
.principal
()
.map
(|
p
|
p
.def_id
()))),
ty
::
TyAdt
(
def
,
substs
)
if
def
.is_struct
()
=>
{
match
def
.
struct
_variant
()
.fields
.last
()
{
match
def
.
non_enum
_variant
()
.fields
.last
()
{
None
=>
Some
(
PointerKind
::
Thin
),
Some
(
f
)
=>
{
let
field_ty
=
self
.field_ty
(
span
,
f
,
substs
);
...
...
src/librustc_typeck/check/method/suggest.rs
浏览文件 @
cf3fefe9
...
...
@@ -228,7 +228,7 @@ pub fn report_method_error(&self,
for
(
ty
,
_
)
in
self
.autoderef
(
span
,
rcvr_ty
)
{
match
ty
.sty
{
ty
::
TyAdt
(
def
,
substs
)
if
!
def
.is_enum
()
=>
{
if
let
Some
(
field
)
=
def
.
struct
_variant
()
if
let
Some
(
field
)
=
def
.
non_enum
_variant
()
.find_field_named
(
item_name
)
{
let
snippet
=
tcx
.sess
.codemap
()
.span_to_snippet
(
expr
.span
);
let
expr_string
=
match
snippet
{
...
...
src/librustc_typeck/check/mod.rs
浏览文件 @
cf3fefe9
...
...
@@ -1444,7 +1444,7 @@ pub fn check_simd<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, sp: Span, def_id: DefId
let
t
=
tcx
.type_of
(
def_id
);
match
t
.sty
{
ty
::
TyAdt
(
def
,
substs
)
if
def
.is_struct
()
=>
{
let
fields
=
&
def
.
struct
_variant
()
.fields
;
let
fields
=
&
def
.
non_enum
_variant
()
.fields
;
if
fields
.is_empty
()
{
span_err!
(
tcx
.sess
,
sp
,
E0075
,
"SIMD vector cannot be empty"
);
return
;
...
...
@@ -1498,7 +1498,7 @@ fn check_packed_inner<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
}
// push struct def_id before checking fields
stack
.push
(
def_id
);
for
field
in
&
def
.
struct
_variant
()
.fields
{
for
field
in
&
def
.
non_enum
_variant
()
.fields
{
let
f
=
field
.ty
(
tcx
,
substs
);
match
f
.sty
{
ty
::
TyAdt
(
def
,
_
)
=>
{
...
...
@@ -2945,7 +2945,7 @@ fn check_field(&self,
debug!
(
"struct named {:?}"
,
base_t
);
let
(
ident
,
def_scope
)
=
self
.tcx
.adjust
(
field
.node
,
base_def
.did
,
self
.body_id
);
let
fields
=
&
base_def
.
struct
_variant
()
.fields
;
let
fields
=
&
base_def
.
non_enum
_variant
()
.fields
;
if
let
Some
(
field
)
=
fields
.iter
()
.find
(|
f
|
f
.name
.to_ident
()
==
ident
)
{
let
field_ty
=
self
.field_ty
(
expr
.span
,
field
,
substs
);
if
field
.vis
.is_accessible_from
(
def_scope
,
self
.tcx
)
{
...
...
@@ -2993,12 +2993,12 @@ fn check_field(&self,
match
expr_t
.sty
{
ty
::
TyAdt
(
def
,
_
)
if
!
def
.is_enum
()
=>
{
if
let
Some
(
suggested_field_name
)
=
Self
::
suggest_field_name
(
def
.
struct
_variant
(),
field
,
vec!
[])
{
Self
::
suggest_field_name
(
def
.
non_enum
_variant
(),
field
,
vec!
[])
{
err
.span_label
(
field
.span
,
format!
(
"did you mean `{}`?"
,
suggested_field_name
));
}
else
{
err
.span_label
(
field
.span
,
"unknown field"
);
let
struct_variant_def
=
def
.
struct
_variant
();
let
struct_variant_def
=
def
.
non_enum
_variant
();
let
field_names
=
self
.available_field_names
(
struct_variant_def
);
if
!
field_names
.is_empty
()
{
err
.note
(
&
format!
(
"available fields are: {}"
,
...
...
@@ -3080,7 +3080,7 @@ fn check_tup_field(&self,
while
let
Some
((
base_t
,
_
))
=
autoderef
.next
()
{
let
field
=
match
base_t
.sty
{
ty
::
TyAdt
(
base_def
,
substs
)
if
base_def
.is_struct
()
=>
{
tuple_like
=
base_def
.
struct
_variant
()
.ctor_kind
==
CtorKind
::
Fn
;
tuple_like
=
base_def
.
non_enum
_variant
()
.ctor_kind
==
CtorKind
::
Fn
;
if
!
tuple_like
{
continue
}
debug!
(
"tuple struct named {:?}"
,
base_t
);
...
...
@@ -3090,7 +3090,7 @@ fn check_tup_field(&self,
};
let
(
ident
,
def_scope
)
=
self
.tcx
.adjust_ident
(
ident
,
base_def
.did
,
self
.body_id
);
let
fields
=
&
base_def
.
struct
_variant
()
.fields
;
let
fields
=
&
base_def
.
non_enum
_variant
()
.fields
;
if
let
Some
(
field
)
=
fields
.iter
()
.find
(|
f
|
f
.name
.to_ident
()
==
ident
)
{
let
field_ty
=
self
.field_ty
(
expr
.span
,
field
,
substs
);
if
field
.vis
.is_accessible_from
(
def_scope
,
self
.tcx
)
{
...
...
@@ -3350,7 +3350,7 @@ pub fn check_struct_path(&self,
Def
::
AssociatedTy
(
..
)
|
Def
::
SelfTy
(
..
)
=>
{
match
ty
.sty
{
ty
::
TyAdt
(
adt
,
substs
)
if
!
adt
.is_enum
()
=>
{
Some
((
adt
.
struct
_variant
(),
adt
.did
,
substs
))
Some
((
adt
.
non_enum
_variant
(),
adt
.did
,
substs
))
}
_
=>
None
,
}
...
...
@@ -3412,7 +3412,7 @@ fn check_expr_struct(&self,
self
.check_expr_has_type_or_error
(
base_expr
,
struct_ty
);
match
struct_ty
.sty
{
ty
::
TyAdt
(
adt
,
substs
)
if
adt
.is_struct
()
=>
{
let
fru_field_types
=
adt
.
struct
_variant
()
.fields
.iter
()
.map
(|
f
|
{
let
fru_field_types
=
adt
.
non_enum
_variant
()
.fields
.iter
()
.map
(|
f
|
{
self
.normalize_associated_types_in
(
expr
.span
,
&
f
.ty
(
self
.tcx
,
substs
))
})
.collect
();
...
...
src/librustc_typeck/check/wfcheck.rs
浏览文件 @
cf3fefe9
...
...
@@ -130,14 +130,14 @@ fn check_item_well_formed(&mut self, item: &hir::Item) {
}
hir
::
ItemStruct
(
ref
struct_def
,
ref
ast_generics
)
=>
{
self
.check_type_defn
(
item
,
false
,
|
fcx
|
{
vec!
[
fcx
.
struct
_variant
(
struct_def
)]
vec!
[
fcx
.
non_enum
_variant
(
struct_def
)]
});
self
.check_variances_for_type_defn
(
item
,
ast_generics
);
}
hir
::
ItemUnion
(
ref
struct_def
,
ref
ast_generics
)
=>
{
self
.check_type_defn
(
item
,
true
,
|
fcx
|
{
vec!
[
fcx
.
struct
_variant
(
struct_def
)]
vec!
[
fcx
.
non_enum
_variant
(
struct_def
)]
});
self
.check_variances_for_type_defn
(
item
,
ast_generics
);
...
...
@@ -689,7 +689,7 @@ struct AdtField<'tcx> {
}
impl
<
'a
,
'gcx
,
'tcx
>
FnCtxt
<
'a
,
'gcx
,
'tcx
>
{
fn
struct
_variant
(
&
self
,
struct_def
:
&
hir
::
VariantData
)
->
AdtVariant
<
'tcx
>
{
fn
non_enum
_variant
(
&
self
,
struct_def
:
&
hir
::
VariantData
)
->
AdtVariant
<
'tcx
>
{
let
fields
=
struct_def
.fields
()
.iter
()
.map
(|
field
|
{
...
...
@@ -704,7 +704,7 @@ fn struct_variant(&self, struct_def: &hir::VariantData) -> AdtVariant<'tcx> {
fn
enum_variants
(
&
self
,
enum_def
:
&
hir
::
EnumDef
)
->
Vec
<
AdtVariant
<
'tcx
>>
{
enum_def
.variants
.iter
()
.map
(|
variant
|
self
.
struct
_variant
(
&
variant
.node.data
))
.map
(|
variant
|
self
.
non_enum
_variant
(
&
variant
.node.data
))
.collect
()
}
...
...
src/librustc_typeck/coherence/builtin.rs
浏览文件 @
cf3fefe9
...
...
@@ -288,7 +288,7 @@ pub fn coerce_unsized_info<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
// conversion). This will work out because `U:
// Unsize<V>`, and we have a builtin rule that `*mut
// U` can be coerced to `*mut V` if `U: Unsize<V>`.
let
fields
=
&
def_a
.
struct
_variant
()
.fields
;
let
fields
=
&
def_a
.
non_enum
_variant
()
.fields
;
let
diff_fields
=
fields
.iter
()
.enumerate
()
.filter_map
(|(
i
,
f
)|
{
...
...
src/librustdoc/clean/inline.rs
浏览文件 @
cf3fefe9
...
...
@@ -186,7 +186,7 @@ fn build_enum(cx: &DocContext, did: DefId) -> clean::Enum {
fn
build_struct
(
cx
:
&
DocContext
,
did
:
DefId
)
->
clean
::
Struct
{
let
predicates
=
cx
.tcx
.predicates_of
(
did
);
let
variant
=
cx
.tcx
.adt_def
(
did
)
.
struct
_variant
();
let
variant
=
cx
.tcx
.adt_def
(
did
)
.
non_enum
_variant
();
clean
::
Struct
{
struct_type
:
match
variant
.ctor_kind
{
...
...
@@ -202,7 +202,7 @@ fn build_struct(cx: &DocContext, did: DefId) -> clean::Struct {
fn
build_union
(
cx
:
&
DocContext
,
did
:
DefId
)
->
clean
::
Union
{
let
predicates
=
cx
.tcx
.predicates_of
(
did
);
let
variant
=
cx
.tcx
.adt_def
(
did
)
.
struct
_variant
();
let
variant
=
cx
.tcx
.adt_def
(
did
)
.
non_enum
_variant
();
clean
::
Union
{
struct_type
:
doctree
::
Plain
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录