@@ -601,7 +601,6 @@ impl FetchMetadata {
601601 }
602602 command. current_dir ( current_dir) ;
603603
604- let mut needs_nightly = false ;
605604 let mut other_options = vec ! [ ] ;
606605 // cargo metadata only supports a subset of flags of what cargo usually accepts, and usually
607606 // the only relevant flags for metadata here are unstable ones, so we pass those along
@@ -611,15 +610,13 @@ impl FetchMetadata {
611610 if arg == "-Z"
612611 && let Some ( arg) = extra_args. next ( )
613612 {
614- needs_nightly = true ;
615613 other_options. push ( "-Z" . to_owned ( ) ) ;
616614 other_options. push ( arg. to_owned ( ) ) ;
617615 }
618616 }
619617
620618 let mut lockfile_path = None ;
621619 if cargo_toml. is_rust_manifest ( ) {
622- needs_nightly = true ;
623620 other_options. push ( "-Zscript" . to_owned ( ) ) ;
624621 } else if config
625622 . toolchain_version
@@ -637,10 +634,6 @@ impl FetchMetadata {
637634
638635 command. other_options ( other_options. clone ( ) ) ;
639636
640- if needs_nightly {
641- command. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "nightly" ) ;
642- }
643-
644637 // Pre-fetch basic metadata using `--no-deps`, which:
645638 // - avoids fetching registries like crates.io,
646639 // - skips dependency resolution and does not modify lockfiles,
@@ -710,7 +703,7 @@ impl FetchMetadata {
710703 other_options. push ( target_lockfile. to_string ( ) ) ;
711704 using_lockfile_copy = true ;
712705 }
713- if using_lockfile_copy {
706+ if using_lockfile_copy || other_options . iter ( ) . any ( |it| it . starts_with ( "-Z" ) ) {
714707 command. env ( "__CARGO_TEST_CHANNEL_OVERRIDE_DO_NOT_USE_THIS" , "nightly" ) ;
715708 other_options. push ( "-Zunstable-options" . to_owned ( ) ) ;
716709 }
0 commit comments