Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 24 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@
static REQUIRED_MAJOR: usize = 1;
static REQUIRED_MINOR: usize = 40;

const MACRO_PROBE_PRELUDE: &str = r#"
#[allow(unused_imports)]
use core::prelude::v1::*;
#[cfg(feature = "std")]
#[allow(unused_imports)]
use std::prelude::v1::*;
"#;

fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut ac = autocfg::AutoCfg::new()?;

Expand Down Expand Up @@ -49,7 +57,7 @@

ac.emit_expression_maybe_using_feature(
"matches_macro",
"{ let a = Some(5i32); matches!(a, None) }",
"let a = Some(5i32); matches!(a, None)",
);

ac.emit_expression_maybe_using_feature(
Expand Down Expand Up @@ -194,7 +202,7 @@
pub fn from_rustc(rustc: &Path) -> Result<Self, Error> {
// Get rustc's verbose version
let output = Command::new(rustc)
.args(&["--version", "--verbose"])

Check failure on line 205 in build.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> build.rs:205:27 | 205 | .args(&["--version", "--verbose"]) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: change this to: `["--version", "--verbose"]` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#needless_borrows_for_generic_args = note: `-D clippy::needless-borrows-for-generic-args` implied by `-D warnings` = help: to override `-D warnings` add `#[allow(clippy::needless_borrows_for_generic_args)]`
.output()
.map_err(error::from_io)?;
if !output.status.success() {
Expand Down Expand Up @@ -410,7 +418,9 @@
.arg("--crate-type=lib")
.arg("--out-dir")
.arg(&self.out_dir)
.arg("--emit=llvm-ir");
.arg("--emit=llvm-ir")
// use Rust 2018 so core can be referenced from probes
.arg("--edition=2018");

if let Some(ref rustflags) = self.rustflags {
command.args(rustflags);
Expand Down Expand Up @@ -589,8 +599,12 @@
/// pub fn probe() { let _ = EXPR; }
/// ```
pub fn probe_expression(&self, expr: &str) -> bool {
self.probe(format!("pub fn probe() {{ let _ = {}; }}", expr))
.unwrap_or(false)
self.probe(format!(
"{} pub fn probe() {{ let _ = {}; }}",
super::MACRO_PROBE_PRELUDE,
expr
))
.unwrap_or(false)
}

/// Emits the given `cfg` value if `probe_expression` returns true.
Expand All @@ -613,8 +627,12 @@
/// pub const PROBE: () = ((), EXPR).0;
/// ```
pub fn probe_constant(&self, expr: &str) -> bool {
self.probe(format!("pub const PROBE: () = ((), {}).0;", expr))
.unwrap_or(false)
self.probe(format!(
"{} pub const PROBE: () = ((), {}).0;",
super::MACRO_PROBE_PRELUDE,
expr
))
.unwrap_or(false)
}

/// Emits the given `cfg` value if `probe_constant` returns true.
Expand Down Expand Up @@ -803,7 +821,7 @@

cargo_target_dir
.to_str()
.map(|cargo_target_dir| dir.contains(&cargo_target_dir))

Check failure on line 824 in build.rs

View workflow job for this annotation

GitHub Actions / clippy

the borrowed expression implements the required traits

error: the borrowed expression implements the required traits --> build.rs:824:62 | 824 | .map(|cargo_target_dir| dir.contains(&cargo_target_dir)) | ^^^^^^^^^^^^^^^^^ help: change this to: `cargo_target_dir` | = help: for further information visit https://rust-lang.github.io/rust-clippy/rust-1.91.0/index.html#needless_borrows_for_generic_args
})
})
.unwrap_or(false)
Expand Down
Loading