From 5b3a0dff9c638b66c23dac7615d9b31ec3df0df5 Mon Sep 17 00:00:00 2001 From: Pavan Kumar Sunkara Date: Fri, 7 Feb 2020 07:17:42 +0100 Subject: [PATCH] Remove extern & macro_use where possible --- benches/01_default.rs | 4 ---- benches/02_simple.rs | 4 ---- benches/03_complex.rs | 2 -- benches/04_new_help.rs | 9 ++------- benches/05_ripgrep.rs | 4 ---- benches/06_rustup.rs | 4 ---- clap_derive/README.md | 5 +---- clap_derive/src/derives/clap.rs | 1 + clap_derive/src/derives/from_argmatches.rs | 5 ++--- clap_derive/src/derives/into_app.rs | 1 + clap_derive/src/lib.rs | 7 +------ clap_derive/tests/deny-warnings.rs | 2 -- clap_derive/tests/utils.rs | 3 --- examples/01a_quick_example.rs | 2 -- examples/01b_quick_example.rs | 2 -- examples/02_apps.rs | 2 -- examples/03_args.rs | 2 -- examples/04_using_matches.rs | 2 -- examples/05_flag_args.rs | 2 -- examples/06_positional_args.rs | 2 -- examples/07_option_args.rs | 2 -- examples/08_subcommands.rs | 2 -- examples/10_default_values.rs | 2 -- examples/11_only_specific_values.rs | 2 -- examples/14_groups.rs | 2 -- examples/15_custom_validator.rs | 2 -- examples/16_app_settings.rs | 2 -- examples/20_subcommands.rs | 2 -- examples/21_aliases.rs | 2 -- examples/22_stop_parsing_with_--.rs | 2 -- src/lib.rs | 1 - 31 files changed, 8 insertions(+), 78 deletions(-) diff --git a/benches/01_default.rs b/benches/01_default.rs index 24e619e6..0d0d4cd1 100644 --- a/benches/01_default.rs +++ b/benches/01_default.rs @@ -1,10 +1,6 @@ #![feature(test)] -extern crate clap; -extern crate test; - use clap::App; - use test::Bencher; #[bench] diff --git a/benches/02_simple.rs b/benches/02_simple.rs index 8722047e..f41efad4 100644 --- a/benches/02_simple.rs +++ b/benches/02_simple.rs @@ -1,10 +1,6 @@ #![feature(test)] -extern crate clap; -extern crate test; - use clap::{App, Arg}; - use test::Bencher; macro_rules! create_app { diff --git a/benches/03_complex.rs b/benches/03_complex.rs index 84bbd7be..b69a0988 100644 --- a/benches/03_complex.rs +++ b/benches/03_complex.rs @@ -1,7 +1,5 @@ #![feature(test)] -extern crate test; - use clap::{clap_app, App, AppSettings, Arg, ArgSettings}; use test::Bencher; diff --git a/benches/04_new_help.rs b/benches/04_new_help.rs index 1680df5a..5810de6c 100644 --- a/benches/04_new_help.rs +++ b/benches/04_new_help.rs @@ -1,14 +1,9 @@ #![feature(test)] -extern crate clap; -extern crate test; - -use test::Bencher; - -use std::io::Cursor; - use clap::App; use clap::{Arg, ArgSettings}; +use std::io::Cursor; +use test::Bencher; fn build_help(app: &mut App) -> String { let mut buf = Cursor::new(Vec::with_capacity(50)); diff --git a/benches/05_ripgrep.rs b/benches/05_ripgrep.rs index 695da070..1e8d571f 100644 --- a/benches/05_ripgrep.rs +++ b/benches/05_ripgrep.rs @@ -5,11 +5,7 @@ #![feature(test)] -extern crate clap; -extern crate test; - use clap::{App, AppSettings, Arg, ArgSettings}; - use std::collections::HashMap; use std::io::Cursor; use test::Bencher; diff --git a/benches/06_rustup.rs b/benches/06_rustup.rs index 05754569..f526af89 100644 --- a/benches/06_rustup.rs +++ b/benches/06_rustup.rs @@ -4,11 +4,7 @@ #![feature(test)] -extern crate clap; -extern crate test; - use clap::{App, AppSettings, Arg, ArgGroup, ArgSettings}; - use test::Bencher; #[bench] diff --git a/clap_derive/README.md b/clap_derive/README.md index ff89f477..2f78df83 100644 --- a/clap_derive/README.md +++ b/clap_derive/README.md @@ -10,7 +10,7 @@ consumers. ## Documentation -Find it on [Docs.rs](https://docs.rs/clap_derive). You can also check the [examples](https://github.com/clap-rs/clap_derive/tree/master/examples) and the [changelog](https://github.com/clap-rs/clap_derive/blob/master/CHANGELOG.md). +Find it on [Docs.rs](https://docs.rs/clap_derive). You can also check the [examples](https://github.com/clap-rs/clap/tree/master/clap_derive/examples) and the [changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md). ## Example @@ -23,9 +23,6 @@ clap = "3" And then, in your rust file: ```rust -#[macro_use] -extern crate clap; - use std::path::PathBuf; use clap::Clap; diff --git a/clap_derive/src/derives/clap.rs b/clap_derive/src/derives/clap.rs index 0367dcf5..bee22813 100644 --- a/clap_derive/src/derives/clap.rs +++ b/clap_derive/src/derives/clap.rs @@ -13,6 +13,7 @@ // MIT/Apache 2.0 license. use proc_macro2::Span; use proc_macro_error::{abort, abort_call_site, set_dummy}; +use quote::{quote, quote_spanned}; use syn::{self, punctuated, spanned::Spanned, token, FieldsUnnamed, Ident}; use super::{from_argmatches, into_app, sub_type, Attrs, Kind, Name, ParserKind, Ty}; diff --git a/clap_derive/src/derives/from_argmatches.rs b/clap_derive/src/derives/from_argmatches.rs index 057e638b..fe12628f 100644 --- a/clap_derive/src/derives/from_argmatches.rs +++ b/clap_derive/src/derives/from_argmatches.rs @@ -14,10 +14,9 @@ use std::env; use proc_macro2; -use syn; -use syn::punctuated; +use quote::{quote, quote_spanned}; use syn::spanned::Spanned as _; -use syn::token; +use syn::{punctuated, token}; use super::{ spanned::Sp, sub_type, Attrs, Kind, Name, ParserKind, Ty, DEFAULT_CASING, DEFAULT_ENV_CASING, diff --git a/clap_derive/src/derives/into_app.rs b/clap_derive/src/derives/into_app.rs index 16b3c397..b7949d45 100644 --- a/clap_derive/src/derives/into_app.rs +++ b/clap_derive/src/derives/into_app.rs @@ -14,6 +14,7 @@ use std::env; use proc_macro2; +use quote::quote; use syn; use super::{spanned::Sp, Attrs, GenOutput, Name, DEFAULT_CASING, DEFAULT_ENV_CASING}; diff --git a/clap_derive/src/lib.rs b/clap_derive/src/lib.rs index 214cdeb6..78cb3c65 100644 --- a/clap_derive/src/lib.rs +++ b/clap_derive/src/lib.rs @@ -18,14 +18,9 @@ #![recursion_limit = "256"] extern crate proc_macro; -extern crate syn; -#[macro_use] -extern crate quote; -extern crate heck; -extern crate proc_macro2; -extern crate proc_macro_error; use proc_macro_error::proc_macro_error; +use syn; mod derives; diff --git a/clap_derive/tests/deny-warnings.rs b/clap_derive/tests/deny-warnings.rs index 68643752..75e88765 100644 --- a/clap_derive/tests/deny-warnings.rs +++ b/clap_derive/tests/deny-warnings.rs @@ -14,8 +14,6 @@ #![deny(warnings)] -extern crate clap; - use clap::Clap; fn try_str(s: &str) -> Result { diff --git a/clap_derive/tests/utils.rs b/clap_derive/tests/utils.rs index dd8e8a93..8d39a273 100644 --- a/clap_derive/tests/utils.rs +++ b/clap_derive/tests/utils.rs @@ -1,6 +1,3 @@ -#![allow(unused)] -extern crate clap; - use clap::IntoApp; pub fn get_help() -> String { diff --git a/examples/01a_quick_example.rs b/examples/01a_quick_example.rs index 4dd1be9a..2311bf80 100644 --- a/examples/01a_quick_example.rs +++ b/examples/01a_quick_example.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::App; fn main() { diff --git a/examples/01b_quick_example.rs b/examples/01b_quick_example.rs index 05796e5a..2faf3791 100644 --- a/examples/01b_quick_example.rs +++ b/examples/01b_quick_example.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/02_apps.rs b/examples/02_apps.rs index 29e16e99..03555317 100644 --- a/examples/02_apps.rs +++ b/examples/02_apps.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::App; fn main() { diff --git a/examples/03_args.rs b/examples/03_args.rs index e0274cd3..e85c6091 100644 --- a/examples/03_args.rs +++ b/examples/03_args.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/04_using_matches.rs b/examples/04_using_matches.rs index 64ff929f..ad6d5c05 100644 --- a/examples/04_using_matches.rs +++ b/examples/04_using_matches.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/05_flag_args.rs b/examples/05_flag_args.rs index f2ebb9da..ea4ada45 100644 --- a/examples/05_flag_args.rs +++ b/examples/05_flag_args.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/06_positional_args.rs b/examples/06_positional_args.rs index 10b53cd2..adc0d59d 100644 --- a/examples/06_positional_args.rs +++ b/examples/06_positional_args.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/07_option_args.rs b/examples/07_option_args.rs index 3ad81f4e..4a7764b7 100644 --- a/examples/07_option_args.rs +++ b/examples/07_option_args.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/08_subcommands.rs b/examples/08_subcommands.rs index dc584edc..383ea4cc 100644 --- a/examples/08_subcommands.rs +++ b/examples/08_subcommands.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/10_default_values.rs b/examples/10_default_values.rs index 16b5722e..1b975a24 100644 --- a/examples/10_default_values.rs +++ b/examples/10_default_values.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/11_only_specific_values.rs b/examples/11_only_specific_values.rs index 73c6cee3..05d5cc77 100644 --- a/examples/11_only_specific_values.rs +++ b/examples/11_only_specific_values.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/14_groups.rs b/examples/14_groups.rs index 4a1ea839..e72da1cc 100644 --- a/examples/14_groups.rs +++ b/examples/14_groups.rs @@ -20,8 +20,6 @@ /// of the three numbers. So you create three flags `--major`, `--minor`, and `--patch`. All of /// these arguments shouldn't be used at one time but you want to specify that *at least one* of /// them is used. For this, you can create a group. -extern crate clap; - use clap::{App, Arg, ArgGroup}; fn main() { diff --git a/examples/15_custom_validator.rs b/examples/15_custom_validator.rs index d470b168..a15161c0 100644 --- a/examples/15_custom_validator.rs +++ b/examples/15_custom_validator.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/16_app_settings.rs b/examples/16_app_settings.rs index 2f4ef0c2..a76c6d0e 100644 --- a/examples/16_app_settings.rs +++ b/examples/16_app_settings.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, AppSettings}; fn main() { diff --git a/examples/20_subcommands.rs b/examples/20_subcommands.rs index b0d4b562..36657904 100644 --- a/examples/20_subcommands.rs +++ b/examples/20_subcommands.rs @@ -39,8 +39,6 @@ // Let's make a quick program to illustrate. We'll be using the same example as above but for // brevity sake we won't implement all of the subcommands, only a few. -extern crate clap; - use clap::{App, AppSettings, Arg}; fn main() { diff --git a/examples/21_aliases.rs b/examples/21_aliases.rs index 1fd4b724..bd5b0034 100644 --- a/examples/21_aliases.rs +++ b/examples/21_aliases.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; fn main() { diff --git a/examples/22_stop_parsing_with_--.rs b/examples/22_stop_parsing_with_--.rs index bb0e4fa1..9e63a0ed 100644 --- a/examples/22_stop_parsing_with_--.rs +++ b/examples/22_stop_parsing_with_--.rs @@ -1,5 +1,3 @@ -extern crate clap; - use clap::{App, Arg}; /// myprog -f -p=bob -- sloppy slop slop diff --git a/src/lib.rs b/src/lib.rs index 300c292e..77411fb1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -186,7 +186,6 @@ //! // //! // This example demonstrates clap's building from YAML style of creating arguments which is far //! // more clean, but takes a very small performance hit compared to the other two methods. -//! #[macro_use] //! use clap::App; //! //! fn main() {