Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
dcd332ed
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,发现更多精彩内容 >>
提交
dcd332ed
编写于
7月 01, 2017
作者:
S
Scott McMurray
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Delete deprecated & unstable range-specific `step_by`
Replacement: 41439 Deprecation: 42310 for 1.19 Fixes 41477
上级
05b57976
变更
8
显示空白变更内容
内联
并排
Showing
8 changed file
with
20 addition
and
251 deletion
+20
-251
src/liballoc/tests/vec_deque.rs
src/liballoc/tests/vec_deque.rs
+1
-2
src/libcore/iter/mod.rs
src/libcore/iter/mod.rs
+0
-6
src/libcore/iter/range.rs
src/libcore/iter/range.rs
+0
-213
src/libcore/tests/iter.rs
src/libcore/tests/iter.rs
+16
-26
src/libcore/tests/lib.rs
src/libcore/tests/lib.rs
+0
-1
src/librand/lib.rs
src/librand/lib.rs
+1
-1
src/test/run-pass/range_inclusive.rs
src/test/run-pass/range_inclusive.rs
+1
-1
src/test/run-pass/sync-send-iterators-in-libcore.rs
src/test/run-pass/sync-send-iterators-in-libcore.rs
+1
-1
未找到文件。
src/liballoc/tests/vec_deque.rs
浏览文件 @
dcd332ed
...
...
@@ -510,8 +510,7 @@ fn test_from_iter() {
let
u
:
Vec
<
_
>
=
deq
.iter
()
.cloned
()
.collect
();
assert_eq!
(
u
,
v
);
// FIXME #27741: Remove `.skip(0)` when Range::step_by is fully removed
let
seq
=
(
0
..
)
.skip
(
0
)
.step_by
(
2
)
.take
(
256
);
let
seq
=
(
0
..
)
.step_by
(
2
)
.take
(
256
);
let
deq
:
VecDeque
<
_
>
=
seq
.collect
();
for
(
i
,
&
x
)
in
deq
.iter
()
.enumerate
()
{
assert_eq!
(
2
*
i
,
x
);
...
...
src/libcore/iter/mod.rs
浏览文件 @
dcd332ed
...
...
@@ -314,12 +314,6 @@
reason
=
"likely to be replaced by finer-grained traits"
,
issue
=
"42168"
)]
pub
use
self
::
range
::
Step
;
#[unstable(feature
=
"step_by"
,
reason
=
"recent addition"
,
issue
=
"27741"
)]
#[rustc_deprecated(since
=
"1.19.0"
,
reason
=
"replaced by `iter::StepBy`"
)]
#[allow(deprecated)]
pub
use
self
::
range
::
StepBy
as
DeprecatedStepBy
;
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
use
self
::
sources
::{
Repeat
,
repeat
};
...
...
src/libcore/iter/range.rs
浏览文件 @
dcd332ed
...
...
@@ -244,219 +244,6 @@ fn steps_between_by_one(start: &Self, end: &Self) -> Option<usize> {
step_impl_no_between!
(
u64
i64
);
step_impl_no_between!
(
u128
i128
);
/// An adapter for stepping range iterators by a custom amount.
///
/// The resulting iterator handles overflow by stopping. The `A`
/// parameter is the type being iterated over, while `R` is the range
/// type (usually one of `std::ops::{Range, RangeFrom, RangeInclusive}`.
#[derive(Clone,
Debug)]
#[unstable(feature
=
"step_by"
,
reason
=
"recent addition"
,
issue
=
"27741"
)]
#[rustc_deprecated(since
=
"1.19.0"
,
reason
=
"replaced by `iter::StepBy`"
)]
#[allow(deprecated)]
pub
struct
StepBy
<
A
,
R
>
{
step_by
:
A
,
range
:
R
,
}
impl
<
A
:
Step
>
ops
::
RangeFrom
<
A
>
{
/// Creates an iterator starting at the same point, but stepping by
/// the given amount at each iteration.
///
/// # Examples
///
/// ```
/// #![feature(step_by)]
/// fn main() {
/// let result: Vec<_> = (0..).step_by(2).take(5).collect();
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
/// }
/// ```
#[unstable(feature
=
"step_by"
,
reason
=
"recent addition"
,
issue
=
"27741"
)]
#[rustc_deprecated(since
=
"1.19.0"
,
reason
=
"replaced by `Iterator::step_by`"
)]
#[allow(deprecated)]
pub
fn
step_by
(
self
,
by
:
A
)
->
StepBy
<
A
,
Self
>
{
StepBy
{
step_by
:
by
,
range
:
self
}
}
}
impl
<
A
:
Step
>
ops
::
Range
<
A
>
{
/// Creates an iterator with the same range, but stepping by the
/// given amount at each iteration.
///
/// The resulting iterator handles overflow by stopping.
///
/// # Examples
///
/// ```
/// #![feature(step_by)]
/// fn main() {
/// let result: Vec<_> = (0..10).step_by(2).collect();
/// assert_eq!(result, vec![0, 2, 4, 6, 8]);
/// }
/// ```
#[unstable(feature
=
"step_by"
,
reason
=
"recent addition"
,
issue
=
"27741"
)]
#[rustc_deprecated(since
=
"1.19.0"
,
reason
=
"replaced by `Iterator::step_by`"
)]
#[allow(deprecated)]
pub
fn
step_by
(
self
,
by
:
A
)
->
StepBy
<
A
,
Self
>
{
StepBy
{
step_by
:
by
,
range
:
self
}
}
}
impl
<
A
:
Step
>
ops
::
RangeInclusive
<
A
>
{
/// Creates an iterator with the same range, but stepping by the
/// given amount at each iteration.
///
/// The resulting iterator handles overflow by stopping.
///
/// # Examples
///
/// ```
/// #![feature(step_by, inclusive_range_syntax)]
///
/// let result: Vec<_> = (0...10).step_by(2).collect();
/// assert_eq!(result, vec![0, 2, 4, 6, 8, 10]);
/// ```
#[unstable(feature
=
"step_by"
,
reason
=
"recent addition"
,
issue
=
"27741"
)]
#[rustc_deprecated(since
=
"1.19.0"
,
reason
=
"replaced by `Iterator::step_by`"
)]
#[allow(deprecated)]
pub
fn
step_by
(
self
,
by
:
A
)
->
StepBy
<
A
,
Self
>
{
StepBy
{
step_by
:
by
,
range
:
self
}
}
}
#[unstable(feature
=
"step_by"
,
reason
=
"recent addition"
,
issue
=
"27741"
)]
#[allow(deprecated)]
impl
<
A
>
Iterator
for
StepBy
<
A
,
ops
::
RangeFrom
<
A
>>
where
A
:
Clone
,
for
<
'a
>
&
'a
A
:
Add
<&
'a
A
,
Output
=
A
>
{
type
Item
=
A
;
#[inline]
fn
next
(
&
mut
self
)
->
Option
<
A
>
{
let
mut
n
=
&
self
.range.start
+
&
self
.step_by
;
mem
::
swap
(
&
mut
n
,
&
mut
self
.range.start
);
Some
(
n
)
}
#[inline]
fn
size_hint
(
&
self
)
->
(
usize
,
Option
<
usize
>
)
{
(
usize
::
MAX
,
None
)
// Too bad we can't specify an infinite lower bound
}
}
#[unstable(feature
=
"fused"
,
issue
=
"35602"
)]
#[allow(deprecated)]
impl
<
A
>
FusedIterator
for
StepBy
<
A
,
ops
::
RangeFrom
<
A
>>
where
A
:
Clone
,
for
<
'a
>
&
'a
A
:
Add
<&
'a
A
,
Output
=
A
>
{}
#[unstable(feature
=
"step_by"
,
reason
=
"recent addition"
,
issue
=
"27741"
)]
#[allow(deprecated)]
impl
<
A
:
Step
+
Clone
>
Iterator
for
StepBy
<
A
,
ops
::
Range
<
A
>>
{
type
Item
=
A
;
#[inline]
fn
next
(
&
mut
self
)
->
Option
<
A
>
{
let
rev
=
self
.step_by
.is_negative
();
if
(
rev
&&
self
.range.start
>
self
.range.end
)
||
(
!
rev
&&
self
.range.start
<
self
.range.end
)
{
match
self
.range.start
.step
(
&
self
.step_by
)
{
Some
(
mut
n
)
=>
{
mem
::
swap
(
&
mut
self
.range.start
,
&
mut
n
);
Some
(
n
)
},
None
=>
{
let
mut
n
=
self
.range.end
.clone
();
mem
::
swap
(
&
mut
self
.range.start
,
&
mut
n
);
Some
(
n
)
}
}
}
else
{
None
}
}
#[inline]
fn
size_hint
(
&
self
)
->
(
usize
,
Option
<
usize
>
)
{
match
Step
::
steps_between
(
&
self
.range.start
,
&
self
.range.end
,
&
self
.step_by
)
{
Some
(
hint
)
=>
(
hint
,
Some
(
hint
)),
None
=>
(
0
,
None
)
}
}
}
#[unstable(feature
=
"fused"
,
issue
=
"35602"
)]
#[allow(deprecated)]
impl
<
A
:
Step
+
Clone
>
FusedIterator
for
StepBy
<
A
,
ops
::
Range
<
A
>>
{}
#[unstable(feature
=
"inclusive_range"
,
reason
=
"recently added, follows RFC"
,
issue
=
"28237"
)]
#[allow(deprecated)]
impl
<
A
:
Step
+
Clone
>
Iterator
for
StepBy
<
A
,
ops
::
RangeInclusive
<
A
>>
{
type
Item
=
A
;
#[inline]
fn
next
(
&
mut
self
)
->
Option
<
A
>
{
let
rev
=
self
.step_by
.is_negative
();
if
(
rev
&&
self
.range.start
>=
self
.range.end
)
||
(
!
rev
&&
self
.range.start
<=
self
.range.end
)
{
match
self
.range.start
.step
(
&
self
.step_by
)
{
Some
(
n
)
=>
{
Some
(
mem
::
replace
(
&
mut
self
.range.start
,
n
))
},
None
=>
{
let
last
=
self
.range.start
.replace_one
();
self
.range.end
.replace_zero
();
self
.step_by
.replace_one
();
Some
(
last
)
},
}
}
else
{
None
}
}
#[inline]
fn
size_hint
(
&
self
)
->
(
usize
,
Option
<
usize
>
)
{
match
Step
::
steps_between
(
&
self
.range.start
,
&
self
.range.end
,
&
self
.step_by
)
{
Some
(
hint
)
=>
(
hint
.saturating_add
(
1
),
hint
.checked_add
(
1
)),
None
=>
(
0
,
None
)
}
}
}
#[unstable(feature
=
"fused"
,
issue
=
"35602"
)]
#[allow(deprecated)]
impl
<
A
:
Step
+
Clone
>
FusedIterator
for
StepBy
<
A
,
ops
::
RangeInclusive
<
A
>>
{}
macro_rules!
range_exact_iter_impl
{
(
$
(
$t:ty
)
*
)
=>
(
$
(
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
...
...
src/libcore/tests/iter.rs
浏览文件 @
dcd332ed
...
...
@@ -12,15 +12,6 @@
use
core
::{
i8
,
i16
,
isize
};
use
core
::
usize
;
// FIXME #27741: This is here to simplify calling Iterator::step_by. Remove
// once Range::step_by is completely gone (not just deprecated).
trait
IterEx
:
Sized
{
fn
iter_step_by
(
self
,
n
:
usize
)
->
StepBy
<
Self
>
;
}
impl
<
I
:
Iterator
>
IterEx
for
I
{
fn
iter_step_by
(
self
,
n
:
usize
)
->
StepBy
<
Self
>
{
self
.step_by
(
n
)
}
}
#[test]
fn
test_lt
()
{
let
empty
:
[
isize
;
0
]
=
[];
...
...
@@ -76,7 +67,7 @@ fn test_multi_iter() {
#[test]
fn
test_counter_from_iter
()
{
let
it
=
(
0
..
)
.
iter_
step_by
(
5
)
.take
(
10
);
let
it
=
(
0
..
)
.step_by
(
5
)
.take
(
10
);
let
xs
:
Vec
<
isize
>
=
FromIterator
::
from_iter
(
it
);
assert_eq!
(
xs
,
[
0
,
5
,
10
,
15
,
20
,
25
,
30
,
35
,
40
,
45
]);
}
...
...
@@ -94,7 +85,7 @@ fn test_iterator_chain() {
}
assert_eq!
(
i
,
expected
.len
());
let
ys
=
(
30
..
)
.
iter_
step_by
(
10
)
.take
(
4
);
let
ys
=
(
30
..
)
.step_by
(
10
)
.take
(
4
);
let
it
=
xs
.iter
()
.cloned
()
.chain
(
ys
);
let
mut
i
=
0
;
for
x
in
it
{
...
...
@@ -156,13 +147,13 @@ fn test_iterator_chain_find() {
#[test]
fn
test_iterator_step_by
()
{
// Identity
let
mut
it
=
(
0
..
)
.
iter_
step_by
(
1
)
.take
(
3
);
let
mut
it
=
(
0
..
)
.step_by
(
1
)
.take
(
3
);
assert_eq!
(
it
.next
(),
Some
(
0
));
assert_eq!
(
it
.next
(),
Some
(
1
));
assert_eq!
(
it
.next
(),
Some
(
2
));
assert_eq!
(
it
.next
(),
None
);
let
mut
it
=
(
0
..
)
.
iter_
step_by
(
3
)
.take
(
4
);
let
mut
it
=
(
0
..
)
.step_by
(
3
)
.take
(
4
);
assert_eq!
(
it
.next
(),
Some
(
0
));
assert_eq!
(
it
.next
(),
Some
(
3
));
assert_eq!
(
it
.next
(),
Some
(
6
));
...
...
@@ -173,7 +164,7 @@ fn test_iterator_step_by() {
#[test]
#[should_panic]
fn
test_iterator_step_by_zero
()
{
let
mut
it
=
(
0
..
)
.
iter_
step_by
(
0
);
let
mut
it
=
(
0
..
)
.step_by
(
0
);
it
.next
();
}
...
...
@@ -252,7 +243,7 @@ fn test(self) -> bool { true }
#[test]
fn
test_filter_map
()
{
let
it
=
(
0
..
)
.
iter_
step_by
(
1
)
.take
(
10
)
let
it
=
(
0
..
)
.step_by
(
1
)
.take
(
10
)
.filter_map
(|
x
|
if
x
%
2
==
0
{
Some
(
x
*
x
)
}
else
{
None
});
assert_eq!
(
it
.collect
::
<
Vec
<
usize
>>
(),
[
0
*
0
,
2
*
2
,
4
*
4
,
6
*
6
,
8
*
8
]);
}
...
...
@@ -654,7 +645,7 @@ fn add(old: &mut isize, new: &usize) -> Option<f64> {
fn
test_iterator_flat_map
()
{
let
xs
=
[
0
,
3
,
6
];
let
ys
=
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
];
let
it
=
xs
.iter
()
.flat_map
(|
&
x
|
(
x
..
)
.
iter_
step_by
(
1
)
.take
(
3
));
let
it
=
xs
.iter
()
.flat_map
(|
&
x
|
(
x
..
)
.step_by
(
1
)
.take
(
3
));
let
mut
i
=
0
;
for
x
in
it
{
assert_eq!
(
x
,
ys
[
i
]);
...
...
@@ -680,13 +671,13 @@ fn test_inspect() {
#[test]
fn
test_cycle
()
{
let
cycle_len
=
3
;
let
it
=
(
0
..
)
.
iter_
step_by
(
1
)
.take
(
cycle_len
)
.cycle
();
let
it
=
(
0
..
)
.step_by
(
1
)
.take
(
cycle_len
)
.cycle
();
assert_eq!
(
it
.size_hint
(),
(
usize
::
MAX
,
None
));
for
(
i
,
x
)
in
it
.take
(
100
)
.enumerate
()
{
assert_eq!
(
i
%
cycle_len
,
x
);
}
let
mut
it
=
(
0
..
)
.
iter_
step_by
(
1
)
.take
(
0
)
.cycle
();
let
mut
it
=
(
0
..
)
.step_by
(
1
)
.take
(
0
)
.cycle
();
assert_eq!
(
it
.size_hint
(),
(
0
,
Some
(
0
)));
assert_eq!
(
it
.next
(),
None
);
}
...
...
@@ -765,7 +756,7 @@ fn test_iterator_min() {
#[test]
fn
test_iterator_size_hint
()
{
let
c
=
(
0
..
)
.
iter_
step_by
(
1
);
let
c
=
(
0
..
)
.step_by
(
1
);
let
v
:
&
[
_
]
=
&
[
0
,
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
];
let
v2
=
&
[
10
,
11
,
12
];
let
vi
=
v
.iter
();
...
...
@@ -1090,8 +1081,8 @@ fn test_range_step() {
#![allow(deprecated)]
assert_eq!
((
0
..
20
)
.step_by
(
5
)
.collect
::
<
Vec
<
isize
>>
(),
[
0
,
5
,
10
,
15
]);
assert_eq!
((
20
..
0
)
.step_by
(
-
5
)
.collect
::
<
Vec
<
isize
>>
(),
[
20
,
15
,
10
,
5
]);
assert_eq!
((
20
..
0
)
.step_by
(
-
6
)
.collect
::
<
Vec
<
isize
>>
(),
[
20
,
14
,
8
,
2
]);
assert_eq!
((
1
..
21
)
.rev
()
.step_by
(
5
)
.collect
::
<
Vec
<
isize
>>
(),
[
20
,
15
,
10
,
5
]);
assert_eq!
((
1
..
21
)
.rev
()
.step_by
(
6
)
.collect
::
<
Vec
<
isize
>>
(),
[
20
,
14
,
8
,
2
]);
assert_eq!
((
200
..
255
)
.step_by
(
50
)
.collect
::
<
Vec
<
u8
>>
(),
[
200
,
250
]);
assert_eq!
((
200
..-
5
)
.step_by
(
1
)
.collect
::
<
Vec
<
isize
>>
(),
[]);
assert_eq!
((
200
..
200
)
.step_by
(
1
)
.collect
::
<
Vec
<
isize
>>
(),
[]);
...
...
@@ -1099,13 +1090,12 @@ fn test_range_step() {
assert_eq!
((
0
..
20
)
.step_by
(
1
)
.size_hint
(),
(
20
,
Some
(
20
)));
assert_eq!
((
0
..
20
)
.step_by
(
21
)
.size_hint
(),
(
1
,
Some
(
1
)));
assert_eq!
((
0
..
20
)
.step_by
(
5
)
.size_hint
(),
(
4
,
Some
(
4
)));
assert_eq!
((
20
..
0
)
.step_by
(
-
5
)
.size_hint
(),
(
4
,
Some
(
4
)));
assert_eq!
((
20
..
0
)
.step_by
(
-
6
)
.size_hint
(),
(
4
,
Some
(
4
)));
assert_eq!
((
1
..
21
)
.rev
()
.step_by
(
5
)
.size_hint
(),
(
4
,
Some
(
4
)));
assert_eq!
((
1
..
21
)
.rev
()
.step_by
(
6
)
.size_hint
(),
(
4
,
Some
(
4
)));
assert_eq!
((
20
..-
5
)
.step_by
(
1
)
.size_hint
(),
(
0
,
Some
(
0
)));
assert_eq!
((
20
..
20
)
.step_by
(
1
)
.size_hint
(),
(
0
,
Some
(
0
)));
assert_eq!
((
0
..
1
)
.step_by
(
0
)
.size_hint
(),
(
0
,
None
));
assert_eq!
((
i8
::
MAX
..
i8
::
MIN
)
.step_by
(
i8
::
MIN
)
.size_hint
(),
(
2
,
Some
(
2
)));
assert_eq!
((
i16
::
MIN
..
i16
::
MAX
)
.step_by
(
i16
::
MAX
)
.size_hint
(),
(
3
,
Some
(
3
)));
assert_eq!
((
i8
::
MIN
..
i8
::
MAX
)
.step_by
(
-
(
i8
::
MIN
as
i32
)
as
usize
)
.size_hint
(),
(
2
,
Some
(
2
)));
assert_eq!
((
i16
::
MIN
..
i16
::
MAX
)
.step_by
(
i16
::
MAX
as
usize
)
.size_hint
(),
(
3
,
Some
(
3
)));
assert_eq!
((
isize
::
MIN
..
isize
::
MAX
)
.step_by
(
1
)
.size_hint
(),
(
usize
::
MAX
,
Some
(
usize
::
MAX
)));
}
...
...
src/libcore/tests/lib.rs
浏览文件 @
dcd332ed
...
...
@@ -36,7 +36,6 @@
#![feature(sort_internals)]
#![feature(sort_unstable)]
#![feature(specialization)]
#![feature(step_by)]
#![feature(step_trait)]
#![feature(test)]
#![feature(trusted_len)]
...
...
src/librand/lib.rs
浏览文件 @
dcd332ed
...
...
@@ -31,7 +31,7 @@
issue
=
"27703"
)]
#![feature(core_intrinsics)]
#![feature(staged_api)]
#![feature(step_by)]
#![feature(
iterator_
step_by)]
#![feature(custom_attribute)]
#![feature(specialization)]
#![allow(unused_attributes)]
...
...
src/test/run-pass/range_inclusive.rs
浏览文件 @
dcd332ed
...
...
@@ -10,7 +10,7 @@
// Test inclusive range syntax.
#![feature(inclusive_range_syntax,
inclusive_range,
step_by)]
#![feature(inclusive_range_syntax,
inclusive_range,
iterator_
step_by)]
use
std
::
ops
::{
RangeInclusive
,
RangeToInclusive
};
...
...
src/test/run-pass/sync-send-iterators-in-libcore.rs
浏览文件 @
dcd332ed
...
...
@@ -14,7 +14,7 @@
#![feature(iter_empty)]
#![feature(iter_once)]
#![feature(iter_unfold)]
#![feature(step_by)]
#![feature(
iterator_
step_by)]
#![feature(str_escape)]
use
std
::
iter
::{
empty
,
once
,
repeat
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录