@@ -703,7 +703,9 @@ See '<bright-cyan,bold>cargo help</> <cyan><<command>></>' for more information
703
703
. into_iter ( )
704
704
. map ( |t| clap_complete:: CompletionCandidate :: new ( t) )
705
705
. collect :: < Vec < _ > > ( ) ;
706
- candidates. extend ( get_alias_candidates ( ) ) ;
706
+ if let Ok ( gctx) = new_gctx_for_completions ( ) {
707
+ candidates. extend ( get_alias_candidates ( & gctx) ) ;
708
+ }
707
709
candidates
708
710
} ) )
709
711
. subcommands ( commands:: builtin ( ) )
@@ -726,33 +728,30 @@ fn get_toolchains_from_rustup() -> Vec<String> {
726
728
stdout. lines ( ) . map ( |line| format ! ( "+{}" , line) ) . collect ( )
727
729
}
728
730
729
- fn get_alias_candidates ( ) -> Vec < clap_complete:: CompletionCandidate > {
730
- if let Ok ( gctx) = new_gctx_for_completions ( ) {
731
- let alias_map = user_defined_aliases ( & gctx) ;
732
- return alias_map
733
- . iter ( )
734
- . map ( |( alias, cmd_info) | {
735
- let help_text = match cmd_info {
736
- CommandInfo :: Alias { target } => {
737
- let cmd_str = target
738
- . iter ( )
739
- . map ( String :: as_str)
740
- . collect :: < Vec < _ > > ( )
741
- . join ( " " ) ;
742
- format ! ( "alias for {}" , cmd_str)
743
- }
744
- CommandInfo :: BuiltIn { .. } => {
745
- unreachable ! ( "BuiltIn command shouldn't appear in alias map" )
746
- }
747
- CommandInfo :: External { .. } => {
748
- unreachable ! ( "External command shouldn't appear in alias map" )
749
- }
750
- } ;
751
- clap_complete:: CompletionCandidate :: new ( alias. clone ( ) ) . help ( Some ( help_text. into ( ) ) )
752
- } )
753
- . collect ( ) ;
754
- }
755
- Vec :: new ( )
731
+ fn get_alias_candidates ( gctx : & GlobalContext ) -> Vec < clap_complete:: CompletionCandidate > {
732
+ let alias_map = user_defined_aliases ( gctx) ;
733
+ alias_map
734
+ . iter ( )
735
+ . map ( |( alias, cmd_info) | {
736
+ let help_text = match cmd_info {
737
+ CommandInfo :: Alias { target } => {
738
+ let cmd_str = target
739
+ . iter ( )
740
+ . map ( String :: as_str)
741
+ . collect :: < Vec < _ > > ( )
742
+ . join ( " " ) ;
743
+ format ! ( "alias for {}" , cmd_str)
744
+ }
745
+ CommandInfo :: BuiltIn { .. } => {
746
+ unreachable ! ( "BuiltIn command shouldn't appear in alias map" )
747
+ }
748
+ CommandInfo :: External { .. } => {
749
+ unreachable ! ( "External command shouldn't appear in alias map" )
750
+ }
751
+ } ;
752
+ clap_complete:: CompletionCandidate :: new ( alias. clone ( ) ) . help ( Some ( help_text. into ( ) ) )
753
+ } )
754
+ . collect ( )
756
755
}
757
756
758
757
#[ test]
0 commit comments