Skip to content
Myr

Use concat/stringify macros by absolute path

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by David Tolnay · committed by David Tolnay · parent cb57a41 · Browse files · 3 files+52 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+52 added−6 removed

  • other:+52 added−6 removed

3 files+52 added−6 removed

modified:src/lib.rs+23 added
620 unmodified lines
621 M: Display + Debug + Send + Sync + 'static,622 {623 Error::from_adhoc(message, backtrace!())624 }625626 #[cfg(anyhow_no_macro_reexport)]627 pub use crate::{__anyhow_concat as concat, __anyhow_stringify as stringify};628 #[cfg(not(anyhow_no_macro_reexport))]629 pub use core::{concat, stringify};630631 #[cfg(anyhow_no_macro_reexport)]632 #[doc(hidden)]633 #[macro_export]634 macro_rules! __anyhow_concat {635 ($($tt:tt)*) => {636 concat!($($tt)*)637 };638 }639640 #[cfg(anyhow_no_macro_reexport)]641 #[doc(hidden)]642 #[macro_export]643 macro_rules! __anyhow_stringify {644 ($($tt:tt)*) => {645 stringify!($($tt)*)646 };647 }648}
modified:src/macros.rs+4 added-1 removed
112 unmodified lines
113/// ```114#[macro_export]115macro_rules! ensure {116 ($cond:expr $(,)?) => {117 $crate::ensure!($cond, concat!("Condition failed: `", stringify!($cond), "`"))117 $crate::ensure!(118 $cond,119 $crate::private::concat!("Condition failed: `", $crate::private::stringify!($cond), "`"),120 )121 };122 ($cond:expr, $msg:literal $(,)?) => {123 if !$cond {124 return $crate::private::Err($crate::anyhow!($msg));
58 unmodified lines
modified:build.rs+25 added-5 removed
1use std::env;2use std::fs;3use std::path::Path;4use std::process::{Command, ExitStatus, Stdio};5use std::str;67// This code exercises the surface area that we expect of the std Backtrace8// type. If the current toolchain is able to compile it, we go ahead and use9// backtrace in anyhow.
25 unmodified lines
35 }36"#;3738fn main() {38 if !cfg!(feature = "std") {39 return;39 if cfg!(feature = "std") {40 match compile_probe() {41 Some(status) if status.success() => println!("cargo:rustc-cfg=backtrace"),42 _ => {}43 }44 }41 match compile_probe() {42 Some(status) if status.success() => println!("cargo:rustc-cfg=backtrace"),43 _ => {}4546 let rustc = match rustc_minor_version() {47 Some(rustc) => rustc,48 None => return,49 };5051 if rustc < 38 {52 println!("cargo:rustc-cfg=anyhow_no_macro_reexport");53 }54}5556fn compile_probe() -> Option<ExitStatus> {
12 unmodified lines
69 .arg(probefile)70 .status()71 .ok()72}7374fn rustc_minor_version() -> Option<u32> {75 let rustc = env::var_os("RUSTC")?;76 let output = Command::new(rustc).arg("--version").output().ok()?;77 let version = str::from_utf8(&output.stdout).ok()?;78 let mut pieces = version.split('.');79 if pieces.next() != Some("rustc 1") {80 return None;81 }82 pieces.next()?.parse().ok()83}