diff --git a/src/bin/cargo/commands/remove.rs b/src/bin/cargo/commands/remove.rs index d491ee400512..665b139b2a39 100644 --- a/src/bin/cargo/commands/remove.rs +++ b/src/bin/cargo/commands/remove.rs @@ -96,13 +96,14 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { .cloned() .collect::>(); - let section = parse_section(args); + let (section, fallback_search_sections) = parse_section(args); let options = RemoveOptions { config, spec, dependencies, section, + fallback_search_sections, dry_run, }; remove(&options)?; @@ -134,26 +135,38 @@ pub fn exec(config: &mut Config, args: &ArgMatches) -> CliResult { Ok(()) } -fn parse_section(args: &ArgMatches) -> DepTable { +fn parse_section(args: &ArgMatches) -> (DepTable, Vec) { let dev = args.flag("dev"); let build = args.flag("build"); + let mut search_kinds = Vec::new(); + let kind = if dev { + search_kinds.extend_from_slice(&[DepKind::Build, DepKind::Normal]); DepKind::Development } else if build { + search_kinds.extend_from_slice(&[DepKind::Development, DepKind::Normal]); DepKind::Build } else { + search_kinds.extend_from_slice(&[DepKind::Build, DepKind::Development]); DepKind::Normal }; let mut table = DepTable::new().set_kind(kind); - + let mut search_tables = search_kinds + .iter() + .map(|k| DepTable::new().set_kind(*k)) + .collect::>(); if let Some(target) = args.get_one::("target") { assert!(!target.is_empty(), "Target specification may not be empty"); table = table.set_target(target); + search_tables = search_tables + .into_iter() + .map(|t| t.set_target(target.clone())) + .collect::>(); } - table + (table, search_tables) } /// Clean up the workspace.dependencies, profile, patch, and replace sections of the root manifest diff --git a/src/cargo/ops/cargo_remove.rs b/src/cargo/ops/cargo_remove.rs index 4866caeddace..51df8c2ab58f 100644 --- a/src/cargo/ops/cargo_remove.rs +++ b/src/cargo/ops/cargo_remove.rs @@ -17,6 +17,8 @@ pub struct RemoveOptions<'a> { pub dependencies: Vec, /// Which dependency section to remove these from pub section: DepTable, + /// Try to search for the dependency in these sections if it is not found in the specified section + pub fallback_search_sections: Vec, /// Whether or not to actually write the manifest pub dry_run: bool, }