@@ -10,6 +10,7 @@ use clap::{
10
10
Arg , ArgAction , ArgGroup , ArgMatches , Command , ValueEnum ,
11
11
} ;
12
12
use clap_complete:: Shell ;
13
+ use itertools:: Itertools ;
13
14
14
15
use crate :: {
15
16
cli:: {
@@ -1334,11 +1335,22 @@ fn target_remove(cfg: &Cfg, m: &ArgMatches) -> Result<utils::ExitCode> {
1334
1335
let distributable = DistributableToolchain :: try_from ( & toolchain) ?;
1335
1336
1336
1337
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 ) ;
1342
1354
distributable. remove_component ( new_component) ?;
1343
1355
}
1344
1356
0 commit comments