about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorflip1995 <hello@philkrones.com>2020-05-17 17:36:26 +0200
committerflip1995 <hello@philkrones.com>2020-05-17 17:36:26 +0200
commitf1d3086492db10deaa3268952792e93ad09ecec0 (patch)
treeafcbe3fb36c937b9dade83ce3644367e157c38dc /src
parent8bba1b758916d012a09463c4aade5750cd482f80 (diff)
downloadrust-f1d3086492db10deaa3268952792e93ad09ecec0.tar.gz
rust-f1d3086492db10deaa3268952792e93ad09ecec0.zip
Merge commit 'e214ea82ad0a751563acf67e1cd9279cf302db3a' into clippyup
Diffstat (limited to 'src')
-rw-r--r--src/driver.rs222
-rw-r--r--src/lintlist/mod.rs130
2 files changed, 154 insertions, 198 deletions
diff --git a/src/driver.rs b/src/driver.rs
index 1ce0300f239..d3a7e24937f 100644
--- a/src/driver.rs
+++ b/src/driver.rs
@@ -295,121 +295,119 @@ fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<Pat
 pub fn main() {
     rustc_driver::init_rustc_env_logger();
     lazy_static::initialize(&ICE_HOOK);
-    exit(
-        rustc_driver::catch_with_exit_code(move || {
-            let mut orig_args: Vec<String> = env::args().collect();
-
-            if orig_args.iter().any(|a| a == "--version" || a == "-V") {
-                let version_info = rustc_tools_util::get_version_info!();
-                println!("{}", version_info);
-                exit(0);
-            }
+    exit(rustc_driver::catch_with_exit_code(move || {
+        let mut orig_args: Vec<String> = env::args().collect();
 
-            // Get the sysroot, looking from most specific to this invocation to the least:
-            // - command line
-            // - runtime environment
-            //    - SYSROOT
-            //    - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
-            // - sysroot from rustc in the path
-            // - compile-time environment
-            //    - SYSROOT
-            //    - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
-            let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true);
-            let have_sys_root_arg = sys_root_arg.is_some();
-            let sys_root = sys_root_arg
-                .map(PathBuf::from)
-                .or_else(|| std::env::var("SYSROOT").ok().map(PathBuf::from))
-                .or_else(|| {
-                    let home = std::env::var("RUSTUP_HOME")
-                        .or_else(|_| std::env::var("MULTIRUST_HOME"))
-                        .ok();
-                    let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
-                        .or_else(|_| std::env::var("MULTIRUST_TOOLCHAIN"))
-                        .ok();
-                    toolchain_path(home, toolchain)
-                })
-                .or_else(|| {
-                    Command::new("rustc")
-                        .arg("--print")
-                        .arg("sysroot")
-                        .output()
-                        .ok()
-                        .and_then(|out| String::from_utf8(out.stdout).ok())
-                        .map(|s| PathBuf::from(s.trim()))
-                })
-                .or_else(|| option_env!("SYSROOT").map(PathBuf::from))
-                .or_else(|| {
-                    let home = option_env!("RUSTUP_HOME")
-                        .or(option_env!("MULTIRUST_HOME"))
-                        .map(ToString::to_string);
-                    let toolchain = option_env!("RUSTUP_TOOLCHAIN")
-                        .or(option_env!("MULTIRUST_TOOLCHAIN"))
-                        .map(ToString::to_string);
-                    toolchain_path(home, toolchain)
-                })
-                .map(|pb| pb.to_string_lossy().to_string())
-                .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
-
-            // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
-            // We're invoking the compiler programmatically, so we ignore this/
-            let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
-
-            if wrapper_mode {
-                // we still want to be able to invoke it normally though
-                orig_args.remove(1);
-            }
+        if orig_args.iter().any(|a| a == "--version" || a == "-V") {
+            let version_info = rustc_tools_util::get_version_info!();
+            println!("{}", version_info);
+            exit(0);
+        }
 
-            if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
-                display_help();
-                exit(0);
-            }
+        // Get the sysroot, looking from most specific to this invocation to the least:
+        // - command line
+        // - runtime environment
+        //    - SYSROOT
+        //    - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
+        // - sysroot from rustc in the path
+        // - compile-time environment
+        //    - SYSROOT
+        //    - RUSTUP_HOME, MULTIRUST_HOME, RUSTUP_TOOLCHAIN, MULTIRUST_TOOLCHAIN
+        let sys_root_arg = arg_value(&orig_args, "--sysroot", |_| true);
+        let have_sys_root_arg = sys_root_arg.is_some();
+        let sys_root = sys_root_arg
+            .map(PathBuf::from)
+            .or_else(|| std::env::var("SYSROOT").ok().map(PathBuf::from))
+            .or_else(|| {
+                let home = std::env::var("RUSTUP_HOME")
+                    .or_else(|_| std::env::var("MULTIRUST_HOME"))
+                    .ok();
+                let toolchain = std::env::var("RUSTUP_TOOLCHAIN")
+                    .or_else(|_| std::env::var("MULTIRUST_TOOLCHAIN"))
+                    .ok();
+                toolchain_path(home, toolchain)
+            })
+            .or_else(|| {
+                Command::new("rustc")
+                    .arg("--print")
+                    .arg("sysroot")
+                    .output()
+                    .ok()
+                    .and_then(|out| String::from_utf8(out.stdout).ok())
+                    .map(|s| PathBuf::from(s.trim()))
+            })
+            .or_else(|| option_env!("SYSROOT").map(PathBuf::from))
+            .or_else(|| {
+                let home = option_env!("RUSTUP_HOME")
+                    .or(option_env!("MULTIRUST_HOME"))
+                    .map(ToString::to_string);
+                let toolchain = option_env!("RUSTUP_TOOLCHAIN")
+                    .or(option_env!("MULTIRUST_TOOLCHAIN"))
+                    .map(ToString::to_string);
+                toolchain_path(home, toolchain)
+            })
+            .map(|pb| pb.to_string_lossy().to_string())
+            .expect("need to specify SYSROOT env var during clippy compilation, or use rustup or multirust");
 
-            let should_describe_lints = || {
-                let args: Vec<_> = env::args().collect();
-                args.windows(2).any(|args| {
-                    args[1] == "help"
-                        && match args[0].as_str() {
-                            "-W" | "-A" | "-D" | "-F" => true,
-                            _ => false,
-                        }
-                })
-            };
-
-            if !wrapper_mode && should_describe_lints() {
-                describe_lints();
-                exit(0);
-            }
+        // Setting RUSTC_WRAPPER causes Cargo to pass 'rustc' as the first argument.
+        // We're invoking the compiler programmatically, so we ignore this/
+        let wrapper_mode = orig_args.get(1).map(Path::new).and_then(Path::file_stem) == Some("rustc".as_ref());
+
+        if wrapper_mode {
+            // we still want to be able to invoke it normally though
+            orig_args.remove(1);
+        }
+
+        if !wrapper_mode && (orig_args.iter().any(|a| a == "--help" || a == "-h") || orig_args.len() == 1) {
+            display_help();
+            exit(0);
+        }
+
+        let should_describe_lints = || {
+            let args: Vec<_> = env::args().collect();
+            args.windows(2).any(|args| {
+                args[1] == "help"
+                    && match args[0].as_str() {
+                        "-W" | "-A" | "-D" | "-F" => true,
+                        _ => false,
+                    }
+            })
+        };
 
-            // this conditional check for the --sysroot flag is there so users can call
-            // `clippy_driver` directly
-            // without having to pass --sysroot or anything
-            let mut args: Vec<String> = orig_args.clone();
-            if !have_sys_root_arg {
-                args.extend(vec!["--sysroot".into(), sys_root]);
-            };
-
-            // this check ensures that dependencies are built but not linted and the final
-            // crate is linted but not built
-            let clippy_enabled = env::var("CLIPPY_TESTS").map_or(false, |val| val == "true")
-                || arg_value(&orig_args, "--cap-lints", |val| val == "allow").is_none();
-
-            if clippy_enabled {
-                args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
-                if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
-                    args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
-                        if s.is_empty() {
-                            None
-                        } else {
-                            Some(s.to_string())
-                        }
-                    }));
-                }
+        if !wrapper_mode && should_describe_lints() {
+            describe_lints();
+            exit(0);
+        }
+
+        // this conditional check for the --sysroot flag is there so users can call
+        // `clippy_driver` directly
+        // without having to pass --sysroot or anything
+        let mut args: Vec<String> = orig_args.clone();
+        if !have_sys_root_arg {
+            args.extend(vec!["--sysroot".into(), sys_root]);
+        };
+
+        // this check ensures that dependencies are built but not linted and the final
+        // crate is linted but not built
+        let clippy_enabled = env::var("CLIPPY_TESTS").map_or(false, |val| val == "true")
+            || arg_value(&orig_args, "--cap-lints", |val| val == "allow").is_none();
+
+        if clippy_enabled {
+            args.extend(vec!["--cfg".into(), r#"feature="cargo-clippy""#.into()]);
+            if let Ok(extra_args) = env::var("CLIPPY_ARGS") {
+                args.extend(extra_args.split("__CLIPPY_HACKERY__").filter_map(|s| {
+                    if s.is_empty() {
+                        None
+                    } else {
+                        Some(s.to_string())
+                    }
+                }));
             }
-            let mut clippy = ClippyCallbacks;
-            let mut default = DefaultCallbacks;
-            let callbacks: &mut (dyn rustc_driver::Callbacks + Send) =
-                if clippy_enabled { &mut clippy } else { &mut default };
-            rustc_driver::run_compiler(&args, callbacks, None, None)
-        })
-    )
+        }
+        let mut clippy = ClippyCallbacks;
+        let mut default = DefaultCallbacks;
+        let callbacks: &mut (dyn rustc_driver::Callbacks + Send) =
+            if clippy_enabled { &mut clippy } else { &mut default };
+        rustc_driver::run_compiler(&args, callbacks, None, None)
+    }))
 }
diff --git a/src/lintlist/mod.rs b/src/lintlist/mod.rs
index 51d1cb2216a..9457a64f9c6 100644
--- a/src/lintlist/mod.rs
+++ b/src/lintlist/mod.rs
@@ -67,25 +67,25 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "bit_mask",
     },
     Lint {
-        name: "blacklisted_name",
-        group: "style",
-        desc: "usage of a blacklisted/placeholder name",
+        name: "bind_instead_of_map",
+        group: "complexity",
+        desc: "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`",
         deprecation: None,
-        module: "blacklisted_name",
+        module: "methods",
     },
     Lint {
-        name: "block_in_if_condition_expr",
+        name: "blacklisted_name",
         group: "style",
-        desc: "braces that can be eliminated in conditions, e.g., `if { true } ...`",
+        desc: "usage of a blacklisted/placeholder name",
         deprecation: None,
-        module: "block_in_if_condition",
+        module: "blacklisted_name",
     },
     Lint {
-        name: "block_in_if_condition_stmt",
+        name: "blocks_in_if_conditions",
         group: "style",
-        desc: "complex blocks in conditions, e.g., `if { let x = true; x } ...`",
+        desc: "useless or complex blocks that can be eliminated in conditions",
         deprecation: None,
-        module: "block_in_if_condition",
+        module: "blocks_in_if_conditions",
     },
     Lint {
         name: "bool_comparison",
@@ -522,6 +522,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "methods",
     },
     Lint {
+        name: "expect_used",
+        group: "restriction",
+        desc: "using `.expect()` on `Result` or `Option`, which might be better handled",
+        deprecation: None,
+        module: "methods",
+    },
+    Lint {
         name: "expl_impl_clone_on_copy",
         group: "pedantic",
         desc: "implementing `Clone` explicitly on `Copy` types",
@@ -676,16 +683,9 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "loops",
     },
     Lint {
-        name: "for_loop_over_option",
-        group: "correctness",
-        desc: "for-looping over an `Option`, which is more clearly expressed as an `if let`",
-        deprecation: None,
-        module: "loops",
-    },
-    Lint {
-        name: "for_loop_over_result",
+        name: "for_loops_over_fallibles",
         group: "correctness",
-        desc: "for-looping over a `Result`, which is more clearly expressed as an `if let`",
+        desc: "for-looping over an `Option` or a `Result`, which is more clearly expressed as an `if let`",
         deprecation: None,
         module: "loops",
     },
@@ -725,13 +725,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "methods",
     },
     Lint {
-        name: "identity_conversion",
-        group: "complexity",
-        desc: "using always-identical `Into`/`From`/`IntoIter` conversions",
-        deprecation: None,
-        module: "identity_conversion",
-    },
-    Lint {
         name: "identity_op",
         group: "complexity",
         desc: "using identity operations, e.g., `x + 0` or `y / 1`",
@@ -1145,6 +1138,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "methods",
     },
     Lint {
+        name: "map_unwrap_or",
+        group: "pedantic",
+        desc: "using `.map(f).unwrap_or(a)` or `.map(f).unwrap_or_else(func)`, which are more succinctly expressed as `map_or(a, f)` or `map_or_else(a, f)`",
+        deprecation: None,
+        module: "methods",
+    },
+    Lint {
         name: "match_as_ref",
         group: "complexity",
         desc: "a `match` on an Option value instead of using `as_ref()` or `as_mut`",
@@ -1579,13 +1579,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "eq_op",
     },
     Lint {
-        name: "option_and_then_some",
-        group: "complexity",
-        desc: "using `Option.and_then(|x| Some(y))`, which is more succinctly expressed as `map(|x| y)`",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
         name: "option_as_ref_deref",
         group: "complexity",
         desc: "using `as_ref().map(Deref::deref)`, which is more succinctly expressed as `as_deref()`",
@@ -1600,13 +1593,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "option_env_unwrap",
     },
     Lint {
-        name: "option_expect_used",
-        group: "restriction",
-        desc: "using `Option.expect()`, which might be better handled",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
         name: "option_map_or_none",
         group: "style",
         desc: "using `Option.map_or(None, f)`, which is more succinctly expressed as `and_then(f)`",
@@ -1621,20 +1607,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "map_unit_fn",
     },
     Lint {
-        name: "option_map_unwrap_or",
-        group: "pedantic",
-        desc: "using `Option.map(f).unwrap_or(a)`, which is more succinctly expressed as `map_or(a, f)`",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
-        name: "option_map_unwrap_or_else",
-        group: "pedantic",
-        desc: "using `Option.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `map_or_else(g, f)`",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
         name: "option_option",
         group: "pedantic",
         desc: "usage of `Option<Option<T>>`",
@@ -1642,13 +1614,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "types",
     },
     Lint {
-        name: "option_unwrap_used",
-        group: "restriction",
-        desc: "using `Option.unwrap()`, which should at least get a better message using `expect()`",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
         name: "or_fun_call",
         group: "perf",
         desc: "using any `*or` method with a function call, which suggests `*or_else`",
@@ -1887,13 +1852,6 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "matches",
     },
     Lint {
-        name: "result_expect_used",
-        group: "restriction",
-        desc: "using `Result.expect()`, which might be better handled",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
         name: "result_map_or_into_option",
         group: "style",
         desc: "using `Result.map_or(None, Some)`, which is more succinctly expressed as `ok()`",
@@ -1908,25 +1866,11 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "map_unit_fn",
     },
     Lint {
-        name: "result_map_unwrap_or_else",
-        group: "pedantic",
-        desc: "using `Result.map(f).unwrap_or_else(g)`, which is more succinctly expressed as `.map_or_else(g, f)`",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
-        name: "result_unwrap_used",
-        group: "restriction",
-        desc: "using `Result.unwrap()`, which might be better handled",
-        deprecation: None,
-        module: "methods",
-    },
-    Lint {
-        name: "reverse_range_loop",
+        name: "reversed_empty_ranges",
         group: "correctness",
-        desc: "iteration over an empty range, such as `10..0` or `5..5`",
+        desc: "reversing the limits of range expressions, resulting in empty ranges",
         deprecation: None,
-        module: "loops",
+        module: "ranges",
     },
     Lint {
         name: "same_functions_in_if_condition",
@@ -2426,6 +2370,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "returns",
     },
     Lint {
+        name: "unwrap_used",
+        group: "restriction",
+        desc: "using `.unwrap()` on `Result` or `Option`, which should at least get a better message using `expect()`",
+        deprecation: None,
+        module: "methods",
+    },
+    Lint {
         name: "use_debug",
         group: "restriction",
         desc: "use of `Debug`-based formatting",
@@ -2461,6 +2412,13 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
         module: "attrs",
     },
     Lint {
+        name: "useless_conversion",
+        group: "complexity",
+        desc: "calls to `Into`/`From`/`IntoIter` that performs useless conversions to the same type",
+        deprecation: None,
+        module: "useless_conversion",
+    },
+    Lint {
         name: "useless_format",
         group: "complexity",
         desc: "useless use of `format!`",
@@ -2469,7 +2427,7 @@ pub static ref ALL_LINTS: Vec<Lint> = vec![
     },
     Lint {
         name: "useless_let_if_seq",
-        group: "style",
+        group: "nursery",
         desc: "unidiomatic `let mut` declaration followed by initialization in `if`",
         deprecation: None,
         module: "let_if_seq",