Skip to content

Btree: assert more API compatibility #91746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions library/alloc/src/collections/btree/map/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1556,7 +1556,7 @@ fn test_clone_from() {
}

#[allow(dead_code)]
fn test_variance() {
fn assert_covariance() {
fn map_key<'new>(v: BTreeMap<&'static str, ()>) -> BTreeMap<&'new str, ()> {
v
}
Expand Down Expand Up @@ -1615,7 +1615,7 @@ fn test_variance() {
}

#[allow(dead_code)]
fn test_sync() {
fn assert_sync() {
fn map<T: Sync>(v: &BTreeMap<T, T>) -> impl Sync + '_ {
v
}
Expand Down Expand Up @@ -1684,7 +1684,7 @@ fn test_sync() {
}

#[allow(dead_code)]
fn test_send() {
fn assert_send() {
fn map<T: Send>(v: BTreeMap<T, T>) -> impl Send {
v
}
Expand Down
38 changes: 35 additions & 3 deletions library/alloc/src/collections/btree/set/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use super::super::testing::rng::DeterministicRng;
use super::*;
use crate::vec::Vec;
use std::cmp::Ordering;
use std::hash::{Hash, Hasher};
use std::iter::FromIterator;
use std::panic::{catch_unwind, AssertUnwindSafe};

Expand Down Expand Up @@ -513,7 +514,7 @@ fn test_recovery() {
}

#[allow(dead_code)]
fn test_variance() {
fn assert_covariance() {
fn set<'new>(v: BTreeSet<&'static str>) -> BTreeSet<&'new str> {
v
}
Expand All @@ -530,7 +531,7 @@ fn test_variance() {
}

#[allow(dead_code)]
fn test_sync() {
fn assert_sync() {
fn set<T: Sync>(v: &BTreeSet<T>) -> impl Sync + '_ {
v
}
Expand Down Expand Up @@ -569,7 +570,7 @@ fn test_sync() {
}

#[allow(dead_code)]
fn test_send() {
fn assert_send() {
fn set<T: Send>(v: BTreeSet<T>) -> impl Send {
v
}
Expand Down Expand Up @@ -607,6 +608,37 @@ fn test_send() {
}
}

#[allow(dead_code)]
// Check that the member-like functions conditionally provided by #[derive()]
// are not overriden by genuine member functions with a different signature.
fn assert_derives() {
fn hash<T: Hash, H: Hasher>(v: BTreeSet<T>, state: &mut H) {
v.hash(state);
// Tested much more thoroughly outside the crate in btree_set_hash.rs
}
fn eq<T: PartialEq>(v: BTreeSet<T>) {
let _ = v.eq(&v);
}
fn ne<T: PartialEq>(v: BTreeSet<T>) {
let _ = v.ne(&v);
}
fn cmp<T: Ord>(v: BTreeSet<T>) {
let _ = v.cmp(&v);
}
fn min<T: Ord>(v: BTreeSet<T>, w: BTreeSet<T>) {
let _ = v.min(w);
}
fn max<T: Ord>(v: BTreeSet<T>, w: BTreeSet<T>) {
let _ = v.max(w);
}
fn clamp<T: Ord>(v: BTreeSet<T>, w: BTreeSet<T>, x: BTreeSet<T>) {
let _ = v.clamp(w, x);
}
fn partial_cmp<T: PartialOrd>(v: &BTreeSet<T>) {
let _ = v.partial_cmp(&v);
}
}

#[test]
fn test_ord_absence() {
fn set<K>(mut set: BTreeSet<K>) {
Expand Down