Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
87d57e49
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,发现更多精彩内容 >>
提交
87d57e49
编写于
6月 08, 2012
作者:
T
Tim Chevalier
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Don't treat all class fields as mutable, except in trans
Closes #2550
上级
75adeaad
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
43 addition
and
7 deletion
+43
-7
src/rustc/middle/trans/base.rs
src/rustc/middle/trans/base.rs
+6
-4
src/rustc/middle/trans/shape.rs
src/rustc/middle/trans/shape.rs
+1
-1
src/rustc/middle/ty.rs
src/rustc/middle/ty.rs
+21
-2
src/test/run-pass/issue-2550.rs
src/test/run-pass/issue-2550.rs
+15
-0
未找到文件。
src/rustc/middle/trans/base.rs
浏览文件 @
87d57e49
...
@@ -776,7 +776,8 @@ fn trans_class_drop(bcx: block, v0: ValueRef, dtor_did: ast::def_id,
...
@@ -776,7 +776,8 @@ fn trans_class_drop(bcx: block, v0: ValueRef, dtor_did: ast::def_id,
let
args
=
[
bcx
.fcx.llretptr
,
self_arg
];
let
args
=
[
bcx
.fcx.llretptr
,
self_arg
];
Call
(
bcx
,
dtor_addr
,
args
);
Call
(
bcx
,
dtor_addr
,
args
);
// Drop the fields
// Drop the fields
for
vec
::
eachi
(
ty
::
class_items_as_fields
(
bcx
.tcx
(),
class_did
,
substs
))
for
vec
::
eachi
(
ty
::
class_items_as_mutable_fields
(
bcx
.tcx
(),
class_did
,
substs
))
{|
i
,
fld
|
{|
i
,
fld
|
let
llfld_a
=
GEPi
(
bcx
,
classptr
,
[
0u
,
i
]);
let
llfld_a
=
GEPi
(
bcx
,
classptr
,
[
0u
,
i
]);
bcx
=
drop_ty
(
bcx
,
llfld_a
,
fld
.mt.ty
);
bcx
=
drop_ty
(
bcx
,
llfld_a
,
fld
.mt.ty
);
...
@@ -1114,7 +1115,8 @@ fn iter_variant(cx: block, a_tup: ValueRef,
...
@@ -1114,7 +1115,8 @@ fn iter_variant(cx: block, a_tup: ValueRef,
ret
next_cx
;
ret
next_cx
;
}
}
ty
::
ty_class
(
did
,
substs
)
{
ty
::
ty_class
(
did
,
substs
)
{
for
vec
::
eachi
(
ty
::
class_items_as_fields
(
cx
.tcx
(),
did
,
substs
))
for
vec
::
eachi
(
ty
::
class_items_as_mutable_fields
(
cx
.tcx
(),
did
,
substs
))
{|
i
,
fld
|
{|
i
,
fld
|
let
llfld_a
=
GEPi
(
cx
,
av
,
[
0u
,
i
]);
let
llfld_a
=
GEPi
(
cx
,
av
,
[
0u
,
i
]);
cx
=
f
(
cx
,
llfld_a
,
fld
.mt.ty
);
cx
=
f
(
cx
,
llfld_a
,
fld
.mt.ty
);
...
@@ -2523,7 +2525,7 @@ fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t,
...
@@ -2523,7 +2525,7 @@ fn trans_rec_field_inner(bcx: block, val: ValueRef, ty: ty::t,
if
option
::
is_some
(
ty
::
ty_dtor
(
bcx
.tcx
(),
did
))
{
if
option
::
is_some
(
ty
::
ty_dtor
(
bcx
.tcx
(),
did
))
{
deref
=
true
;
deref
=
true
;
}
}
ty
::
class_items_as_fields
(
bcx
.tcx
(),
did
,
substs
)
ty
::
class_items_as_
mutable_
fields
(
bcx
.tcx
(),
did
,
substs
)
}
}
// Constraint?
// Constraint?
_
{
bcx
.tcx
()
.sess
.span_bug
(
sp
,
"trans_rec_field:
\
_
{
bcx
.tcx
()
.sess
.span_bug
(
sp
,
"trans_rec_field:
\
...
@@ -4815,7 +4817,7 @@ fn trans_class_ctor(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
...
@@ -4815,7 +4817,7 @@ fn trans_class_ctor(ccx: @crate_ctxt, path: path, decl: ast::fn_decl,
else
{
selfptr
};
else
{
selfptr
};
// initialize fields to zero
// initialize fields to zero
let
fields
=
ty
::
class_items_as_fields
(
bcx_top
.tcx
(),
parent_id
,
let
fields
=
ty
::
class_items_as_
mutable_
fields
(
bcx_top
.tcx
(),
parent_id
,
dummy_substs
(
psubsts
.tys
));
dummy_substs
(
psubsts
.tys
));
let
mut
bcx
=
bcx_top
;
let
mut
bcx
=
bcx_top
;
// Initialize fields to zero so init assignments can validly
// Initialize fields to zero so init assignments can validly
...
...
src/rustc/middle/trans/shape.rs
浏览文件 @
87d57e49
...
@@ -351,7 +351,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
...
@@ -351,7 +351,7 @@ fn shape_of(ccx: @crate_ctxt, t: ty::t) -> [u8] {
add_substr
(
s
,
shape_of
(
ccx
,
tp
));
add_substr
(
s
,
shape_of
(
ccx
,
tp
));
}
}
};
};
for
ty
::
class_items_as_fields
(
ccx
.tcx
,
did
,
substs
)
.each
{|
f
|
for
ty
::
class_items_as_
mutable_
fields
(
ccx
.tcx
,
did
,
substs
)
.each
{|
f
|
sub
+=
shape_of
(
ccx
,
f
.mt.ty
);
sub
+=
shape_of
(
ccx
,
f
.mt.ty
);
}
}
add_substr
(
s
,
sub
);
add_substr
(
s
,
sub
);
...
...
src/rustc/middle/ty.rs
浏览文件 @
87d57e49
...
@@ -26,7 +26,7 @@
...
@@ -26,7 +26,7 @@
export
args_eq
;
export
args_eq
;
export
ast_constr_to_constr
;
export
ast_constr_to_constr
;
export
block_ty
;
export
block_ty
;
export
class_items_as_fields
;
export
class_items_as_fields
,
class_items_as_mutable_fields
;
export
constr
;
export
constr
;
export
constr_general
;
export
constr_general
;
export
constr_table
;
export
constr_table
;
...
@@ -2864,15 +2864,34 @@ fn class_field_tys(items: [@class_member]) -> [field_ty] {
...
@@ -2864,15 +2864,34 @@ fn class_field_tys(items: [@class_member]) -> [field_ty] {
// Return a list of fields corresponding to the class's items
// Return a list of fields corresponding to the class's items
// (as if the class was a record). trans uses this
// (as if the class was a record). trans uses this
// Takes a list of substs with which to instantiate field types
// Takes a list of substs with which to instantiate field types
// Keep in mind that this function reports that all fields are
// mutable, regardless of how they were declared. It's meant to
// be used in trans.
fn
class_items_as_mutable_fields
(
cx
:
ctxt
,
did
:
ast
::
def_id
,
substs
:
substs
)
->
[
field
]
{
class_item_fields
(
cx
,
did
,
substs
,
{|
_
mt
|
m_mutbl
})
}
// Same as class_items_as_mutable_fields, but doesn't change
// mutability.
fn
class_items_as_fields
(
cx
:
ctxt
,
did
:
ast
::
def_id
,
fn
class_items_as_fields
(
cx
:
ctxt
,
did
:
ast
::
def_id
,
substs
:
substs
)
->
[
field
]
{
substs
:
substs
)
->
[
field
]
{
class_item_fields
(
cx
,
did
,
substs
,
{|
mt
|
alt
mt
{
class_mutable
{
m_mutbl
}
class_immutable
{
m_imm
}}})
}
fn
class_item_fields
(
cx
:
ctxt
,
did
:
ast
::
def_id
,
substs
:
substs
,
frob_mutability
:
fn
(
class_mutability
)
->
mutability
)
->
[
field
]
{
let
mut
rslt
=
[];
let
mut
rslt
=
[];
for
lookup_class_fields
(
cx
,
did
)
.each
{|
f
|
for
lookup_class_fields
(
cx
,
did
)
.each
{|
f
|
// consider all instance vars mut, because the
// consider all instance vars mut, because the
// constructor may mutate all vars
// constructor may mutate all vars
rslt
+=
[{
ident
:
f
.ident
,
mt
:
rslt
+=
[{
ident
:
f
.ident
,
mt
:
{
ty
:
lookup_field_type
(
cx
,
did
,
f
.id
,
substs
),
{
ty
:
lookup_field_type
(
cx
,
did
,
f
.id
,
substs
),
mutbl
:
m_mutbl
}}];
mutbl
:
frob_mutability
(
f
.mutability
)
}}];
}
}
rslt
rslt
}
}
...
...
src/test/run-pass/issue-2550.rs
0 → 100644
浏览文件 @
87d57e49
class
C
{
let
x
:
uint
;
new
(
x
:
uint
)
{
self
.x
=
x
;
}
}
fn
f
<
T
:
copy
>
(
_
x
:
T
)
{
}
#[warn(err_non_implicitly_copyable_typarams)]
fn
main
()
{
f
(
C
(
1u
));
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录