Skip to content

Commit cbbe3ef

Browse files
authored
Merge pull request #109 from 3scale-rs/fix-implicit-macro-exports-in-new-compilers
build.rs: use explicit prelude imports in probes
2 parents 87d3011 + 9015f50 commit cbbe3ef

File tree

1 file changed

+24
-6
lines changed

1 file changed

+24
-6
lines changed

build.rs

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
static REQUIRED_MAJOR: usize = 1;
66
static REQUIRED_MINOR: usize = 40;
77

8+
const MACRO_PROBE_PRELUDE: &str = r#"
9+
#[allow(unused_imports)]
10+
use core::prelude::v1::*;
11+
#[cfg(feature = "std")]
12+
#[allow(unused_imports)]
13+
use std::prelude::v1::*;
14+
"#;
15+
816
fn main() -> Result<(), Box<dyn std::error::Error>> {
917
let mut ac = autocfg::AutoCfg::new()?;
1018

@@ -49,7 +57,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
4957

5058
ac.emit_expression_maybe_using_feature(
5159
"matches_macro",
52-
"{ let a = Some(5i32); matches!(a, None) }",
60+
"let a = Some(5i32); matches!(a, None)",
5361
);
5462

5563
ac.emit_expression_maybe_using_feature(
@@ -410,7 +418,9 @@ mod autocfg {
410418
.arg("--crate-type=lib")
411419
.arg("--out-dir")
412420
.arg(&self.out_dir)
413-
.arg("--emit=llvm-ir");
421+
.arg("--emit=llvm-ir")
422+
// use Rust 2018 so core can be referenced from probes
423+
.arg("--edition=2018");
414424

415425
if let Some(ref rustflags) = self.rustflags {
416426
command.args(rustflags);
@@ -589,8 +599,12 @@ mod autocfg {
589599
/// pub fn probe() { let _ = EXPR; }
590600
/// ```
591601
pub fn probe_expression(&self, expr: &str) -> bool {
592-
self.probe(format!("pub fn probe() {{ let _ = {}; }}", expr))
593-
.unwrap_or(false)
602+
self.probe(format!(
603+
"{} pub fn probe() {{ let _ = {}; }}",
604+
super::MACRO_PROBE_PRELUDE,
605+
expr
606+
))
607+
.unwrap_or(false)
594608
}
595609

596610
/// Emits the given `cfg` value if `probe_expression` returns true.
@@ -613,8 +627,12 @@ mod autocfg {
613627
/// pub const PROBE: () = ((), EXPR).0;
614628
/// ```
615629
pub fn probe_constant(&self, expr: &str) -> bool {
616-
self.probe(format!("pub const PROBE: () = ((), {}).0;", expr))
617-
.unwrap_or(false)
630+
self.probe(format!(
631+
"{} pub const PROBE: () = ((), {}).0;",
632+
super::MACRO_PROBE_PRELUDE,
633+
expr
634+
))
635+
.unwrap_or(false)
618636
}
619637

620638
/// Emits the given `cfg` value if `probe_constant` returns true.

0 commit comments

Comments
 (0)