@@ -13,12 +13,49 @@ fn main() {
13
13
let mut error_generic_member_access = false ;
14
14
if cfg ! ( feature = "std" ) {
15
15
println ! ( "cargo:rerun-if-changed=build/probe.rs" ) ;
16
- println ! ( "cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP" ) ;
17
16
18
- if compile_probe ( ) {
17
+ let consider_rustc_bootstrap;
18
+ if compile_probe ( false ) {
19
+ // This is a nightly or dev compiler, so it supports unstable
20
+ // features regardless of RUSTC_BOOTSTRAP. No need to rerun build
21
+ // script if RUSTC_BOOTSTRAP is changed.
22
+ error_generic_member_access = true ;
23
+ consider_rustc_bootstrap = false ;
24
+ } else if let Some ( rustc_bootstrap) = env:: var_os ( "RUSTC_BOOTSTRAP" ) {
25
+ if compile_probe ( true ) {
26
+ // This is a stable or beta compiler for which the user has set
27
+ // RUSTC_BOOTSTRAP to turn on unstable features. Rerun build
28
+ // script if they change it.
29
+ error_generic_member_access = true ;
30
+ consider_rustc_bootstrap = true ;
31
+ } else if rustc_bootstrap == "1" {
32
+ // This compiler does not support the generic member access API
33
+ // in the form that anyhow expects. No need to pay attention to
34
+ // RUSTC_BOOTSTRAP.
35
+ error_generic_member_access = false ;
36
+ consider_rustc_bootstrap = false ;
37
+ } else {
38
+ // This is a stable or beta compiler for which RUSTC_BOOTSTRAP
39
+ // is set to restrict the use of unstable features by this
40
+ // crate.
41
+ error_generic_member_access = false ;
42
+ consider_rustc_bootstrap = true ;
43
+ }
44
+ } else {
45
+ // Without RUSTC_BOOTSTRAP, this compiler does not support the
46
+ // generic member access API in the form that anyhow expects, but
47
+ // try again if the user turns on unstable features.
48
+ error_generic_member_access = false ;
49
+ consider_rustc_bootstrap = true ;
50
+ }
51
+
52
+ if error_generic_member_access {
19
53
println ! ( "cargo:rustc-cfg=std_backtrace" ) ;
20
54
println ! ( "cargo:rustc-cfg=error_generic_member_access" ) ;
21
- error_generic_member_access = true ;
55
+ }
56
+
57
+ if consider_rustc_bootstrap {
58
+ println ! ( "cargo:rerun-if-env-changed=RUSTC_BOOTSTRAP" ) ;
22
59
}
23
60
}
24
61
@@ -50,7 +87,7 @@ fn main() {
50
87
}
51
88
}
52
89
53
- fn compile_probe ( ) -> bool {
90
+ fn compile_probe ( rustc_bootstrap : bool ) -> bool {
54
91
if env:: var_os ( "RUSTC_STAGE" ) . is_some ( ) {
55
92
// We are running inside rustc bootstrap. This is a highly non-standard
56
93
// environment with issues such as:
@@ -76,6 +113,10 @@ fn compile_probe() -> bool {
76
113
Command :: new ( rustc)
77
114
} ;
78
115
116
+ if !rustc_bootstrap {
117
+ cmd. env_remove ( "RUSTC_BOOTSTRAP" ) ;
118
+ }
119
+
79
120
cmd. stderr ( Stdio :: null ( ) )
80
121
. arg ( "--edition=2018" )
81
122
. arg ( "--crate-name=anyhow" )
0 commit comments