Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b9b1554d
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,发现更多精彩内容 >>
提交
b9b1554d
编写于
5月 24, 2020
作者:
R
Ralf Jung
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix unsizing casts
上级
b97ed1a4
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
18 addition
and
20 deletion
+18
-20
src/librustc_mir/interpret/cast.rs
src/librustc_mir/interpret/cast.rs
+18
-20
未找到文件。
src/librustc_mir/interpret/cast.rs
浏览文件 @
b9b1554d
...
...
@@ -25,12 +25,8 @@ pub fn cast(
// FIXME: In which cases should we trigger UB when the source is uninit?
match
cast_kind
{
Pointer
(
PointerCast
::
Unsize
)
=>
{
assert_eq!
(
cast_ty
,
dest
.layout.ty
,
"mismatch of cast type {} and place type {}"
,
cast_ty
,
dest
.layout.ty
);
self
.unsize_into
(
src
,
dest
)
?
;
let
cast_ty
=
self
.layout_of
(
cast_ty
)
?
;
self
.unsize_into
(
src
,
cast_ty
,
dest
)
?
;
}
Misc
=>
{
...
...
@@ -266,11 +262,11 @@ fn unsize_into_ptr(
dest
:
PlaceTy
<
'tcx
,
M
::
PointerTag
>
,
// The pointee types
source_ty
:
Ty
<
'tcx
>
,
de
st_ty
:
Ty
<
'tcx
>
,
ca
st_ty
:
Ty
<
'tcx
>
,
)
->
InterpResult
<
'tcx
>
{
// A<Struct> -> A<Trait> conversion
let
(
src_pointee_ty
,
dest_pointee_ty
)
=
self
.tcx
.struct_lockstep_tails_erasing_lifetimes
(
source_ty
,
de
st_ty
,
self
.param_env
);
self
.tcx
.struct_lockstep_tails_erasing_lifetimes
(
source_ty
,
ca
st_ty
,
self
.param_env
);
match
(
&
src_pointee_ty
.kind
,
&
dest_pointee_ty
.kind
)
{
(
&
ty
::
Array
(
_
,
length
),
&
ty
::
Slice
(
_
))
=>
{
...
...
@@ -298,32 +294,33 @@ fn unsize_into_ptr(
self
.write_immediate
(
val
,
dest
)
}
_
=>
bug!
(
"invalid unsizing {:?} -> {:?}"
,
src
.layout.ty
,
dest
.layout.
ty
),
_
=>
bug!
(
"invalid unsizing {:?} -> {:?}"
,
src
.layout.ty
,
cast_
ty
),
}
}
fn
unsize_into
(
&
mut
self
,
src
:
OpTy
<
'tcx
,
M
::
PointerTag
>
,
cast_ty
:
TyAndLayout
<
'tcx
>
,
dest
:
PlaceTy
<
'tcx
,
M
::
PointerTag
>
,
)
->
InterpResult
<
'tcx
>
{
trace!
(
"Unsizing {:?} of type {} into {:?}"
,
*
src
,
src
.layout.ty
,
dest
.layout
.ty
);
match
(
&
src
.layout.ty.kind
,
&
dest
.layout
.ty.kind
)
{
(
&
ty
::
Ref
(
_
,
s
,
_
),
&
ty
::
Ref
(
_
,
d
,
_
)
|
&
ty
::
RawPtr
(
TypeAndMut
{
ty
:
d
,
..
}))
|
(
&
ty
::
RawPtr
(
TypeAndMut
{
ty
:
s
,
..
}),
&
ty
::
RawPtr
(
TypeAndMut
{
ty
:
d
,
..
}))
=>
{
self
.unsize_into_ptr
(
src
,
dest
,
s
,
d
)
trace!
(
"Unsizing {:?} of type {} into {:?}"
,
*
src
,
src
.layout.ty
,
cast_ty
.ty
);
match
(
&
src
.layout.ty.kind
,
&
cast_ty
.ty.kind
)
{
(
&
ty
::
Ref
(
_
,
s
,
_
),
&
ty
::
Ref
(
_
,
c
,
_
)
|
&
ty
::
RawPtr
(
TypeAndMut
{
ty
:
c
,
..
}))
|
(
&
ty
::
RawPtr
(
TypeAndMut
{
ty
:
s
,
..
}),
&
ty
::
RawPtr
(
TypeAndMut
{
ty
:
c
,
..
}))
=>
{
self
.unsize_into_ptr
(
src
,
dest
,
s
,
c
)
}
(
&
ty
::
Adt
(
def_a
,
_
),
&
ty
::
Adt
(
def_b
,
_
))
=>
{
assert_eq!
(
def_a
,
def_b
);
if
def_a
.is_box
()
||
def_b
.is_box
()
{
if
!
def_a
.is_box
()
||
!
def_b
.is_box
()
{
bug!
(
"invalid unsizing between {:?} -> {:?}"
,
src
.layout
,
dest
.layout
);
bug!
(
"invalid unsizing between {:?} -> {:?}"
,
src
.layout
.ty
,
cast_ty
.ty
);
}
return
self
.unsize_into_ptr
(
src
,
dest
,
src
.layout.ty
.boxed_ty
(),
dest
.layout
.ty
.boxed_ty
(),
cast_ty
.ty
.boxed_ty
(),
);
}
...
...
@@ -331,15 +328,16 @@ fn unsize_into(
// Example: `Arc<T>` -> `Arc<Trait>`
// here we need to increase the size of every &T thin ptr field to a fat ptr
for
i
in
0
..
src
.layout.fields
.count
()
{
let
dst_field
=
self
.place_field
(
dest
,
i
)
?
;
if
dst_field
.layout
.is_zst
()
{
let
cast_ty_field
=
cast_ty
.field
(
self
,
i
)
?
;
if
cast_ty_field
.is_zst
()
{
continue
;
}
let
src_field
=
self
.operand_field
(
src
,
i
)
?
;
if
src_field
.layout.ty
==
dst_field
.layout.ty
{
let
dst_field
=
self
.place_field
(
dest
,
i
)
?
;
if
src_field
.layout.ty
==
cast_ty_field
.ty
{
self
.copy_op
(
src_field
,
dst_field
)
?
;
}
else
{
self
.unsize_into
(
src_field
,
dst_field
)
?
;
self
.unsize_into
(
src_field
,
cast_ty_field
,
dst_field
)
?
;
}
}
Ok
(())
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录