diff --git a/src/bin/cargo/main.rs b/src/bin/cargo/main.rs index b8e286e91676..45874d38a35c 100644 --- a/src/bin/cargo/main.rs +++ b/src/bin/cargo/main.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] // while we're getting used to 2018 #![allow(clippy::all)] -use cargo::util::config::{ConfigError, ConfigErrorKind, Value}; +use cargo::util::config::{ConfigError, ConfigErrorKind}; use cargo::util::toml::StringOrVec; use cargo::util::CliError; use cargo::util::{self, closest_msg, command_prelude, CargoResult, CliResult, Config}; @@ -63,22 +63,26 @@ fn builtin_aliases_execs(cmd: &str) -> Option<&(&str, &str, &str)> { /// 4. If still no command is found, return `None`. fn aliased_command(config: &Config, command: &str) -> CargoResult>> { let alias_name = format!("alias.{command}"); - let user_alias = match config.get::>(&alias_name) { - Ok(record) => Some( + let user_alias = match config.get_string(&alias_name) { + Ok(Some(record)) => Some( record .val .split_whitespace() .map(|s| s.to_string()) .collect(), ), - Err(e) => match e.downcast_ref::().map(|e| e.kind()) { - // Just report we cannot find anything. - Some(ConfigErrorKind::MissingKey) => None, - // Alias might be set as an toml array, fallback and try it. - Some(ConfigErrorKind::UnexpectedValue) => config.get::>(&alias_name)?, - // A unrecoverable error, e.g. TOML parsing error. Relay it to the user. - Some(ConfigErrorKind::Custom) | None => return Err(e), - }, + // Just report we cannot find anything. + Ok(None) => None, + // Alias might be set as an toml array, fallback and try it. + Err(e) + if e.downcast_ref::() + .map(|e| matches!(e.kind(), ConfigErrorKind::UnexpectedValue)) + .unwrap_or_default() => + { + config.get::>(&alias_name)? + } + // A unrecoverable error, e.g. TOML parsing error. Relay it to the user. + Err(e) => return Err(e), }; let result = user_alias.or_else(|| {