@@ -367,17 +367,33 @@ impl LocalManifest {
367
367
pub fn remove_from_table ( & mut self , table_path : & [ String ] , name : & str ) -> CargoResult < ( ) > {
368
368
let parent_table = self . get_table_mut ( table_path) ?;
369
369
370
- let dep = parent_table
371
- . get_mut ( name)
372
- . filter ( |t| !t. is_none ( ) )
373
- . ok_or_else ( || non_existent_dependency_err ( name, table_path. join ( "." ) ) ) ?;
374
-
375
- // remove the dependency
376
- * dep = toml_edit:: Item :: None ;
370
+ match parent_table. get_mut ( name) . filter ( |t| !t. is_none ( ) ) {
371
+ Some ( dep) => {
372
+ // remove the dependency
373
+ * dep = toml_edit:: Item :: None ;
374
+
375
+ // remove table if empty
376
+ if parent_table. as_table_like ( ) . unwrap ( ) . is_empty ( ) {
377
+ * parent_table = toml_edit:: Item :: None ;
378
+ }
379
+ }
380
+ None => {
381
+ // Search in other tables.
382
+ let sections = self . get_sections ( ) ;
383
+ let found_table_path = sections. iter ( ) . find_map ( |( t, _) | {
384
+ let table_path: Vec < String > =
385
+ t. to_table ( ) . iter ( ) . map ( |s| s. to_string ( ) ) . collect ( ) ;
386
+ self . get_table ( & table_path)
387
+ . ok ( )
388
+ . and_then ( |t| t. get ( name) . is_some ( ) . then ( || table_path. join ( "." ) ) )
389
+ } ) ;
377
390
378
- // remove table if empty
379
- if parent_table. as_table_like ( ) . unwrap ( ) . is_empty ( ) {
380
- * parent_table = toml_edit:: Item :: None ;
391
+ return Err ( non_existent_dependency_err (
392
+ name,
393
+ table_path. join ( "." ) ,
394
+ found_table_path,
395
+ ) ) ;
396
+ }
381
397
}
382
398
383
399
Ok ( ( ) )
@@ -537,9 +553,14 @@ fn non_existent_table_err(table: impl std::fmt::Display) -> anyhow::Error {
537
553
538
554
fn non_existent_dependency_err (
539
555
name : impl std:: fmt:: Display ,
540
- table : impl std:: fmt:: Display ,
556
+ search_table : impl std:: fmt:: Display ,
557
+ found_table : Option < impl std:: fmt:: Display > ,
541
558
) -> anyhow:: Error {
542
- anyhow:: format_err!( "the dependency `{name}` could not be found in `{table}`." )
559
+ let mut msg = format ! ( "the dependency `{name}` could not be found in `{search_table}`." ) ;
560
+ if let Some ( found_table) = found_table {
561
+ msg. push_str ( & format ! ( " But it was found in `{found_table}`." , ) ) ;
562
+ }
563
+ anyhow:: format_err!( msg)
543
564
}
544
565
545
566
fn remove_array_index ( array : & mut toml_edit:: Array , index : usize ) {
0 commit comments