@@ -92,7 +92,7 @@ pub fn complete(
9292 if value. is_some ( ) {
9393 ParseState :: ValueDone
9494 } else {
95- ParseState :: Opt ( opt. unwrap ( ) . clone ( ) )
95+ ParseState :: Opt ( opt. unwrap ( ) )
9696 }
9797 }
9898 Some ( clap:: ArgAction :: SetTrue ) | Some ( clap:: ArgAction :: SetFalse ) => {
@@ -115,7 +115,7 @@ pub fn complete(
115115 Some ( opt) => {
116116 state = match short. next_value_os ( ) {
117117 Some ( _) => ParseState :: ValueDone ,
118- None => ParseState :: Opt ( opt. clone ( ) ) ,
118+ None => ParseState :: Opt ( opt) ,
119119 } ;
120120 }
121121 None => {
@@ -142,23 +142,23 @@ pub fn complete(
142142}
143143
144144#[ derive( Debug , PartialEq , Eq , Clone ) ]
145- enum ParseState {
145+ enum ParseState < ' a > {
146146 /// Parsing a value done, there is no state to record.
147147 ValueDone ,
148148
149149 /// Parsing a positional argument after `--`
150150 Pos ( usize ) ,
151151
152152 /// Parsing a optional flag argument
153- Opt ( clap:: Arg ) ,
153+ Opt ( & ' a clap:: Arg ) ,
154154}
155155
156156fn complete_arg (
157157 arg : & clap_lex:: ParsedArg < ' _ > ,
158158 cmd : & clap:: Command ,
159159 current_dir : Option < & std:: path:: Path > ,
160160 pos_index : usize ,
161- state : ParseState ,
161+ state : ParseState < ' _ > ,
162162) -> Result < Vec < CompletionCandidate > , std:: io:: Error > {
163163 debug ! (
164164 "complete_arg: arg={:?}, cmd={:?}, current_dir={:?}, pos_index={:?}, state={:?}" ,
@@ -202,7 +202,7 @@ fn complete_arg(
202202 completions. extend ( hidden_longs_aliases ( cmd) . into_iter ( ) . filter ( |comp| {
203203 comp. get_content ( )
204204 . starts_with ( format ! ( "--{}" , flag) . as_str ( ) )
205- } ) )
205+ } ) ) ;
206206 }
207207 }
208208 } else if arg. is_escape ( ) || arg. is_stdio ( ) || arg. is_empty ( ) {
@@ -236,7 +236,7 @@ fn complete_arg(
236236 } else if let Some ( short) = arg. to_short ( ) {
237237 if !short. is_negative_number ( ) {
238238 // Find the first takes_value option.
239- let ( leading_flags, takes_value_opt, mut short) = parse_shortflags ( & cmd, short) ;
239+ let ( leading_flags, takes_value_opt, mut short) = parse_shortflags ( cmd, short) ;
240240
241241 // Clone `short` to `peek_short` to peek whether the next flag is a `=`.
242242 if let Some ( opt) = takes_value_opt {
@@ -250,7 +250,7 @@ fn complete_arg(
250250
251251 let value = short. next_value_os ( ) . unwrap_or ( OsStr :: new ( "" ) ) ;
252252 completions. extend (
253- complete_arg_value ( value. to_str ( ) . ok_or ( value) , & opt, current_dir)
253+ complete_arg_value ( value. to_str ( ) . ok_or ( value) , opt, current_dir)
254254 . into_iter ( )
255255 . map ( |comp| {
256256 CompletionCandidate :: new ( format ! (
@@ -299,11 +299,11 @@ fn complete_arg(
299299 }
300300 }
301301 ParseState :: Opt ( opt) => {
302- completions. extend ( complete_arg_value ( arg. to_value ( ) , & opt, current_dir) ) ;
302+ completions. extend ( complete_arg_value ( arg. to_value ( ) , opt, current_dir) ) ;
303303 }
304304 }
305305 if completions. iter ( ) . any ( |a| a. is_visible ( ) ) {
306- completions. retain ( |a| a. is_visible ( ) )
306+ completions. retain ( |a| a. is_visible ( ) ) ;
307307 }
308308
309309 Ok ( completions)
@@ -452,7 +452,7 @@ fn longs_and_visible_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
452452 . filter_map ( |a| {
453453 a. get_long_and_visible_aliases ( ) . map ( |longs| {
454454 longs. into_iter ( ) . map ( |s| {
455- CompletionCandidate :: new ( format ! ( "--{}" , s. to_string ( ) ) )
455+ CompletionCandidate :: new ( format ! ( "--{}" , s) )
456456 . help ( a. get_help ( ) . cloned ( ) )
457457 . visible ( !a. is_hide_set ( ) )
458458 } )
@@ -470,7 +470,7 @@ fn hidden_longs_aliases(p: &clap::Command) -> Vec<CompletionCandidate> {
470470 . filter_map ( |a| {
471471 a. get_aliases ( ) . map ( |longs| {
472472 longs. into_iter ( ) . map ( |s| {
473- CompletionCandidate :: new ( format ! ( "--{}" , s. to_string ( ) ) )
473+ CompletionCandidate :: new ( format ! ( "--{}" , s) )
474474 . help ( a. get_help ( ) . cloned ( ) )
475475 . visible ( false )
476476 } )
@@ -526,7 +526,7 @@ fn subcommands(p: &clap::Command) -> Vec<CompletionCandidate> {
526526 . help ( sc. get_about ( ) . cloned ( ) )
527527 . visible ( !sc. is_hide_set ( ) )
528528 } )
529- . chain ( sc. get_aliases ( ) . into_iter ( ) . map ( |s| {
529+ . chain ( sc. get_aliases ( ) . map ( |s| {
530530 CompletionCandidate :: new ( s. to_string ( ) )
531531 . help ( sc. get_about ( ) . cloned ( ) )
532532 . visible ( false )
@@ -535,11 +535,11 @@ fn subcommands(p: &clap::Command) -> Vec<CompletionCandidate> {
535535 . collect ( )
536536}
537537
538- /// Parse the short flags and find the first takes_value option.
539- fn parse_shortflags < ' s > (
540- cmd : & clap:: Command ,
538+ /// Parse the short flags and find the first ` takes_value` option.
539+ fn parse_shortflags < ' c , ' s > (
540+ cmd : & ' c clap:: Command ,
541541 mut short : clap_lex:: ShortFlags < ' s > ,
542- ) -> ( OsString , Option < clap:: Arg > , clap_lex:: ShortFlags < ' s > ) {
542+ ) -> ( OsString , Option < & ' c clap:: Arg > , clap_lex:: ShortFlags < ' s > ) {
543543 let takes_value_opt;
544544 let mut leading_flags = OsString :: new ( ) ;
545545 // Find the first takes_value option.
@@ -579,7 +579,7 @@ fn parse_shortflags<'s>(
579579 }
580580 }
581581
582- ( leading_flags, takes_value_opt. cloned ( ) , short)
582+ ( leading_flags, takes_value_opt, short)
583583}
584584
585585/// A completion candidate definition
0 commit comments