1+ use std:: borrow:: ToOwned ;
12use std:: io:: { self , BufReader , Write } ;
23use std:: path:: Path ;
34use std:: process:: { Command , Stdio } ;
@@ -74,7 +75,7 @@ impl Context {
7475
7576 /// Get a context structure from a provided target flag, used when cargo
7677 /// was not used to build the binary.
77- fn from_flag ( metadata : Metadata , target_flag : Option < & str > ) -> Result < Self > {
78+ fn from_flag ( metadata : & Metadata , target_flag : Option < & str > ) -> Result < Self > {
7879 let host_target_name = rustc_version:: version_meta ( ) ?. host ;
7980
8081 // Get the "default" target override in .cargo/config.
@@ -100,7 +101,7 @@ impl Context {
100101 fn from_target_name ( target_name : & str ) -> Result < Self > {
101102 let cfg = Cfg :: of ( target_name) ?;
102103
103- Ok ( Context {
104+ Ok ( Self {
104105 cfg,
105106 target : target_name. to_string ( ) ,
106107 } )
@@ -279,13 +280,13 @@ To see all the flags the proxied tool accepts run `cargo-{} -- --help`.{}",
279280 }
280281}
281282
282- fn get_metadata ( tool : & Tool , matches : & ArgMatches ) -> Result < Metadata > {
283+ fn get_metadata ( tool : Tool , matches : & ArgMatches ) -> Result < Metadata > {
283284 let mut metadata_command = MetadataCommand :: new ( ) ;
284285 metadata_command. no_deps ( ) ;
285286 if tool. needs_build ( ) {
286287 if let Some ( features) = matches. get_many :: < String > ( "features" ) {
287288 metadata_command. features ( CargoOpt :: SomeFeatures (
288- features. map ( |s| s . to_owned ( ) ) . collect ( ) ,
289+ features. map ( ToOwned :: to_owned) . collect ( ) ,
289290 ) ) ;
290291 }
291292 if matches. get_flag ( "no-default-features" ) {
@@ -306,17 +307,17 @@ fn get_metadata(tool: &Tool, matches: &ArgMatches) -> Result<Metadata> {
306307 Ok ( metadata)
307308}
308309
309- pub fn run ( tool : Tool , matches : ArgMatches ) -> Result < i32 > {
310+ pub fn run ( tool : Tool , matches : & ArgMatches ) -> Result < i32 > {
310311 let mut tool_args = vec ! [ ] ;
311312 if let Some ( args) = matches. get_many :: < String > ( "args" ) {
312- tool_args. extend ( args. map ( |s| s . as_str ( ) ) ) ;
313+ tool_args. extend ( args. map ( String :: as_str) ) ;
313314 }
314315
315316 let tool_help = tool_args. first ( ) == Some ( & "--help" ) ;
316317
317318 let target_artifact = if tool. needs_build ( ) && !tool_help {
318- let metadata = get_metadata ( & tool, & matches) ?;
319- cargo_build ( & matches, & metadata) ?. map ( |a| ( a, metadata) )
319+ let metadata = get_metadata ( tool, matches) ?;
320+ cargo_build ( matches, & metadata) ?. map ( |a| ( a, metadata) )
320321 } else {
321322 None
322323 } ;
@@ -328,8 +329,8 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result<i32> {
328329 Context :: from_artifact ( metadata, artifact) ?
329330 } else {
330331 Context :: from_flag (
331- get_metadata ( & tool, & matches) ?,
332- matches. get_one :: < String > ( "target" ) . map ( |s| s . as_str ( ) ) ,
332+ & get_metadata ( tool, matches) ?,
333+ matches. get_one :: < String > ( "target" ) . map ( String :: as_str) ,
333334 ) ?
334335 } ;
335336
@@ -345,7 +346,7 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result<i32> {
345346 }
346347
347348 // Extra flags
348- if let Tool :: Readobj = tool {
349+ if tool == Tool :: Readobj {
349350 // The default output style of `readobj` is JSON-like, which is not user friendly, so we
350351 // change it to the human readable GNU style
351352 lltool. arg ( "--elf-output-style=GNU" ) ;
@@ -354,23 +355,23 @@ pub fn run(tool: Tool, matches: ArgMatches) -> Result<i32> {
354355 if tool. needs_build ( ) {
355356 // Artifact
356357 if let Some ( ( artifact, _) ) = & target_artifact {
357- let file = match & artifact . executable {
358- // Example and bins have an executable
359- Some ( val ) => val ,
360- // Libs have an rlib and an rmeta. We want the rlib, which always
361- // comes first in the filenames array after some quick testing.
362- //
363- // We could instead look for files ending in .rlib, but that would
364- // fail for cdylib and other fancy crate kinds.
365- None => & artifact . filenames [ 0 ] ,
366- } ;
358+ // Example and bins have an executable while libs have an rlib and an rmeta. We
359+ // want the rlib, which always comes first in the filenames array after some quick
360+ // testing.
361+ //
362+ // We could instead look for files ending in .rlib, but that would
363+ // fail for cdylib and other fancy crate kinds.
364+ let file = artifact
365+ . executable
366+ . as_ref ( )
367+ . map_or_else ( || & artifact . filenames [ 0 ] , |val| val ) ;
367368
368369 match tool {
369370 // Tools that don't need a build
370371 Tool :: Ar | Tool :: As | Tool :: Cov | Tool :: Lld | Tool :: Profdata => { }
371372 // for some tools we change the CWD (current working directory) and
372373 // make the artifact path relative. This makes the path that the
373- // tool will print easier to read. e.g . `libfoo.rlib` instead of
374+ // tool will print easier to read. eg . `libfoo.rlib` instead of
374375 // `/home/user/rust/project/target/$T/debug/libfoo.rlib`.
375376 Tool :: Objdump | Tool :: Nm | Tool :: Readobj | Tool :: Size => {
376377 lltool
@@ -551,7 +552,7 @@ fn cargo_build_args<'a>(matches: &'a ArgMatches, cargo: &mut Command) -> (BuildT
551552 cargo. args ( [ "--target" , target] ) ;
552553 }
553554
554- let verbose = matches. get_count ( "verbose" ) as u64 ;
555+ let verbose = u64 :: from ( matches. get_count ( "verbose" ) ) ;
555556 if verbose > 1 {
556557 cargo. arg ( format ! ( "-{}" , "v" . repeat( ( verbose - 1 ) as usize ) ) ) ;
557558 }
0 commit comments