diff --git a/build.rs b/build.rs
index 420e15965121b160a6290c8c199281666e2db541..f447c0ef9cd44d542449b7387aae7466f966f11b 100644
--- a/build.rs
+++ b/build.rs
@@ -103,9 +103,16 @@ fn rustc_minor_nightly() -> Option<(u32, bool)> {
     }
 
     let minor = pieces.next();
-    let nightly_raw = otry!(otry!(pieces.next()).split('-').nth(1));
-    let nightly =
-        nightly_raw.starts_with("dev") || nightly_raw.starts_with("nightly");
+
+    // If `rustc` was built from a tarball, its version string
+    // will have neither a git hash nor a commit date
+    // (e.g. "rustc 1.39.0"). Treat this case as non-nightly,
+    // since a nightly build should either come from CI
+    // or a git checkout
+    let nightly_raw = otry!(pieces.next()).split('-').nth(1);
+    let nightly = nightly_raw
+        .map(|raw| raw.starts_with("dev") || raw.starts_with("nightly"))
+        .unwrap_or(false);
     let minor = otry!(otry!(minor).parse().ok());
 
     Some((minor, nightly))