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
Provenance
- Commit
435f5ec- Tree
6a3fbef- Author
David Tolnay <dtolnay@gmail.com>- Committer
David Tolnay <dtolnay@gmail.com>- Parent
cb57a41
3 files changed+52 added−6 removed
modified:src/lib.rs+23 added
620 unmodified lines621 M: Display + Debug + Send + Sync + 'static,622 {623 Error::from_adhoc(message, backtrace!())624 }625+626+ #[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};630+631+ #[cfg(anyhow_no_macro_reexport)]632+ #[doc(hidden)]633+ #[macro_export]634+ macro_rules! __anyhow_concat {635+ ($($tt:tt)*) => {636+ concat!($($tt)*)637+ };638+ }639+640+ #[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 lines113 /// ```114 #[macro_export]115 macro_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 linesmodified:build.rs+25 added-5 removed
1 use std::env;2 use std::fs;3 use std::path::Path;4 use std::process::{Command, ExitStatus, Stdio};5+use std::str;6 7 // 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 lines35 }36 "#;37 38 fn 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- _ => {}45+46+ let rustc = match rustc_minor_version() {47+ Some(rustc) => rustc,48+ None => return,49+ };50+51+ if rustc < 38 {52+ println!("cargo:rustc-cfg=anyhow_no_macro_reexport");53 }54 }55 56 fn compile_probe() -> Option<ExitStatus> {12 unmodified lines69 .arg(probefile)70 .status()71 .ok()72 }73+74+fn 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+}