@@ -10,6 +10,7 @@ use clap::{
1010 Arg , ArgAction , ArgGroup , ArgMatches , Command , ValueEnum ,
1111} ;
1212use clap_complete:: Shell ;
13+ use itertools:: Itertools ;
1314
1415use crate :: {
1516 cli:: {
@@ -1334,11 +1335,22 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
13341335 let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
13351336
13361337 for target in m. get_many :: < String > ( "target" ) . unwrap ( ) {
1337- let new_component = Component :: new (
1338- "rust-std" . to_string ( ) ,
1339- Some ( TargetTriple :: new ( target) ) ,
1340- false ,
1341- ) ;
1338+ let target = TargetTriple :: new ( target) ;
1339+ let default_target = cfg. get_default_host_triple ( ) . ok ( ) ;
1340+ if default_target. as_ref ( ) == Some ( & target) {
1341+ warn ! ( "after removing this default host target, proc-macros and build scripts might no longer build" ) ;
1342+ }
1343+ let at_most_one_target = distributable. components ( ) . ok ( ) . and_then ( |cs| {
1344+ // Every component target that is not `None` (wildcard).
1345+ let targets = cs
1346+ . iter ( )
1347+ . filter_map ( |c| c. installed . then ( || c. component . target . clone ( ) ) . flatten ( ) ) ;
1348+ targets. unique ( ) . at_most_one ( ) . ok ( )
1349+ } ) ;
1350+ if at_most_one_target. is_some ( ) {
1351+ warn ! ( "after removing the last target, no build targets will be available" ) ;
1352+ }
1353+ let new_component = Component :: new ( "rust-std" . to_string ( ) , Some ( target) , false ) ;
13421354 distributable. remove_component ( new_component) ?;
13431355 }
13441356
0 commit comments