@@ -496,74 +496,6 @@ impl<'a> Toolchain<'a> {
496
496
} )
497
497
}
498
498
// Distributable only. Installed only.
499
- pub fn list_components ( & self ) -> Result < Option < Vec < ComponentStatus > > > {
500
- if !self . exists ( ) {
501
- return Err ( ErrorKind :: ToolchainNotInstalled ( self . name . to_owned ( ) ) . into ( ) ) ;
502
- }
503
-
504
- let toolchain = & self . name ;
505
- let toolchain = match ToolchainDesc :: from_str ( toolchain) . ok ( ) {
506
- None => return Ok ( None ) ,
507
- Some ( toolchain) => toolchain,
508
- } ;
509
-
510
- let prefix = InstallPrefix :: from ( self . path . to_owned ( ) ) ;
511
- let manifestation = Manifestation :: open ( prefix, toolchain. target . clone ( ) ) ?;
512
-
513
- if let Some ( manifest) = manifestation. load_manifest ( ) ? {
514
- let config = manifestation. read_config ( ) ?;
515
-
516
- // Return all optional components of the "rust" package for the
517
- // toolchain's target triple.
518
- let mut res = Vec :: new ( ) ;
519
-
520
- let rust_pkg = manifest
521
- . packages
522
- . get ( "rust" )
523
- . expect ( "manifest should contain a rust package" ) ;
524
- let targ_pkg = rust_pkg
525
- . targets
526
- . get ( & toolchain. target )
527
- . expect ( "installed manifest should have a known target" ) ;
528
-
529
- for component in & targ_pkg. components {
530
- let installed = config
531
- . as_ref ( )
532
- . map ( |c| component. contained_within ( & c. components ) )
533
- . unwrap_or ( false ) ;
534
-
535
- let component_target = TargetTriple :: new ( & component. target ( ) ) ;
536
-
537
- // Get the component so we can check if it is available
538
- let component_pkg = manifest
539
- . get_package ( & component. short_name_in_manifest ( ) )
540
- . unwrap_or_else ( |_| {
541
- panic ! (
542
- "manifest should contain component {}" ,
543
- & component. short_name( & manifest)
544
- )
545
- } ) ;
546
- let component_target_pkg = component_pkg
547
- . targets
548
- . get ( & component_target)
549
- . expect ( "component should have target toolchain" ) ;
550
-
551
- res. push ( ComponentStatus {
552
- component : component. clone ( ) ,
553
- name : component. name ( & manifest) ,
554
- installed,
555
- available : component_target_pkg. available ( ) ,
556
- } ) ;
557
- }
558
-
559
- res. sort_by ( |a, b| a. component . cmp ( & b. component ) ) ;
560
-
561
- Ok ( Some ( res) )
562
- } else {
563
- Err ( ErrorKind :: ComponentsUnsupported ( self . name . to_string ( ) ) . into ( ) )
564
- }
565
- }
566
- // Distributable only. Installed only.
567
499
fn get_component_suggestion (
568
500
& self ,
569
501
component : & Component ,
@@ -576,8 +508,9 @@ impl<'a> Toolchain<'a> {
576
508
// High number can result in inaccurate suggestions for short queries e.g. `rls`
577
509
const MAX_DISTANCE : usize = 3 ;
578
510
579
- let components = self . list_components ( ) ;
580
- if let Ok ( Some ( components) ) = components {
511
+ let distributable = DistributableToolchain :: new ( & self ) ;
512
+ let components = distributable. ok ( ) . map ( |d| d. list_components ( ) ) ;
513
+ if let Some ( Ok ( components) ) = components {
581
514
let short_name_distance = components
582
515
. iter ( )
583
516
. filter ( |c| !only_installed || c. installed )
@@ -825,6 +758,73 @@ impl<'a> DistributableToolchain<'a> {
825
758
) )
826
759
}
827
760
761
+ // Installed only.
762
+ pub fn list_components ( & self ) -> Result < Vec < ComponentStatus > > {
763
+ if !self . 0 . exists ( ) {
764
+ return Err ( ErrorKind :: ToolchainNotInstalled ( self . 0 . name . to_owned ( ) ) . into ( ) ) ;
765
+ }
766
+
767
+ let toolchain = & self . 0 . name ;
768
+ let toolchain = ToolchainDesc :: from_str ( toolchain)
769
+ . chain_err ( || ErrorKind :: ComponentsUnsupported ( self . 0 . name . to_string ( ) ) ) ?;
770
+
771
+ let prefix = InstallPrefix :: from ( self . 0 . path . to_owned ( ) ) ;
772
+ let manifestation = Manifestation :: open ( prefix, toolchain. target . clone ( ) ) ?;
773
+
774
+ if let Some ( manifest) = manifestation. load_manifest ( ) ? {
775
+ let config = manifestation. read_config ( ) ?;
776
+
777
+ // Return all optional components of the "rust" package for the
778
+ // toolchain's target triple.
779
+ let mut res = Vec :: new ( ) ;
780
+
781
+ let rust_pkg = manifest
782
+ . packages
783
+ . get ( "rust" )
784
+ . expect ( "manifest should contain a rust package" ) ;
785
+ let targ_pkg = rust_pkg
786
+ . targets
787
+ . get ( & toolchain. target )
788
+ . expect ( "installed manifest should have a known target" ) ;
789
+
790
+ for component in & targ_pkg. components {
791
+ let installed = config
792
+ . as_ref ( )
793
+ . map ( |c| component. contained_within ( & c. components ) )
794
+ . unwrap_or ( false ) ;
795
+
796
+ let component_target = TargetTriple :: new ( & component. target ( ) ) ;
797
+
798
+ // Get the component so we can check if it is available
799
+ let component_pkg = manifest
800
+ . get_package ( & component. short_name_in_manifest ( ) )
801
+ . unwrap_or_else ( |_| {
802
+ panic ! (
803
+ "manifest should contain component {}" ,
804
+ & component. short_name( & manifest)
805
+ )
806
+ } ) ;
807
+ let component_target_pkg = component_pkg
808
+ . targets
809
+ . get ( & component_target)
810
+ . expect ( "component should have target toolchain" ) ;
811
+
812
+ res. push ( ComponentStatus {
813
+ component : component. clone ( ) ,
814
+ name : component. name ( & manifest) ,
815
+ installed,
816
+ available : component_target_pkg. available ( ) ,
817
+ } ) ;
818
+ }
819
+
820
+ res. sort_by ( |a, b| a. component . cmp ( & b. component ) ) ;
821
+
822
+ Ok ( res)
823
+ } else {
824
+ Err ( ErrorKind :: ComponentsUnsupported ( self . 0 . name . to_string ( ) ) . into ( ) )
825
+ }
826
+ }
827
+
828
828
// Installed only.
829
829
pub fn remove_component ( & self , mut component : Component ) -> Result < ( ) > {
830
830
// Overlapping code with get_manifest :/.
0 commit comments