Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
7bc29c62
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,发现更多精彩内容 >>
提交
7bc29c62
编写于
11月 21, 2012
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
libcore: Add explicit self to all overloaded operators but Add and Index. r=brson
上级
de0268b6
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
25 addition
and
25 deletion
+25
-25
src/libcore/ops.rs
src/libcore/ops.rs
+10
-10
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+7
-7
src/test/auxiliary/trait_inheritance_overloading_xc.rs
src/test/auxiliary/trait_inheritance_overloading_xc.rs
+2
-2
src/test/bench/shootout-mandelbrot.rs
src/test/bench/shootout-mandelbrot.rs
+1
-1
src/test/run-pass/operator-overloading.rs
src/test/run-pass/operator-overloading.rs
+3
-3
src/test/run-pass/trait-inheritance-overloading.rs
src/test/run-pass/trait-inheritance-overloading.rs
+2
-2
未找到文件。
src/libcore/ops.rs
浏览文件 @
7bc29c62
...
@@ -35,52 +35,52 @@ pub trait Add<RHS,Result> {
...
@@ -35,52 +35,52 @@ pub trait Add<RHS,Result> {
#[lang=
"sub"
]
#[lang=
"sub"
]
pub
trait
Sub
<
RHS
,
Result
>
{
pub
trait
Sub
<
RHS
,
Result
>
{
pure
fn
sub
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
sub
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"mul"
]
#[lang=
"mul"
]
pub
trait
Mul
<
RHS
,
Result
>
{
pub
trait
Mul
<
RHS
,
Result
>
{
pure
fn
mul
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
mul
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"div"
]
#[lang=
"div"
]
pub
trait
Div
<
RHS
,
Result
>
{
pub
trait
Div
<
RHS
,
Result
>
{
pure
fn
div
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
div
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"modulo"
]
#[lang=
"modulo"
]
pub
trait
Modulo
<
RHS
,
Result
>
{
pub
trait
Modulo
<
RHS
,
Result
>
{
pure
fn
modulo
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
modulo
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"neg"
]
#[lang=
"neg"
]
pub
trait
Neg
<
Result
>
{
pub
trait
Neg
<
Result
>
{
pure
fn
neg
()
->
Result
;
pure
fn
neg
(
&
self
)
->
Result
;
}
}
#[lang=
"bitand"
]
#[lang=
"bitand"
]
pub
trait
BitAnd
<
RHS
,
Result
>
{
pub
trait
BitAnd
<
RHS
,
Result
>
{
pure
fn
bitand
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
bitand
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"bitor"
]
#[lang=
"bitor"
]
pub
trait
BitOr
<
RHS
,
Result
>
{
pub
trait
BitOr
<
RHS
,
Result
>
{
pure
fn
bitor
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
bitor
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"bitxor"
]
#[lang=
"bitxor"
]
pub
trait
BitXor
<
RHS
,
Result
>
{
pub
trait
BitXor
<
RHS
,
Result
>
{
pure
fn
bitxor
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
bitxor
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"shl"
]
#[lang=
"shl"
]
pub
trait
Shl
<
RHS
,
Result
>
{
pub
trait
Shl
<
RHS
,
Result
>
{
pure
fn
shl
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
shl
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"shr"
]
#[lang=
"shr"
]
pub
trait
Shr
<
RHS
,
Result
>
{
pub
trait
Shr
<
RHS
,
Result
>
{
pure
fn
shr
(
rhs
:
&
RHS
)
->
Result
;
pure
fn
shr
(
&
self
,
rhs
:
&
RHS
)
->
Result
;
}
}
#[lang=
"index"
]
#[lang=
"index"
]
...
...
src/librustc/middle/ty.rs
浏览文件 @
7bc29c62
...
@@ -2041,25 +2041,25 @@ fn remove_copyable(k: Kind) -> Kind {
...
@@ -2041,25 +2041,25 @@ fn remove_copyable(k: Kind) -> Kind {
}
}
impl
Kind
:
ops
::
BitAnd
<
Kind
,
Kind
>
{
impl
Kind
:
ops
::
BitAnd
<
Kind
,
Kind
>
{
pure
fn
bitand
(
other
:
&
Kind
)
->
Kind
{
pure
fn
bitand
(
&
self
,
other
:
&
Kind
)
->
Kind
{
unsafe
{
unsafe
{
lower_kind
(
self
,
(
*
other
)
)
lower_kind
(
*
self
,
*
other
)
}
}
}
}
}
}
impl
Kind
:
ops
::
BitOr
<
Kind
,
Kind
>
{
impl
Kind
:
ops
::
BitOr
<
Kind
,
Kind
>
{
pure
fn
bitor
(
other
:
&
Kind
)
->
Kind
{
pure
fn
bitor
(
&
self
,
other
:
&
Kind
)
->
Kind
{
unsafe
{
unsafe
{
raise_kind
(
self
,
(
*
other
)
)
raise_kind
(
*
self
,
*
other
)
}
}
}
}
}
}
impl
Kind
:
ops
::
Sub
<
Kind
,
Kind
>
{
impl
Kind
:
ops
::
Sub
<
Kind
,
Kind
>
{
pure
fn
sub
(
other
:
&
Kind
)
->
Kind
{
pure
fn
sub
(
&
self
,
other
:
&
Kind
)
->
Kind
{
unsafe
{
unsafe
{
kind_
(
*
self
&
!*
(
*
other
)
)
kind_
(
*
*
self
&
!**
other
)
}
}
}
}
}
}
...
@@ -2309,7 +2309,7 @@ fn type_kind(cx: ctxt, ty: t) -> Kind {
...
@@ -2309,7 +2309,7 @@ fn type_kind(cx: ctxt, ty: t) -> Kind {
// arbitrary threshold to prevent by-value copying of big records
// arbitrary threshold to prevent by-value copying of big records
if
kind_is_safe_for_default_mode
(
result
)
{
if
kind_is_safe_for_default_mode
(
result
)
{
if
type_size
(
cx
,
ty
)
>
4
{
if
type_size
(
cx
,
ty
)
>
4
{
result
-=
kind_
(
KIND_MASK_DEFAULT_MODE
);
result
=
result
-
kind_
(
KIND_MASK_DEFAULT_MODE
);
}
}
}
}
...
...
src/test/auxiliary/trait_inheritance_overloading_xc.rs
浏览文件 @
7bc29c62
...
@@ -3,7 +3,7 @@ pub trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
...
@@ -3,7 +3,7 @@ pub trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
pub
impl
int
:
MyNum
{
pub
impl
int
:
MyNum
{
pure
fn
add
(
other
:
&
int
)
->
int
{
self
+
*
other
}
pure
fn
add
(
other
:
&
int
)
->
int
{
self
+
*
other
}
pure
fn
sub
(
other
:
&
int
)
->
int
{
self
-
*
other
}
pure
fn
sub
(
&
self
,
other
:
&
int
)
->
int
{
*
self
-
*
other
}
pure
fn
mul
(
other
:
&
int
)
->
int
{
self
*
*
other
}
pure
fn
mul
(
&
self
,
other
:
&
int
)
->
int
{
*
self
*
*
other
}
}
}
src/test/bench/shootout-mandelbrot.rs
浏览文件 @
7bc29c62
...
@@ -24,7 +24,7 @@ struct cmplx {
...
@@ -24,7 +24,7 @@ struct cmplx {
}
}
impl
cmplx
:
ops
::
Mul
<
cmplx
,
cmplx
>
{
impl
cmplx
:
ops
::
Mul
<
cmplx
,
cmplx
>
{
pure
fn
mul
(
x
:
&
cmplx
)
->
cmplx
{
pure
fn
mul
(
&
self
,
x
:
&
cmplx
)
->
cmplx
{
cmplx
{
cmplx
{
re
:
self
.re
*
(
*
x
)
.re
-
self
.im
*
(
*
x
)
.im
,
re
:
self
.re
*
(
*
x
)
.re
-
self
.im
*
(
*
x
)
.im
,
im
:
self
.re
*
(
*
x
)
.im
+
self
.im
*
(
*
x
)
.re
im
:
self
.re
*
(
*
x
)
.im
+
self
.im
*
(
*
x
)
.re
...
...
src/test/run-pass/operator-overloading.rs
浏览文件 @
7bc29c62
...
@@ -13,13 +13,13 @@ impl Point : ops::Add<Point,Point> {
...
@@ -13,13 +13,13 @@ impl Point : ops::Add<Point,Point> {
}
}
impl
Point
:
ops
::
Sub
<
Point
,
Point
>
{
impl
Point
:
ops
::
Sub
<
Point
,
Point
>
{
pure
fn
sub
(
other
:
&
Point
)
->
Point
{
pure
fn
sub
(
&
self
,
other
:
&
Point
)
->
Point
{
Point
{
x
:
self
.x
-
(
*
other
)
.x
,
y
:
self
.y
-
(
*
other
)
.y
}
Point
{
x
:
self
.x
-
(
*
other
)
.x
,
y
:
self
.y
-
(
*
other
)
.y
}
}
}
}
}
impl
Point
:
ops
::
Neg
<
Point
>
{
impl
Point
:
ops
::
Neg
<
Point
>
{
pure
fn
neg
()
->
Point
{
pure
fn
neg
(
&
self
)
->
Point
{
Point
{
x
:
-
self
.x
,
y
:
-
self
.y
}
Point
{
x
:
-
self
.x
,
y
:
-
self
.y
}
}
}
}
}
...
@@ -40,7 +40,7 @@ impl Point : cmp::Eq {
...
@@ -40,7 +40,7 @@ impl Point : cmp::Eq {
fn
main
()
{
fn
main
()
{
let
mut
p
=
Point
{
x
:
10
,
y
:
20
};
let
mut
p
=
Point
{
x
:
10
,
y
:
20
};
p
+=
Point
{
x
:
101
,
y
:
102
};
p
+=
Point
{
x
:
101
,
y
:
102
};
p
-=
Point
{
x
:
100
,
y
:
100
};
p
=
p
-
Point
{
x
:
100
,
y
:
100
};
assert
p
+
Point
{
x
:
5
,
y
:
5
}
==
Point
{
x
:
16
,
y
:
27
};
assert
p
+
Point
{
x
:
5
,
y
:
5
}
==
Point
{
x
:
16
,
y
:
27
};
assert
-
p
==
Point
{
x
:
-
11
,
y
:
-
22
};
assert
-
p
==
Point
{
x
:
-
11
,
y
:
-
22
};
assert
p
[
true
]
==
11
;
assert
p
[
true
]
==
11
;
...
...
src/test/run-pass/trait-inheritance-overloading.rs
浏览文件 @
7bc29c62
...
@@ -3,8 +3,8 @@ trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
...
@@ -3,8 +3,8 @@ trait MyNum : Add<self,self>, Sub<self,self>, Mul<self,self> {
impl
int
:
MyNum
{
impl
int
:
MyNum
{
pure
fn
add
(
other
:
&
int
)
->
int
{
self
+
*
other
}
pure
fn
add
(
other
:
&
int
)
->
int
{
self
+
*
other
}
pure
fn
sub
(
other
:
&
int
)
->
int
{
self
-
*
other
}
pure
fn
sub
(
&
self
,
other
:
&
int
)
->
int
{
*
self
-
*
other
}
pure
fn
mul
(
other
:
&
int
)
->
int
{
self
*
*
other
}
pure
fn
mul
(
&
self
,
other
:
&
int
)
->
int
{
*
self
*
*
other
}
}
}
fn
f
<
T
:
Copy
MyNum
>
(
x
:
T
,
y
:
T
)
->
(
T
,
T
,
T
)
{
fn
f
<
T
:
Copy
MyNum
>
(
x
:
T
,
y
:
T
)
->
(
T
,
T
,
T
)
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录