Merge pull request #334 from dtolnay/probe
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Move probe.rs out of build script string literal into file
authored by David Tolnay · committed by GitHub · parents 199c625, b332769 · Browse files · 2 files·+35 added−38 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+35 added−38 removed
- other:+35 added−38 removed
Provenance
- Commit
15646f4- Tree
bb4425f- Author
David Tolnay <dtolnay@gmail.com>- Committer
GitHub <noreply@github.com>- Parent 1
199c625- Parent 2
b332769
2 files changed+35 added−38 removed
added:build/probe.rs+32 added
1+// This code exercises the surface area that we expect of the Error generic2+// member access API. If the current toolchain is able to compile it, then3+// anyhow is able to provide backtrace support.4+5+#![feature(error_generic_member_access)]6+7+use std::backtrace::Backtrace;8+use std::error::{self, Error, Request};9+use std::fmt::{self, Debug, Display};10+11+struct MyError(Thing);12+struct Thing;13+14+impl Debug for MyError {15+ fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {16+ unimplemented!()17+ }18+}19+20+impl Display for MyError {21+ fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {22+ unimplemented!()23+ }24+}25+26+impl Error for MyError {27+ fn provide<'a>(&'a self, request: &mut Request<'a>) {28+ request.provide_ref(&self.0);29+ }30+}31+32+const _: fn(&dyn Error) -> Option<&Backtrace> = |err| error::request_ref::<Backtrace>(err);modified:build.rs+3 added-38 removed
1-#![allow(clippy::needless_raw_string_hashes, clippy::option_if_let_else)]1+#![allow(clippy::option_if_let_else)]2 3 use std::env;4-use std::fs;4 use std::path::Path;5 use std::process::{Command, ExitStatus, Stdio};6 use std::str;7 1 unmodified line9 compile_error! {10 "`backtrace` feature without `std` feature is not supported"11 }12 14-// This code exercises the surface area that we expect of the Error generic15-// member access API. If the current toolchain is able to compile it, then16-// anyhow is able to provide backtrace support.17-const PROBE: &str = r#"18- #![feature(error_generic_member_access)]19-20- use std::backtrace::Backtrace;21- use std::error::{self, Error, Request};22- use std::fmt::{self, Debug, Display};23-24- struct MyError(Thing);25- struct Thing;26-27- impl Debug for MyError {28- fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {29- unimplemented!()30- }31- }32-33- impl Display for MyError {34- fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {35- unimplemented!()36- }37- }38-39- impl Error for MyError {40- fn provide<'a>(&'a self, request: &mut Request<'a>) {41- request.provide_ref(&self.0);42- }43- }44-45- const _: fn(&dyn Error) -> Option<&Backtrace> = |err| error::request_ref::<Backtrace>(err);46-"#;47-13 fn main() {14 let mut error_generic_member_access = false;15 if cfg!(feature = "std") {16+ println!("cargo:rerun-if-changed=build/probe.rs");17 println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");18 19 match compile_probe() {20 Some(status) if status.success() => {46 unmodified lines67 }68 69 let rustc = env::var_os("RUSTC")?;70 let out_dir = env::var_os("OUT_DIR")?;105- let probefile = Path::new(&out_dir).join("probe.rs");106- fs::write(&probefile, PROBE).ok()?;71+ let probefile = Path::new("build").join("probe.rs");72 73 // Make sure to pick up Cargo rustc configuration.74 let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER") {75 let mut cmd = Command::new(wrapper);42 unmodified lines