6b96050d1f Document `cfg` (Martin Habovstiak)
6fc4860813 Activate `rust_v_1_46` when on high-enough rustc (Martin Habovstiak)

Pull request description:

  This fixes minor mistakes that I made in previous PR.

ACKs for top commit:
  apoelstra:
    ACK 6b96050d1f
  tcharding:
    tACK 6b96050d1f

Tree-SHA512: a926d1b642058538c3a61760593c387a9316050d7468c3eefd18c7a6c1109e736032ac49704b16f418dc0649fe110d48e188cb6b267f002ac60803f0f5a9fedb
This commit is contained in:
Andrew Poelstra 2022-09-14 23:53:50 +00:00
commit 836063dbad
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
2 changed files with 38 additions and 0 deletions

34
internals/build.rs Normal file
View File

@ -0,0 +1,34 @@
fn main() {
let rustc = std::env::var_os("RUSTC");
let rustc = rustc.as_ref().map(std::path::Path::new).unwrap_or_else(|| "rustc".as_ref());
let output = std::process::Command::new(rustc)
.arg("--version")
.output()
.unwrap_or_else(|error| panic!("Failed to run `{:?} --version`: {:?}", rustc, error));
assert!(output.status.success(), "{:?} -- version returned non-zero exit code", rustc);
let stdout = String::from_utf8(output.stdout).expect("rustc produced non-UTF-8 output");
let version_prefix = "rustc ";
if !stdout.starts_with(version_prefix) {
panic!("unexpected rustc output: {}", stdout);
}
let version = &stdout[version_prefix.len()..];
let end = version.find(&[' ', '-'] as &[_]).unwrap_or(version.len());
let version = &version[..end];
let mut version_components = version.split('.');
let major = version_components.next().unwrap();
assert_eq!(major, "1", "Unexpected Rust major version");
let minor = version_components
.next()
.unwrap_or("0")
.parse::<u64>()
.expect("invalid Rust minor version");
// print cfg for all interesting versions less than or equal to minor
// 46 adds `track_caller`
for version in &[46] {
if *version <= minor {
println!("cargo:rustc-cfg=rust_v_1_{}", version);
}
}
}

View File

@ -45,6 +45,7 @@ pub trait DisplayHex: Copy + sealed::IsRef {
///
/// This may be faster than `.display_hex().to_string()` because it uses `reserve_suggestion`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn to_lower_hex_string(self) -> String {
self.to_hex_string(Case::Lower)
}
@ -55,6 +56,7 @@ pub trait DisplayHex: Copy + sealed::IsRef {
///
/// This may be faster than `.display_hex().to_string()` because it uses `reserve_suggestion`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn to_upper_hex_string(self) -> String {
self.to_hex_string(Case::Upper)
}
@ -63,6 +65,7 @@ pub trait DisplayHex: Copy + sealed::IsRef {
///
/// This may be faster than `.display_hex().to_string()` because it uses `reserve_suggestion`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn to_hex_string(self, case: Case) -> String {
let mut string = String::new();
self.append_hex_to_string(case, &mut string);
@ -74,6 +77,7 @@ pub trait DisplayHex: Copy + sealed::IsRef {
/// This may be faster than `write!(string, "{}", self.display_hex())` because it uses
/// `reserve_sugggestion`.
#[cfg(feature = "alloc")]
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn append_hex_to_string(self, case: Case, string: &mut String) {
use fmt::Write;