Skip to content
Myr

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

2 files+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.45#![feature(error_generic_member_access)]67use std::backtrace::Backtrace;8use std::error::{self, Error, Request};9use std::fmt::{self, Debug, Display};1011struct MyError(Thing);12struct Thing;1314impl Debug for MyError {15 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {16 unimplemented!()17 }18}1920impl Display for MyError {21 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {22 unimplemented!()23 }24}2526impl Error for MyError {27 fn provide<'a>(&'a self, request: &mut Request<'a>) {28 request.provide_ref(&self.0);29 }30}3132const _: 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)]23use std::env;4use std::fs;4use std::path::Path;5use std::process::{Command, ExitStatus, Stdio};6use std::str;7
1 unmodified line
9compile_error! {10 "`backtrace` feature without `std` feature is not supported"11}1214// 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.17const PROBE: &str = r#"18 #![feature(error_generic_member_access)]1920 use std::backtrace::Backtrace;21 use std::error::{self, Error, Request};22 use std::fmt::{self, Debug, Display};2324 struct MyError(Thing);25 struct Thing;2627 impl Debug for MyError {28 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {29 unimplemented!()30 }31 }3233 impl Display for MyError {34 fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {35 unimplemented!()36 }37 }3839 impl Error for MyError {40 fn provide<'a>(&'a self, request: &mut Request<'a>) {41 request.provide_ref(&self.0);42 }43 }4445 const _: fn(&dyn Error) -> Option<&Backtrace> = |err| error::request_ref::<Backtrace>(err);46"#;4713fn 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");1819 match compile_probe() {20 Some(status) if status.success() => {
46 unmodified lines
67 }6869 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");7273 // 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