Skip to content

Commit

Permalink
Merge pull request #272 from dtolnay/probe
Browse files Browse the repository at this point in the history
Move probe.rs out of build script string literal into file
  • Loading branch information
dtolnay authored Dec 30, 2023
2 parents be83323 + 72bee68 commit facaaf6
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 35 deletions.
36 changes: 1 addition & 35 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,41 +1,8 @@
#![allow(clippy::needless_raw_string_hashes)]

use std::env;
use std::fs;
use std::path::Path;
use std::process::{Command, ExitStatus, Stdio};
use std::str;

// This code exercises the surface area that we expect of the Error generic
// member access API. If the current toolchain is able to compile it, then
// thiserror is able to provide backtrace support.
const PROBE: &str = r#"
#![feature(error_generic_member_access)]
use std::error::{Error, Request};
use std::fmt::{self, Debug, Display};
struct MyError(Thing);
struct Thing;
impl Debug for MyError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
impl Display for MyError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}
impl Error for MyError {
fn provide<'a>(&'a self, request: &mut Request<'a>) {
request.provide_ref(&self.0);
}
}
"#;

fn main() {
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
Expand All @@ -60,8 +27,7 @@ fn compile_probe() -> Option<ExitStatus> {

let rustc = env::var_os("RUSTC")?;
let out_dir = env::var_os("OUT_DIR")?;
let probefile = Path::new(&out_dir).join("probe.rs");
fs::write(&probefile, PROBE).ok()?;
let probefile = Path::new("build").join("probe.rs");

// Make sure to pick up Cargo rustc configuration.
let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER") {
Expand Down
29 changes: 29 additions & 0 deletions build/probe.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// This code exercises the surface area that we expect of the Error generic
// member access API. If the current toolchain is able to compile it, then
// thiserror is able to provide backtrace support.

#![feature(error_generic_member_access)]

use std::error::{Error, Request};
use std::fmt::{self, Debug, Display};

struct MyError(Thing);
struct Thing;

impl Debug for MyError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}

impl Display for MyError {
fn fmt(&self, _formatter: &mut fmt::Formatter) -> fmt::Result {
unimplemented!()
}
}

impl Error for MyError {
fn provide<'a>(&'a self, request: &mut Request<'a>) {
request.provide_ref(&self.0);
}
}

0 comments on commit facaaf6

Please sign in to comment.