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

Use autocfg instead of version_check #40

Closed
wants to merge 2 commits into from
Closed
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ exclude = [
build = "build.rs"

[build-dependencies]
version_check = "0.9"
autocfg = "0.1"

[features]
nightly = []
26 changes: 9 additions & 17 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
extern crate version_check as rustc;
extern crate autocfg;

fn main() {
if is_rustc_at_least("1.5.0") {
println!("cargo:rustc-cfg=__unicase__iter_cmp");
}
autocfg::rerun_path(file!());

if is_rustc_at_least("1.13.0") {
println!("cargo:rustc-cfg=__unicase__default_hasher");
}
let ac = autocfg::new();

if is_rustc_at_least("1.31.0") {
println!("cargo:rustc-cfg=__unicase__const_fns");
}
ac.emit_has_path("core::iter::Iterator::cmp");
ac.emit_has_type("std::collections::hash_map::DefaultHasher");

if is_rustc_at_least("1.36.0") {
println!("cargo:rustc-cfg=__unicase__core_and_alloc");
}
}
// For `const fn` support
ac.emit_rustc_version(1, 31);

fn is_rustc_at_least(v: &str) -> bool {
rustc::is_min_version(v).unwrap_or(true)
}
ac.emit_sysroot_crate("alloc");
}
20 changes: 10 additions & 10 deletions src/ascii.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
use alloc::string::String;
#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
use core::ops::{Deref, DerefMut};
use core::str::FromStr;
#[cfg(not(__unicase__core_and_alloc))]
#[cfg(not(has_alloc))]
#[allow(deprecated, unused)]
use std::ascii::AsciiExt;

use super::{Ascii, Encoding, UniCase};

impl<S> Ascii<S> {
#[inline]
#[cfg(__unicase__const_fns)]
#[cfg(rustc_1_31)]
pub const fn new(s: S) -> Ascii<S> {
Ascii(s)
}
Expand All @@ -22,7 +22,7 @@ impl<S> Ascii<S> {
///
/// For Rust versions >= 1.31, this is a `const fn`.
#[inline]
#[cfg(not(__unicase__const_fns))]
#[cfg(not(rustc_1_31))]
pub fn new(s: S) -> Ascii<S> {
Ascii(s)
}
Expand Down Expand Up @@ -58,15 +58,15 @@ impl<S> DerefMut for Ascii<S> {
}
}

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
impl<T: AsRef<str>> PartialOrd for Ascii<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
impl<T: AsRef<str>> Ord for Ascii<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand Down Expand Up @@ -134,9 +134,9 @@ impl<S: AsRef<str>> Hash for Ascii<S> {
mod tests {
use ::Ascii;
use std::hash::{Hash, Hasher};
#[cfg(not(__unicase__default_hasher))]
#[cfg(not(has_std__collections__hash_map__DefaultHasher))]
use std::hash::SipHasher as DefaultHasher;
#[cfg(__unicase__default_hasher)]
#[cfg(has_std__collections__hash_map__DefaultHasher)]
use std::collections::hash_map::DefaultHasher;

fn hash<T: Hash>(t: &T) -> u64 {
Expand Down Expand Up @@ -166,7 +166,7 @@ mod tests {
b.iter(|| assert_eq!(Ascii("foobar"), Ascii("FOOBAR")));
}

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
#[test]
fn test_case_cmp() {
assert!(Ascii("foobar") == Ascii("FOOBAR"));
Expand All @@ -179,7 +179,7 @@ mod tests {
assert!(Ascii("a") < Ascii("AA"));
}

#[cfg(__unicase__const_fns)]
#[cfg(rustc_1_31)]
#[test]
fn test_ascii_new_const() {
const _ASCII: Ascii<&'static str> = Ascii::new("");
Expand Down
34 changes: 17 additions & 17 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#![cfg_attr(feature = "nightly", feature(test))]
#![cfg_attr(
all(
__unicase__core_and_alloc,
has_alloc,
not(test),
),
no_std,
Expand Down Expand Up @@ -52,18 +52,18 @@
#[cfg(feature = "nightly")]
extern crate test;

#[cfg(all(__unicase__core_and_alloc, not(test)))]
#[cfg(all(has_alloc, not(test)))]
extern crate alloc;
#[cfg(all(__unicase__core_and_alloc, not(test)))]
#[cfg(all(has_alloc, not(test)))]
use alloc::string::String;

#[cfg(not(all(__unicase__core_and_alloc, not(test))))]
#[cfg(not(all(has_alloc, not(test))))]
extern crate std as alloc;
#[cfg(not(all(__unicase__core_and_alloc, not(test))))]
#[cfg(not(all(has_alloc, not(test))))]
extern crate std as core;

use alloc::borrow::Cow;
#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
use core::cmp::Ordering;
use core::fmt;
use core::hash::{Hash, Hasher};
Expand Down Expand Up @@ -135,7 +135,7 @@ impl<S: AsRef<str>> UniCase<S> {
///
/// Note: This scans the text to determine if it is all ASCII or not.
pub fn new(s: S) -> UniCase<S> {
#[cfg(not(__unicase__core_and_alloc))]
#[cfg(not(has_alloc))]
#[allow(deprecated, unused)]
use std::ascii::AsciiExt;

Expand All @@ -149,29 +149,29 @@ impl<S: AsRef<str>> UniCase<S> {

impl<S> UniCase<S> {
/// Creates a new `UniCase`, skipping the ASCII check.
#[cfg(__unicase__const_fns)]
#[cfg(rustc_1_31)]
pub const fn unicode(s: S) -> UniCase<S> {
UniCase(Encoding::Unicode(Unicode(s)))
}

/// Creates a new `UniCase`, skipping the ASCII check.
///
/// For Rust versions >= 1.31, this is a `const fn`.
#[cfg(not(__unicase__const_fns))]
#[cfg(not(rustc_1_31))]
pub fn unicode(s: S) -> UniCase<S> {
UniCase(Encoding::Unicode(Unicode(s)))
}

/// Creates a new `UniCase` which performs only ASCII case folding.
#[cfg(__unicase__const_fns)]
#[cfg(rustc_1_31)]
pub const fn ascii(s: S) -> UniCase<S> {
UniCase(Encoding::Ascii(Ascii(s)))
}

/// Creates a new `UniCase` which performs only ASCII case folding.
///
/// For Rust versions >= 1.31, this is a `const fn`.
#[cfg(not(__unicase__const_fns))]
#[cfg(not(rustc_1_31))]
pub fn ascii(s: S) -> UniCase<S> {
UniCase(Encoding::Ascii(Ascii(s)))
}
Expand Down Expand Up @@ -299,15 +299,15 @@ into_impl!(&'a str);
into_impl!(String);
into_impl!(Cow<'a, str>);

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
impl<T: AsRef<str>> PartialOrd for UniCase<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
impl<T: AsRef<str>> Ord for UniCase<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand All @@ -333,9 +333,9 @@ impl<S: FromStr + AsRef<str>> FromStr for UniCase<S> {
mod tests {
use super::UniCase;
use std::hash::{Hash, Hasher};
#[cfg(not(__unicase__default_hasher))]
#[cfg(not(has_std__collections__hash_map__DefaultHasher))]
use std::hash::SipHasher as DefaultHasher;
#[cfg(__unicase__default_hasher)]
#[cfg(has_std__collections__hash_map__DefaultHasher)]
use std::collections::hash_map::DefaultHasher;

fn hash<T: Hash>(t: &T) -> u64 {
Expand Down Expand Up @@ -422,7 +422,7 @@ mod tests {
b.iter(|| assert!(::std::str::from_utf8(SUBJECT).is_ok()));
}

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
#[test]
fn test_case_cmp() {
assert!(UniCase::new("a") < UniCase::new("B"));
Expand Down Expand Up @@ -457,7 +457,7 @@ mod tests {
let _: &str = owned.as_ref();
}

#[cfg(__unicase__const_fns)]
#[cfg(rustc_1_31)]
#[test]
fn test_unicase_unicode_const() {
const _UNICASE: UniCase<&'static str> = UniCase::unicode("");
Expand Down
6 changes: 3 additions & 3 deletions src/unicode/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
use core::cmp::Ordering;
use core::hash::{Hash, Hasher};

Expand Down Expand Up @@ -35,15 +35,15 @@ impl<S1: AsRef<str>, S2: AsRef<str>> PartialEq<Unicode<S2>> for Unicode<S1> {

impl<S: AsRef<str>> Eq for Unicode<S> {}

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
impl<T: AsRef<str>> PartialOrd for Unicode<T> {
#[inline]
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}

#[cfg(__unicase__iter_cmp)]
#[cfg(has_core__iter__Iterator__cmp)]
impl<T: AsRef<str>> Ord for Unicode<T> {
#[inline]
fn cmp(&self, other: &Self) -> Ordering {
Expand Down