@@ -231,26 +231,25 @@ fn expand_aliases(
231
231
) -> Result < ( ArgMatches , GlobalArgs ) , CliError > {
232
232
if let Some ( ( cmd, args) ) = args. subcommand ( ) {
233
233
let exec = commands:: builtin_exec ( cmd) ;
234
- let aliased_cmd = super :: aliased_command ( config, cmd) . or_else ( |e| {
235
- // HACK: `cargo version` must always work even with malformed configs.
236
- // Here we treat the error as the aliased command not found,
237
- // so it falls back to call builtin `cargo version`
238
- if cmd == "version" {
239
- Ok ( None )
240
- } else {
241
- Err ( e)
242
- }
243
- } ) ?;
234
+ let aliased_cmd = super :: aliased_command ( config, cmd) ;
244
235
245
236
match ( exec, aliased_cmd) {
246
- ( Some ( _) , Some ( _) ) => {
237
+ ( _, Err ( e) ) => {
238
+ // HACK: `cargo version` must always work even with malformed configs.
239
+ // so when cmd is exactly `version`, it ignores the error
240
+ // and falls back to call builtin `cargo version` then.
241
+ if cmd != "version" {
242
+ return Err ( e. into ( ) ) ;
243
+ }
244
+ }
245
+ ( Some ( _) , Ok ( Some ( _) ) ) => {
247
246
// User alias conflicts with a built-in subcommand
248
247
config. shell ( ) . warn ( format ! (
249
248
"user-defined alias `{}` is ignored, because it is shadowed by a built-in command" ,
250
249
cmd,
251
250
) ) ?;
252
251
}
253
- ( Some ( _) , None ) => {
252
+ ( Some ( _) , Ok ( None ) ) => {
254
253
// Command is built-in and is not conflicting with alias, but contains ignored values.
255
254
if let Some ( mut values) = args. get_many :: < String > ( "" ) {
256
255
return Err ( anyhow:: format_err!(
@@ -264,8 +263,8 @@ To pass the arguments to the subcommand, remove `--`",
264
263
. into ( ) ) ;
265
264
}
266
265
}
267
- ( None , None ) => { }
268
- ( _ , Some ( mut alias) ) => {
266
+ ( None , Ok ( None ) ) => { }
267
+ ( None , Ok ( Some ( mut alias) ) ) => {
269
268
// Check if this alias is shadowing an external subcommand
270
269
// (binary of the form `cargo-<subcommand>`)
271
270
// Currently this is only a warning, but after a transition period this will become
0 commit comments