Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
ad27e262
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,发现更多精彩内容 >>
提交
ad27e262
编写于
7月 10, 2014
作者:
L
Luqman Aden
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
librustc: Set enum discriminant only after field translation.
上级
27748b09
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
20 addition
and
25 deletion
+20
-25
src/librustc/middle/trans/adt.rs
src/librustc/middle/trans/adt.rs
+3
-4
src/librustc/middle/trans/base.rs
src/librustc/middle/trans/base.rs
+4
-6
src/librustc/middle/trans/closure.rs
src/librustc/middle/trans/closure.rs
+1
-1
src/librustc/middle/trans/expr.rs
src/librustc/middle/trans/expr.rs
+12
-14
未找到文件。
src/librustc/middle/trans/adt.rs
浏览文件 @
ad27e262
...
...
@@ -674,11 +674,10 @@ pub fn trans_case<'a>(bcx: &'a Block<'a>, r: &Repr, discr: Disr)
}
/**
* Begin initializing a new value of the given case of the given
* representation. The fields, if any, should then be initialized via
* `trans_field_ptr`.
* Set the discriminant for a new value of the given case of the given
* representation.
*/
pub
fn
trans_s
tart_init
(
bcx
:
&
Block
,
r
:
&
Repr
,
val
:
ValueRef
,
discr
:
Disr
)
{
pub
fn
trans_s
et_discr
(
bcx
:
&
Block
,
r
:
&
Repr
,
val
:
ValueRef
,
discr
:
Disr
)
{
match
*
r
{
CEnum
(
ity
,
min
,
max
)
=>
{
assert_discr_in_range
(
ity
,
min
,
max
,
discr
);
...
...
src/librustc/middle/trans/base.rs
浏览文件 @
ad27e262
...
...
@@ -1735,14 +1735,12 @@ pub fn trans_named_tuple_constructor<'a>(mut bcx: &'a Block<'a>,
if
!
type_is_zero_size
(
ccx
,
result_ty
)
{
let
repr
=
adt
::
represent_type
(
ccx
,
result_ty
);
adt
::
trans_start_init
(
bcx
,
&*
repr
,
llresult
,
disr
);
match
args
{
callee
::
ArgExprs
(
exprs
)
=>
{
for
(
i
,
expr
)
in
exprs
.iter
()
.enumerate
()
{
let
lldestptr
=
adt
::
trans_field_ptr
(
bcx
,
&*
repr
,
llresult
,
disr
,
i
);
bcx
=
expr
::
trans_into
(
bcx
,
*
expr
,
expr
::
SaveIn
(
lldestptr
));
}
let
fields
=
exprs
.iter
()
.map
(|
x
|
*
x
)
.enumerate
()
.collect
::
<
Vec
<
_
>>
();
bcx
=
expr
::
trans_adt
(
bcx
,
&*
repr
,
disr
,
fields
.as_slice
(),
None
,
expr
::
SaveIn
(
llresult
));
}
_
=>
ccx
.sess
()
.bug
(
"expected expr as arguments for variant/struct tuple constructor"
)
}
...
...
@@ -1800,7 +1798,6 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
if
!
type_is_zero_size
(
fcx
.ccx
,
result_ty
)
{
let
repr
=
adt
::
represent_type
(
ccx
,
result_ty
);
adt
::
trans_start_init
(
bcx
,
&*
repr
,
fcx
.llretptr
.get
()
.unwrap
(),
disr
);
for
(
i
,
arg_datum
)
in
arg_datums
.move_iter
()
.enumerate
()
{
let
lldestptr
=
adt
::
trans_field_ptr
(
bcx
,
&*
repr
,
...
...
@@ -1809,6 +1806,7 @@ fn trans_enum_variant_or_tuple_like_struct(ccx: &CrateContext,
i
);
arg_datum
.store_to
(
bcx
,
lldestptr
);
}
adt
::
trans_set_discr
(
bcx
,
&*
repr
,
fcx
.llretptr
.get
()
.unwrap
(),
disr
);
}
finish_fn
(
&
fcx
,
bcx
,
result_ty
);
...
...
src/librustc/middle/trans/closure.rs
浏览文件 @
ad27e262
...
...
@@ -502,7 +502,6 @@ pub fn trans_unboxed_closure<'a>(
let
repr
=
adt
::
represent_type
(
bcx
.ccx
(),
node_id_type
(
bcx
,
id
));
// Create the closure.
adt
::
trans_start_init
(
bcx
,
&*
repr
,
dest_addr
,
0
);
for
freevar
in
freevars_ptr
.iter
()
{
let
datum
=
expr
::
trans_local_var
(
bcx
,
freevar
.def
);
let
upvar_slot_dest
=
adt
::
trans_field_ptr
(
bcx
,
...
...
@@ -512,6 +511,7 @@ pub fn trans_unboxed_closure<'a>(
0
);
bcx
=
datum
.store_to
(
bcx
,
upvar_slot_dest
);
}
adt
::
trans_set_discr
(
bcx
,
&*
repr
,
dest_addr
,
0
);
bcx
}
...
...
src/librustc/middle/trans/expr.rs
浏览文件 @
ad27e262
...
...
@@ -876,8 +876,8 @@ fn trans_def_dps_unadjusted<'a>(
// Nullary variant.
let
ty
=
expr_ty
(
bcx
,
ref_expr
);
let
repr
=
adt
::
represent_type
(
bcx
.ccx
(),
ty
);
adt
::
trans_s
tart_init
(
bcx
,
&*
repr
,
lldest
,
variant_info
.disr_val
);
adt
::
trans_s
et_discr
(
bcx
,
&*
repr
,
lldest
,
variant_info
.disr_val
);
return
bcx
;
}
}
...
...
@@ -886,7 +886,7 @@ fn trans_def_dps_unadjusted<'a>(
match
ty
::
get
(
ty
)
.sty
{
ty
::
ty_struct
(
did
,
_
)
if
ty
::
has_dtor
(
bcx
.tcx
(),
did
)
=>
{
let
repr
=
adt
::
represent_type
(
bcx
.ccx
(),
ty
);
adt
::
trans_s
tart_init
(
bcx
,
&*
repr
,
lldest
,
0
);
adt
::
trans_s
et_discr
(
bcx
,
&*
repr
,
lldest
,
0
);
}
_
=>
{}
}
...
...
@@ -1098,7 +1098,7 @@ fn trans_rec_or_struct<'a>(
* Note that `fields` may be empty; the base expression must always be
* evaluated for side-effects.
*/
struct
StructBaseInfo
{
pub
struct
StructBaseInfo
{
/// The base expression; will be evaluated after all explicit fields.
expr
:
Gc
<
ast
::
Expr
>
,
/// The indices of fields to copy paired with their types.
...
...
@@ -1114,14 +1114,12 @@ struct StructBaseInfo {
* - `optbase` contains information on the base struct (if any) from
* which remaining fields are copied; see comments on `StructBaseInfo`.
*/
fn
trans_adt
<
'a
>
(
bcx
:
&
'a
Block
<
'a
>
,
repr
:
&
adt
::
Repr
,
discr
:
ty
::
Disr
,
fields
:
&
[(
uint
,
Gc
<
ast
::
Expr
>
)],
optbase
:
Option
<
StructBaseInfo
>
,
dest
:
Dest
)
->
&
'a
Block
<
'a
>
{
pub
fn
trans_adt
<
'a
>
(
bcx
:
&
'a
Block
<
'a
>
,
repr
:
&
adt
::
Repr
,
discr
:
ty
::
Disr
,
fields
:
&
[(
uint
,
Gc
<
ast
::
Expr
>
)],
optbase
:
Option
<
StructBaseInfo
>
,
dest
:
Dest
)
->
&
'a
Block
<
'a
>
{
let
_
icx
=
push_ctxt
(
"trans_adt"
);
let
fcx
=
bcx
.fcx
;
let
mut
bcx
=
bcx
;
...
...
@@ -1143,8 +1141,6 @@ fn trans_adt<'a>(
// failure occur before the ADT as a whole is ready.
let
custom_cleanup_scope
=
fcx
.push_custom_cleanup_scope
();
adt
::
trans_start_init
(
bcx
,
repr
,
addr
,
discr
);
for
&
(
i
,
ref
e
)
in
fields
.iter
()
{
let
dest
=
adt
::
trans_field_ptr
(
bcx
,
repr
,
addr
,
discr
,
i
);
let
e_ty
=
expr_ty_adjusted
(
bcx
,
&**
e
);
...
...
@@ -1166,6 +1162,8 @@ fn trans_adt<'a>(
}
}
adt
::
trans_set_discr
(
bcx
,
repr
,
addr
,
discr
);
fcx
.pop_custom_cleanup_scope
(
custom_cleanup_scope
);
return
bcx
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录