Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
f33f266a
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
f33f266a
编写于
8月 15, 2021
作者:
G
Gary Guo
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
BTree: remove Ord bound from new
上级
adf16884
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
24 addition
and
44 deletion
+24
-44
library/alloc/src/collections/btree/map.rs
library/alloc/src/collections/btree/map.rs
+4
-9
library/alloc/src/collections/btree/map/tests.rs
library/alloc/src/collections/btree/map/tests.rs
+7
-1
library/alloc/src/collections/btree/set.rs
library/alloc/src/collections/btree/set.rs
+2
-5
library/alloc/src/collections/btree/set/tests.rs
library/alloc/src/collections/btree/set/tests.rs
+7
-1
library/alloc/tests/const_fns.rs
library/alloc/tests/const_fns.rs
+4
-28
未找到文件。
library/alloc/src/collections/btree/map.rs
浏览文件 @
f33f266a
...
...
@@ -233,9 +233,7 @@ fn clone_subtree<'a, K: Clone, V: Clone>(
}
if
self
.is_empty
()
{
// Ideally we'd call `BTreeMap::new` here, but that has the `K:
// Ord` constraint, which this method lacks.
BTreeMap
{
root
:
None
,
length
:
0
}
BTreeMap
::
new
()
}
else
{
clone_subtree
(
self
.root
.as_ref
()
.unwrap
()
.reborrow
())
// unwrap succeeds because not empty
}
...
...
@@ -499,10 +497,7 @@ impl<K, V> BTreeMap<K, V> {
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
#[rustc_const_unstable(feature
=
"const_btree_new"
,
issue
=
"71835"
)]
pub
const
fn
new
()
->
BTreeMap
<
K
,
V
>
where
K
:
Ord
,
{
pub
const
fn
new
()
->
BTreeMap
<
K
,
V
>
{
BTreeMap
{
root
:
None
,
length
:
0
}
}
...
...
@@ -522,7 +517,7 @@ pub const fn new() -> BTreeMap<K, V>
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
pub
fn
clear
(
&
mut
self
)
{
*
self
=
BTreeMap
{
root
:
None
,
length
:
0
}
;
*
self
=
BTreeMap
::
new
()
;
}
/// Returns a reference to the value corresponding to the key.
...
...
@@ -1957,7 +1952,7 @@ fn hash<H: Hasher>(&self, state: &mut H) {
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
K
:
Ord
,
V
>
Default
for
BTreeMap
<
K
,
V
>
{
impl
<
K
,
V
>
Default
for
BTreeMap
<
K
,
V
>
{
/// Creates an empty `BTreeMap`.
fn
default
()
->
BTreeMap
<
K
,
V
>
{
BTreeMap
::
new
()
...
...
library/alloc/src/collections/btree/map/tests.rs
浏览文件 @
f33f266a
...
...
@@ -1745,7 +1745,7 @@ fn vacant_entry<T: Send + Ord + Default>(v: &mut BTreeMap<T, T>) -> impl Send +
}
}
#[
allow(dead_code)
]
#[
test
]
fn
test_ord_absence
()
{
fn
map
<
K
>
(
mut
map
:
BTreeMap
<
K
,
()
>
)
{
map
.is_empty
();
...
...
@@ -1784,6 +1784,12 @@ fn map_debug<K: Debug>(mut map: BTreeMap<K, ()>) {
fn
map_clone
<
K
:
Clone
>
(
mut
map
:
BTreeMap
<
K
,
()
>
)
{
map
.clone_from
(
&
map
.clone
());
}
#[derive(Debug,
Clone)]
struct
NonOrd
;
map
(
BTreeMap
::
<
NonOrd
,
_
>
::
new
());
map_debug
(
BTreeMap
::
<
NonOrd
,
_
>
::
new
());
map_clone
(
BTreeMap
::
<
NonOrd
,
_
>
::
default
());
}
#[test]
...
...
library/alloc/src/collections/btree/set.rs
浏览文件 @
f33f266a
...
...
@@ -246,10 +246,7 @@ impl<T> BTreeSet<T> {
/// ```
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
#[rustc_const_unstable(feature
=
"const_btree_new"
,
issue
=
"71835"
)]
pub
const
fn
new
()
->
BTreeSet
<
T
>
where
T
:
Ord
,
{
pub
const
fn
new
()
->
BTreeSet
<
T
>
{
BTreeSet
{
map
:
BTreeMap
::
new
()
}
}
...
...
@@ -1192,7 +1189,7 @@ fn extend_one(&mut self, &elem: &'a T) {
}
#[stable(feature
=
"rust1"
,
since
=
"1.0.0"
)]
impl
<
T
:
Ord
>
Default
for
BTreeSet
<
T
>
{
impl
<
T
>
Default
for
BTreeSet
<
T
>
{
/// Creates an empty `BTreeSet`.
fn
default
()
->
BTreeSet
<
T
>
{
BTreeSet
::
new
()
...
...
library/alloc/src/collections/btree/set/tests.rs
浏览文件 @
f33f266a
...
...
@@ -607,7 +607,7 @@ fn union<T: Send + Sync + Ord>(v: &BTreeSet<T>) -> impl Send + '_ {
}
}
#[
allow(dead_code)
]
#[
test
]
fn
test_ord_absence
()
{
fn
set
<
K
>
(
mut
set
:
BTreeSet
<
K
>
)
{
set
.is_empty
();
...
...
@@ -626,6 +626,12 @@ fn set_debug<K: Debug>(set: BTreeSet<K>) {
fn
set_clone
<
K
:
Clone
>
(
mut
set
:
BTreeSet
<
K
>
)
{
set
.clone_from
(
&
set
.clone
());
}
#[derive(Debug,
Clone)]
struct
NonOrd
;
set
(
BTreeSet
::
<
NonOrd
>
::
new
());
set_debug
(
BTreeSet
::
<
NonOrd
>
::
new
());
set_clone
(
BTreeSet
::
<
NonOrd
>
::
default
());
}
#[test]
...
...
library/alloc/tests/const_fns.rs
浏览文件 @
f33f266a
// Test const functions in the library
use
core
::
cmp
::
Ordering
;
// FIXME remove this struct once we put `K: ?const Ord` on BTreeMap::new.
#[derive(PartialEq,
Eq,
PartialOrd)]
pub
struct
MyType
;
impl
const
Ord
for
MyType
{
fn
cmp
(
&
self
,
_
:
&
Self
)
->
Ordering
{
Ordering
::
Equal
}
fn
max
(
self
,
_
:
Self
)
->
Self
{
Self
}
fn
min
(
self
,
_
:
Self
)
->
Self
{
Self
}
fn
clamp
(
self
,
_
:
Self
,
_
:
Self
)
->
Self
{
Self
}
}
pub
const
MY_VEC
:
Vec
<
usize
>
=
Vec
::
new
();
pub
const
MY_VEC2
:
Vec
<
usize
>
=
Default
::
default
();
...
...
@@ -32,13 +8,13 @@ fn clamp(self, _: Self, _: Self) -> Self {
use
std
::
collections
::{
BTreeMap
,
BTreeSet
};
pub
const
MY_BTREEMAP
:
BTreeMap
<
MyType
,
MyTyp
e
>
=
BTreeMap
::
new
();
pub
const
MAP
:
&
'static
BTreeMap
<
MyType
,
MyTyp
e
>
=
&
MY_BTREEMAP
;
pub
const
MY_BTREEMAP
:
BTreeMap
<
usize
,
usiz
e
>
=
BTreeMap
::
new
();
pub
const
MAP
:
&
'static
BTreeMap
<
usize
,
usiz
e
>
=
&
MY_BTREEMAP
;
pub
const
MAP_LEN
:
usize
=
MAP
.len
();
pub
const
MAP_IS_EMPTY
:
bool
=
MAP
.is_empty
();
pub
const
MY_BTREESET
:
BTreeSet
<
MyTyp
e
>
=
BTreeSet
::
new
();
pub
const
SET
:
&
'static
BTreeSet
<
MyTyp
e
>
=
&
MY_BTREESET
;
pub
const
MY_BTREESET
:
BTreeSet
<
usiz
e
>
=
BTreeSet
::
new
();
pub
const
SET
:
&
'static
BTreeSet
<
usiz
e
>
=
&
MY_BTREESET
;
pub
const
SET_LEN
:
usize
=
SET
.len
();
pub
const
SET_IS_EMPTY
:
bool
=
SET
.is_empty
();
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录