Skip to content
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

Simplify/remove build.rs following the bump to 2021 edition #1062

Merged
merged 7 commits into from
Sep 11, 2023
37 changes: 0 additions & 37 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
use std::env;
use std::process::Command;
use std::str::{self, FromStr};

fn main() {
println!("cargo:rerun-if-changed=build.rs");
Expand All @@ -16,39 +14,4 @@ fn main() {
println!("cargo:rustc-cfg=limb_width_32");
}
}

let minor = match rustc_minor_version() {
Some(minor) => minor,
None => return,
};

// BTreeMap::get_key_value
// https://blog.rust-lang.org/2019/12/19/Rust-1.40.0.html#additions-to-the-standard-library
if minor < 40 {
println!("cargo:rustc-cfg=no_btreemap_get_key_value");
}

// BTreeMap::remove_entry
// https://blog.rust-lang.org/2020/07/16/Rust-1.45.0.html#library-changes
if minor < 45 {
println!("cargo:rustc-cfg=no_btreemap_remove_entry");
}

// BTreeMap::retain
// https://blog.rust-lang.org/2021/06/17/Rust-1.53.0.html#stabilized-apis
if minor < 53 {
println!("cargo:rustc-cfg=no_btreemap_retain");
}
}

fn rustc_minor_version() -> Option<u32> {
let rustc = env::var_os("RUSTC")?;
let output = Command::new(rustc).arg("--version").output().ok()?;
let version = str::from_utf8(&output.stdout).ok()?;
let mut pieces = version.split('.');
if pieces.next() != Some("rustc 1") {
return None;
}
let next = pieces.next()?;
u32::from_str(next).ok()
}
41 changes: 1 addition & 40 deletions src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ impl Map<String, Value> {
/// The key may be any borrowed form of the map's key type, but the ordering
/// on the borrowed form *must* match the ordering on the key type.
#[inline]
#[cfg(any(feature = "preserve_order", not(no_btreemap_get_key_value)))]
pub fn get_key_value<Q>(&self, key: &Q) -> Option<(&String, &Value)>
where
String: Borrow<Q>,
Expand Down Expand Up @@ -153,44 +152,7 @@ impl Map<String, Value> {
String: Borrow<Q>,
Q: ?Sized + Ord + Eq + Hash,
{
#[cfg(any(feature = "preserve_order", not(no_btreemap_remove_entry)))]
return self.map.remove_entry(key);
#[cfg(all(
not(feature = "preserve_order"),
no_btreemap_remove_entry,
not(no_btreemap_get_key_value),
))]
{
let (key, _value) = self.map.get_key_value(key)?;
let key = key.clone();
let value = self.map.remove::<String>(&key)?;
Some((key, value))
}
#[cfg(all(
not(feature = "preserve_order"),
no_btreemap_remove_entry,
no_btreemap_get_key_value,
))]
{
use core::ops::{Bound, RangeBounds};

struct Key<'a, Q: ?Sized>(&'a Q);

impl<'a, Q: ?Sized> RangeBounds<Q> for Key<'a, Q> {
fn start_bound(&self) -> Bound<&Q> {
Bound::Included(self.0)
}
fn end_bound(&self) -> Bound<&Q> {
Bound::Included(self.0)
}
}

let mut range = self.map.range(Key(key));
let (key, _value) = range.next()?;
let key = key.clone();
let value = self.map.remove::<String>(&key)?;
Some((key, value))
}
self.map.remove_entry(key)
}

/// Moves all elements from other into self, leaving other empty.
Expand Down Expand Up @@ -276,7 +238,6 @@ impl Map<String, Value> {
///
/// In other words, remove all pairs `(k, v)` such that `f(&k, &mut v)`
/// returns `false`.
#[cfg(not(no_btreemap_retain))]
#[inline]
pub fn retain<F>(&mut self, f: F)
where
Expand Down
1 change: 0 additions & 1 deletion tests/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ fn test_append() {
assert!(val.is_empty());
}

#[cfg(not(no_btreemap_retain))]
#[test]
fn test_retain() {
let mut v: Value = from_str(r#"{"b":null,"a":null,"c":null}"#).unwrap();
Expand Down