Skip to content

Commit 15646f4

Browse files
authored
Merge pull request #334 from dtolnay/probe
Move probe.rs out of build script string literal into file
2 parents 199c625 + b332769 commit 15646f4

File tree

2 files changed

+35
-38
lines changed

2 files changed

+35
-38
lines changed

build.rs

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
1-
#![allow(clippy::needless_raw_string_hashes, clippy::option_if_let_else)]
1+
#![allow(clippy::option_if_let_else)]
22

33
use std::env;
4-
use std::fs;
54
use std::path::Path;
65
use std::process::{Command, ExitStatus, Stdio};
76
use std::str;
@@ -11,43 +10,10 @@ compile_error! {
1110
"`backtrace` feature without `std` feature is not supported"
1211
}
1312

14-
// This code exercises the surface area that we expect of the Error generic
15-
// member access API. If the current toolchain is able to compile it, then
16-
// 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-
4813
fn main() {
4914
let mut error_generic_member_access = false;
5015
if cfg!(feature = "std") {
16+
println!("cargo:rerun-if-changed=build/probe.rs");
5117
println!("cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP");
5218

5319
match compile_probe() {
@@ -102,8 +68,7 @@ fn compile_probe() -> Option<ExitStatus> {
10268

10369
let rustc = env::var_os("RUSTC")?;
10470
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");
10772

10873
// Make sure to pick up Cargo rustc configuration.
10974
let mut cmd = if let Some(wrapper) = env::var_os("RUSTC_WRAPPER") {

build/probe.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// This code exercises the surface area that we expect of the Error generic
2+
// member access API. If the current toolchain is able to compile it, then
3+
// 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);

0 commit comments

Comments
 (0)