Repository: dtolnay/cargo-expand (language: rust)

Issue:
error: no such subcommand: `+nightly`
The `cargo-expand` executable fails to run (built from master):

```
$ cargo-expand --help
error: no such subcommand: `+nightly`
```

I can work around this by setting `CARGO_EXPAND_NO_RUN_NIGHTLY=true`. It looks like otherwise `cargo-expand` assumes a `rustup`-installed cargo (vanilla cargo doesn't accept `+nightly` I think).


Discussion / hints:

Fix patch:
diff --git a/src/main.rs b/src/main.rs
index eb00ef7..3c1b446 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -45,8 +45,7 @@ fn main() {
 fn cargo_expand_or_run_nightly() -> Result<i32> {
     const NO_RUN_NIGHTLY: &str = "CARGO_EXPAND_NO_RUN_NIGHTLY";
 
-    let maybe_nightly = !definitely_not_nightly();
-    if maybe_nightly || env::var_os(NO_RUN_NIGHTLY).is_some() {
+    if env::var_os(NO_RUN_NIGHTLY).is_some() || maybe_nightly() || !can_run_plus_nightly() {
         return cargo_expand();
     }
 
@@ -78,6 +77,10 @@ fn cargo_expand_or_run_nightly() -> Result<i32> {
     })
 }
 
+fn maybe_nightly() -> bool {
+    !definitely_not_nightly()
+}
+
 fn definitely_not_nightly() -> bool {
     let mut cmd = Command::new(cargo_binary());
     cmd.arg("--version");
@@ -95,6 +98,14 @@ fn definitely_not_nightly() -> bool {
     version.starts_with("cargo 1") && !version.contains("nightly")
 }
 
+fn can_run_plus_nightly() -> bool {
+    Command::new("cargo")
+        .arg("+nightly")
+        .arg("--version")
+        .output()
+        .map_or(false, |output| output.status.success())
+}
+
 fn cargo_binary() -> OsString {
     env::var_os("CARGO").unwrap_or_else(|| "cargo".to_owned().into())
 }


Test patch: