Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
0101bbe7
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,发现更多精彩内容 >>
提交
0101bbe7
编写于
1月 02, 2015
作者:
A
Alex Crichton
浏览文件
操作
浏览文件
下载
差异文件
rollup merge of #20420: alexcrichton/second-pass-boxed
上级
faf53559
f2ccdfd8
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
29 addition
and
3 deletion
+29
-3
src/liballoc/boxed.rs
src/liballoc/boxed.rs
+24
-3
src/librustc_typeck/coherence/orphan.rs
src/librustc_typeck/coherence/orphan.rs
+5
-0
未找到文件。
src/liballoc/boxed.rs
浏览文件 @
0101bbe7
...
@@ -10,6 +10,8 @@
...
@@ -10,6 +10,8 @@
//! A unique pointer type.
//! A unique pointer type.
#![stable]
use
core
::
any
::{
Any
,
AnyRefExt
};
use
core
::
any
::{
Any
,
AnyRefExt
};
use
core
::
clone
::
Clone
;
use
core
::
clone
::
Clone
;
use
core
::
cmp
::{
PartialEq
,
PartialOrd
,
Eq
,
Ord
,
Ordering
};
use
core
::
cmp
::{
PartialEq
,
PartialOrd
,
Eq
,
Ord
,
Ordering
};
...
@@ -44,7 +46,7 @@
...
@@ -44,7 +46,7 @@
/// A type that represents a uniquely-owned value.
/// A type that represents a uniquely-owned value.
#[lang
=
"owned_box"
]
#[lang
=
"owned_box"
]
#[
unstable
=
"custom allocators will add an additional type parameter (with default)"
]
#[
stable
]
pub
struct
Box
<
T
>
(
Unique
<
T
>
);
pub
struct
Box
<
T
>
(
Unique
<
T
>
);
#[stable]
#[stable]
...
@@ -111,18 +113,37 @@ fn hash(&self, state: &mut S) {
...
@@ -111,18 +113,37 @@ fn hash(&self, state: &mut S) {
}
}
}
}
#[cfg(not(stage0))]
impl
Box
<
Any
>
{
pub
fn
downcast
<
T
:
'static
>
(
self
)
->
Result
<
Box
<
T
>
,
Box
<
Any
>>
{
if
self
.is
::
<
T
>
()
{
unsafe
{
// Get the raw representation of the trait object
let
to
:
TraitObject
=
mem
::
transmute
::
<
Box
<
Any
>
,
TraitObject
>
(
self
);
// Extract the data pointer
Ok
(
mem
::
transmute
(
to
.data
))
}
}
else
{
Err
(
self
)
}
}
}
/// Extension methods for an owning `Any` trait object.
/// Extension methods for an owning `Any` trait object.
#[unstable
=
"post-DST and coherence changes, this will not be a trait but
\
#[unstable
=
"post-DST and coherence changes, this will not be a trait but
\
rather a direct `impl` on `Box<Any>`"
]
rather a direct `impl` on `Box<Any>`"
]
#[cfg(stage0)]
pub
trait
BoxAny
{
pub
trait
BoxAny
{
/// Returns the boxed value if it is of type `T`, or
/// Returns the boxed value if it is of type `T`, or
/// `Err(Self)` if it isn't.
/// `Err(Self)` if it isn't.
#[
unstable
=
"naming conventions around accessing innards may change"
]
#[
stable
]
fn
downcast
<
T
:
'static
>
(
self
)
->
Result
<
Box
<
T
>
,
Self
>
;
fn
downcast
<
T
:
'static
>
(
self
)
->
Result
<
Box
<
T
>
,
Self
>
;
}
}
#[stable]
#[stable]
#[cfg(stage0)]
impl
BoxAny
for
Box
<
Any
>
{
impl
BoxAny
for
Box
<
Any
>
{
#[inline]
#[inline]
fn
downcast
<
T
:
'static
>
(
self
)
->
Result
<
Box
<
T
>
,
Box
<
Any
>>
{
fn
downcast
<
T
:
'static
>
(
self
)
->
Result
<
Box
<
T
>
,
Box
<
Any
>>
{
...
@@ -147,7 +168,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
...
@@ -147,7 +168,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
}
}
}
}
impl
fmt
::
Show
for
Box
<
Any
+
'static
>
{
impl
fmt
::
Show
for
Box
<
Any
>
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
f
.pad
(
"Box<Any>"
)
f
.pad
(
"Box<Any>"
)
}
}
...
...
src/librustc_typeck/coherence/orphan.rs
浏览文件 @
0101bbe7
...
@@ -57,6 +57,11 @@ fn visit_item(&mut self, item: &'v ast::Item) {
...
@@ -57,6 +57,11 @@ fn visit_item(&mut self, item: &'v ast::Item) {
ty
::
ty_trait
(
ref
data
)
=>
{
ty
::
ty_trait
(
ref
data
)
=>
{
self
.check_def_id
(
item
.span
,
data
.principal_def_id
());
self
.check_def_id
(
item
.span
,
data
.principal_def_id
());
}
}
ty
::
ty_uniq
(
..
)
=>
{
self
.check_def_id
(
item
.span
,
self
.tcx.lang_items
.owned_box
()
.unwrap
());
}
_
=>
{
_
=>
{
span_err!
(
self
.tcx.sess
,
item
.span
,
E0118
,
span_err!
(
self
.tcx.sess
,
item
.span
,
E0118
,
"no base type found for inherent implementation;
\
"no base type found for inherent implementation;
\
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录