@@ -7,19 +7,34 @@ use std::path::PathBuf;
77use crate :: config:: ConfigInfo ;
88use crate :: utils:: { get_toolchain, rustc_toolchain_version_info, rustc_version_info} ;
99
10- fn args ( command : & str ) -> Result < Option < Vec < String > > , String > {
10+ fn args (
11+ command : & str ,
12+ expect_dash_dash : bool ,
13+ ) -> Result < Option < ( ConfigInfo , Vec < String > ) > , String > {
1114 // We skip the binary and the "cargo"/"rustc" option.
1215 if let Some ( "--help" ) = std:: env:: args ( ) . nth ( 2 ) . as_deref ( ) {
1316 usage ( command) ;
1417 return Ok ( None ) ;
1518 }
16- let args = std:: env:: args ( ) . skip ( 2 ) . collect :: < Vec < _ > > ( ) ;
19+ let mut config = ConfigInfo :: default ( ) ;
20+ let mut args = std:: env:: args ( ) . skip ( 2 ) ;
21+ if expect_dash_dash {
22+ while let Some ( arg) = args. next ( ) {
23+ if arg == "--" {
24+ break ;
25+ }
26+ if let Ok ( false ) = config. parse_argument ( & arg, & mut args) {
27+ return Err ( format ! ( "Unknown config option {arg:?}" ) ) ;
28+ }
29+ }
30+ }
31+ let args = args. collect :: < Vec < _ > > ( ) ;
1732 if args. is_empty ( ) {
1833 return Err ( format ! (
19- "Expected at least one argument for `{command}` subcommand, found none"
34+ "Expected at least one argument for `{command}` subcommand (after `--`) , found none"
2035 ) ) ;
2136 }
22- Ok ( Some ( args) )
37+ Ok ( Some ( ( config , args) ) )
2338}
2439
2540fn usage ( command : & str ) {
@@ -41,8 +56,8 @@ struct RustcTools {
4156}
4257
4358impl RustcTools {
44- fn new ( command : & str ) -> Result < Option < Self > , String > {
45- let Some ( args) = args ( command) ? else { return Ok ( None ) } ;
59+ fn new ( command : & str , expect_dash_dash : bool ) -> Result < Option < Self > , String > {
60+ let Some ( ( mut config , args) ) = args ( command, expect_dash_dash ) ? else { return Ok ( None ) } ;
4661
4762 // We first need to go to the original location to ensure that the config setup will go as
4863 // expected.
@@ -71,8 +86,7 @@ impl RustcTools {
7186 } ) ?;
7287
7388 let mut env: HashMap < String , String > = std:: env:: vars ( ) . collect ( ) ;
74- let mut config = ConfigInfo :: default ( ) ;
75- config. setup ( & mut env, false ) ?;
89+ config. setup ( & mut env, false , false ) ?;
7690 let toolchain = get_toolchain ( ) ?;
7791
7892 let toolchain_version = rustc_toolchain_version_info ( & toolchain) ?;
@@ -115,7 +129,7 @@ fn exec(input: &[&dyn AsRef<OsStr>], env: &HashMap<String, String>) -> Result<()
115129}
116130
117131pub fn run_cargo ( ) -> Result < ( ) , String > {
118- let Some ( mut tools) = RustcTools :: new ( "cargo" ) ? else { return Ok ( ( ) ) } ;
132+ let Some ( mut tools) = RustcTools :: new ( "cargo" , false ) ? else { return Ok ( ( ) ) } ;
119133 let rustflags = tools. env . get ( "RUSTFLAGS" ) . cloned ( ) . unwrap_or_default ( ) ;
120134 tools. env . insert ( "RUSTDOCFLAGS" . to_string ( ) , rustflags) ;
121135 let mut command: Vec < & dyn AsRef < OsStr > > = vec ! [ & "cargo" , & tools. toolchain] ;
@@ -126,7 +140,7 @@ pub fn run_cargo() -> Result<(), String> {
126140}
127141
128142pub fn run_rustc ( ) -> Result < ( ) , String > {
129- let Some ( tools) = RustcTools :: new ( "rustc" ) ? else { return Ok ( ( ) ) } ;
143+ let Some ( tools) = RustcTools :: new ( "rustc" , true ) ? else { return Ok ( ( ) ) } ;
130144 let mut command = tools. config . rustc_command_vec ( ) ;
131145 for arg in & tools. args {
132146 command. push ( arg) ;
0 commit comments