Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
b36a9488
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,发现更多精彩内容 >>
提交
b36a9488
编写于
12月 11, 2013
作者:
D
Daniel Micay
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
stop treating `Rc` cycles as unsafe
上级
63ba93f9
变更
5
显示空白变更内容
内联
并排
Showing
5 changed file
with
13 addition
and
70 deletion
+13
-70
src/libextra/serialize.rs
src/libextra/serialize.rs
+2
-2
src/libstd/rc.rs
src/libstd/rc.rs
+9
-45
src/test/compile-fail/issue-7013.rs
src/test/compile-fail/issue-7013.rs
+1
-1
src/test/compile-fail/no_freeze-rc.rs
src/test/compile-fail/no_freeze-rc.rs
+1
-1
src/test/compile-fail/rcmut-not-const-and-not-owned.rs
src/test/compile-fail/rcmut-not-const-and-not-owned.rs
+0
-21
未找到文件。
src/libextra/serialize.rs
浏览文件 @
b36a9488
...
@@ -406,14 +406,14 @@ fn encode(&self, s: &mut S) {
...
@@ -406,14 +406,14 @@ fn encode(&self, s: &mut S) {
}
}
}
}
impl
<
S
:
Encoder
,
T
:
Encodable
<
S
>
+
Freeze
>
Encodable
<
S
>
for
Rc
<
T
>
{
impl
<
S
:
Encoder
,
T
:
Encodable
<
S
>>
Encodable
<
S
>
for
Rc
<
T
>
{
#[inline]
#[inline]
fn
encode
(
&
self
,
s
:
&
mut
S
)
{
fn
encode
(
&
self
,
s
:
&
mut
S
)
{
self
.borrow
()
.encode
(
s
)
self
.borrow
()
.encode
(
s
)
}
}
}
}
impl
<
D
:
Decoder
,
T
:
Decodable
<
D
>
+
Freeze
>
Decodable
<
D
>
for
Rc
<
T
>
{
impl
<
D
:
Decoder
,
T
:
Decodable
<
D
>
+
NonManaged
>
Decodable
<
D
>
for
Rc
<
T
>
{
#[inline]
#[inline]
fn
decode
(
d
:
&
mut
D
)
->
Rc
<
T
>
{
fn
decode
(
d
:
&
mut
D
)
->
Rc
<
T
>
{
Rc
::
new
(
Decodable
::
decode
(
d
))
Rc
::
new
(
Decodable
::
decode
(
d
))
...
...
src/libstd/rc.rs
浏览文件 @
b36a9488
...
@@ -19,9 +19,8 @@
...
@@ -19,9 +19,8 @@
use
ptr
::
RawPtr
;
use
ptr
::
RawPtr
;
use
unstable
::
intrinsics
::
transmute
;
use
unstable
::
intrinsics
::
transmute
;
use
ops
::
Drop
;
use
ops
::
Drop
;
use
kinds
::
{
Freeze
,
Send
}
;
use
kinds
::
NonManaged
;
use
clone
::{
Clone
,
DeepClone
};
use
clone
::{
Clone
,
DeepClone
};
use
cell
::
RefCell
;
use
cmp
::{
Eq
,
TotalEq
,
Ord
,
TotalOrd
,
Ordering
};
use
cmp
::{
Eq
,
TotalEq
,
Ord
,
TotalOrd
,
Ordering
};
struct
RcBox
<
T
>
{
struct
RcBox
<
T
>
{
...
@@ -36,46 +35,17 @@ pub struct Rc<T> {
...
@@ -36,46 +35,17 @@ pub struct Rc<T> {
priv
ptr
:
*
mut
RcBox
<
T
>
priv
ptr
:
*
mut
RcBox
<
T
>
}
}
impl
<
T
:
Freeze
>
Rc
<
T
>
{
impl
<
T
:
NonManaged
>
Rc
<
T
>
{
/// Construct a new reference-counted box
from a `Freeze` value
/// Construct a new reference-counted box
#[inline]
#[inline]
pub
fn
new
(
value
:
T
)
->
Rc
<
T
>
{
pub
fn
new
(
value
:
T
)
->
Rc
<
T
>
{
unsafe
{
unsafe
{
Rc
::
new_unchecked
(
value
)
Rc
{
ptr
:
transmute
(
~
RcBox
{
value
:
value
,
count
:
1
})
}
}
}
}
impl
<
T
:
Send
>
Rc
<
T
>
{
/// Construct a new reference-counted box from a `Send` value
#[inline]
pub
fn
from_send
(
value
:
T
)
->
Rc
<
T
>
{
unsafe
{
Rc
::
new_unchecked
(
value
)
}
}
}
impl
<
T
:
Freeze
>
Rc
<
RefCell
<
T
>>
{
/// Construct a new reference-counted box from a `RefCell`-wrapped `Freeze` value
#[inline]
pub
fn
from_mut
(
value
:
RefCell
<
T
>
)
->
Rc
<
RefCell
<
T
>>
{
unsafe
{
Rc
::
new_unchecked
(
value
)
}
}
}
}
}
}
impl
<
T
>
Rc
<
T
>
{
impl
<
T
>
Rc
<
T
>
{
/// Unsafety construct a new reference-counted box from any value.
///
/// It is possible to create cycles, which will leak, and may interact
/// poorly with managed pointers.
#[inline]
pub
unsafe
fn
new_unchecked
(
value
:
T
)
->
Rc
<
T
>
{
Rc
{
ptr
:
transmute
(
~
RcBox
{
value
:
value
,
count
:
1
})}
}
/// Borrow the value contained in the reference-counted box
/// Borrow the value contained in the reference-counted box
#[inline]
#[inline]
pub
fn
borrow
<
'r
>
(
&
'r
self
)
->
&
'r
T
{
pub
fn
borrow
<
'r
>
(
&
'r
self
)
->
&
'r
T
{
...
@@ -147,10 +117,10 @@ fn clone(&self) -> Rc<T> {
...
@@ -147,10 +117,10 @@ fn clone(&self) -> Rc<T> {
}
}
}
}
impl
<
T
:
DeepClone
>
DeepClone
for
Rc
<
T
>
{
impl
<
T
:
NonManaged
+
DeepClone
>
DeepClone
for
Rc
<
T
>
{
#[inline]
#[inline]
fn
deep_clone
(
&
self
)
->
Rc
<
T
>
{
fn
deep_clone
(
&
self
)
->
Rc
<
T
>
{
unsafe
{
Rc
::
new_unchecked
(
self
.borrow
()
.deep_clone
())
}
Rc
::
new
(
self
.borrow
()
.deep_clone
())
}
}
}
}
...
@@ -176,7 +146,7 @@ mod test_rc {
...
@@ -176,7 +146,7 @@ mod test_rc {
#[test]
#[test]
fn
test_clone
()
{
fn
test_clone
()
{
let
x
=
Rc
::
from_send
(
RefCell
::
new
(
5
));
let
x
=
Rc
::
new
(
RefCell
::
new
(
5
));
let
y
=
x
.clone
();
let
y
=
x
.clone
();
x
.borrow
()
.with_mut
(|
inner
|
{
x
.borrow
()
.with_mut
(|
inner
|
{
*
inner
=
20
;
*
inner
=
20
;
...
@@ -186,7 +156,7 @@ fn test_clone() {
...
@@ -186,7 +156,7 @@ fn test_clone() {
#[test]
#[test]
fn
test_deep_clone
()
{
fn
test_deep_clone
()
{
let
x
=
Rc
::
from_send
(
RefCell
::
new
(
5
));
let
x
=
Rc
::
new
(
RefCell
::
new
(
5
));
let
y
=
x
.deep_clone
();
let
y
=
x
.deep_clone
();
x
.borrow
()
.with_mut
(|
inner
|
{
x
.borrow
()
.with_mut
(|
inner
|
{
*
inner
=
20
;
*
inner
=
20
;
...
@@ -210,13 +180,7 @@ fn test_simple_clone() {
...
@@ -210,13 +180,7 @@ fn test_simple_clone() {
#[test]
#[test]
fn
test_destructor
()
{
fn
test_destructor
()
{
let
x
=
Rc
::
from_send
(
~
5
);
let
x
=
Rc
::
new
(
~
5
);
assert_eq!
(
**
x
.borrow
(),
5
);
assert_eq!
(
**
x
.borrow
(),
5
);
}
}
#[test]
fn
test_from_mut
()
{
let
a
=
10
;
let
_
x
=
Rc
::
from_mut
(
RefCell
::
new
(
&
a
));
}
}
}
src/test/compile-fail/issue-7013.rs
浏览文件 @
b36a9488
...
@@ -37,7 +37,7 @@ struct A
...
@@ -37,7 +37,7 @@ struct A
fn
main
()
fn
main
()
{
{
let
a
=
A
{
v
:
~
B
{
v
:
None
}
as
~
Foo
};
//~ ERROR cannot pack type `~B`, which does not fulfill `Send`
let
a
=
A
{
v
:
~
B
{
v
:
None
}
as
~
Foo
};
//~ ERROR cannot pack type `~B`, which does not fulfill `Send`
let
v
=
Rc
::
from_send
(
RefCell
::
new
(
a
));
let
v
=
Rc
::
new
(
RefCell
::
new
(
a
));
let
w
=
v
.clone
();
let
w
=
v
.clone
();
let
b
=
v
.borrow
();
let
b
=
v
.borrow
();
let
mut
b
=
b
.borrow_mut
();
let
mut
b
=
b
.borrow_mut
();
...
...
src/test/compile-fail/no_freeze-rc.rs
浏览文件 @
b36a9488
...
@@ -14,6 +14,6 @@
...
@@ -14,6 +14,6 @@
fn
bar
<
T
:
Freeze
>
(
_
:
T
)
{}
fn
bar
<
T
:
Freeze
>
(
_
:
T
)
{}
fn
main
()
{
fn
main
()
{
let
x
=
Rc
::
from_send
(
RefCell
::
new
(
5
));
let
x
=
Rc
::
new
(
RefCell
::
new
(
5
));
bar
(
x
);
//~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::cell::RefCell<int>>`, which does not fulfill `Freeze`
bar
(
x
);
//~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::cell::RefCell<int>>`, which does not fulfill `Freeze`
}
}
src/test/compile-fail/rcmut-not-const-and-not-owned.rs
已删除
100644 → 0
浏览文件 @
63ba93f9
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
use
std
::
cell
::
RefCell
;
use
std
::
rc
::
Rc
;
fn
o
<
T
:
Send
>
(
_
:
&
T
)
{}
fn
c
<
T
:
Freeze
>
(
_
:
&
T
)
{}
fn
main
()
{
let
x
=
Rc
::
from_send
(
RefCell
::
new
(
0
));
o
(
&
x
);
//~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::cell::RefCell<int>>`, which does not fulfill `Send`
c
(
&
x
);
//~ ERROR instantiating a type parameter with an incompatible type `std::rc::Rc<std::cell::RefCell<int>>`, which does not fulfill `Freeze`
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录