Skip to content

Commit

Permalink
Detect -Z assume-incomplete-release flag
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 17, 2021
1 parent 445d068 commit d50608e
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
27 changes: 27 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ fn main() {
fs::write(out_file, version)
.unwrap_or_else(|e| panic!("failed to write {}: {}", out_file.display(), e));

if assume_incomplete_release() {
println!("cargo:rustc-cfg=const_fn_assume_incomplete_release");
}

// Mark as build script has been run successfully.
println!("cargo:rustc-cfg=const_fn_has_build_script");
}
Expand Down Expand Up @@ -100,3 +104,26 @@ impl Version {
format!("Version {{ minor: {}, nightly: {} }}\n", self.minor, self.nightly)
}
}

// https://github.com/rust-lang/rust/pull/81468
// https://github.com/taiki-e/const_fn/issues/27
fn assume_incomplete_release() -> bool {
// Recognized formats:
//
// -Z assume-incomplete-release
//
// -Zassume-incomplete-release

if let Some(rustflags) = env::var_os("RUSTFLAGS") {
for mut flag in rustflags.to_string_lossy().split(' ') {
if flag.starts_with("-Z") {
flag = &flag["-Z".len()..];
}
if flag == "assume-incomplete-release" {
return true;
}
}
}

false
}
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,9 @@ fn expand(arg: Arg, mut func: Func) -> TokenStream {
tokens
}
Arg::Version(req) => {
if req.major > 1 || req.minor > VERSION.minor {
if req.major > 1
|| req.minor + (cfg!(const_fn_assume_incomplete_release) as u32) > VERSION.minor
{
func.print_const = false;
}
func.to_token_stream()
Expand Down

0 comments on commit d50608e

Please sign in to comment.