diff --git a/clippy_dev/src/main.rs b/clippy_dev/src/main.rs index 3010e0d24..22a2f2ca7 100644 --- a/clippy_dev/src/main.rs +++ b/clippy_dev/src/main.rs @@ -1,9 +1,5 @@ #![cfg_attr(feature = "deny-warnings", deny(warnings))] -extern crate clap; -extern crate clippy_dev; -extern crate regex; - use clap::{App, Arg, SubCommand}; use clippy_dev::*; diff --git a/clippy_dummy/Cargo.toml b/clippy_dummy/Cargo.toml index 064fd8a6f..7b11795fa 100644 --- a/clippy_dummy/Cargo.toml +++ b/clippy_dummy/Cargo.toml @@ -14,4 +14,4 @@ keywords = ["clippy", "lint", "plugin"] categories = ["development-tools", "development-tools::cargo-plugins"] [build-dependencies] -term = "0.5.1" +term = "0.6" diff --git a/clippy_dummy/build.rs b/clippy_dummy/build.rs index 1288250da..21af4f824 100644 --- a/clippy_dummy/build.rs +++ b/clippy_dummy/build.rs @@ -1,42 +1,42 @@ -extern crate term; +use term::color::{GREEN, RED, WHITE}; +use term::{Attr, Error, Result}; fn main() { - if let Err(_) = foo() { - eprintln!("error: Clippy is no longer available via crates.io\n"); - eprintln!("help: please run `rustup component add clippy` instead"); + if foo().is_err() { + eprintln!( + "error: Clippy is no longer available via crates.io\n\n\ + help: please run `rustup component add clippy` instead" + ); } std::process::exit(1); } -fn foo() -> Result<(), ()> { - let mut t = term::stderr().ok_or(())?; +fn foo() -> Result<()> { + let mut t = term::stderr().ok_or(Error::NotSupported)?; - t.attr(term::Attr::Bold).map_err(|_| ())?; - t.fg(term::color::RED).map_err(|_| ())?; - write!(t, "\nerror: ").map_err(|_| ())?; + t.attr(Attr::Bold)?; + t.fg(RED)?; + write!(t, "\nerror: ")?; + t.reset()?; + t.fg(WHITE)?; + writeln!(t, "Clippy is no longer available via crates.io\n")?; - t.reset().map_err(|_| ())?; - t.fg(term::color::WHITE).map_err(|_| ())?; - writeln!(t, "Clippy is no longer available via crates.io\n").map_err(|_| ())?; + t.attr(Attr::Bold)?; + t.fg(GREEN)?; + write!(t, "help: ")?; + t.reset()?; + t.fg(WHITE)?; + write!(t, "please run `")?; - t.attr(term::Attr::Bold).map_err(|_| ())?; - t.fg(term::color::GREEN).map_err(|_| ())?; - write!(t, "help: ").map_err(|_| ())?; + t.attr(Attr::Bold)?; + write!(t, "rustup component add clippy")?; + t.reset()?; + t.fg(WHITE)?; + writeln!(t, "` instead")?; - t.reset().map_err(|_| ())?; - t.fg(term::color::WHITE).map_err(|_| ())?; - write!(t, "please run `").map_err(|_| ())?; - - t.attr(term::Attr::Bold).map_err(|_| ())?; - write!(t, "rustup component add clippy").map_err(|_| ())?; - - t.reset().map_err(|_| ())?; - t.fg(term::color::WHITE).map_err(|_| ())?; - writeln!(t, "` instead").map_err(|_| ())?; - - t.reset().map_err(|_| ())?; + t.reset()?; Ok(()) } diff --git a/clippy_lints/src/consts.rs b/clippy_lints/src/consts.rs index 5d62a7d51..d86766ee0 100644 --- a/clippy_lints/src/consts.rs +++ b/clippy_lints/src/consts.rs @@ -252,18 +252,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> { if let ExprKind::Path(qpath) = &callee.kind; let res = self.tables.qpath_res(qpath, callee.hir_id); if let Some(def_id) = res.opt_def_id(); - let get_def_path = self.lcx.get_def_path(def_id, ); - let def_path = get_def_path - .iter() - .copied() - .map(Symbol::as_str) - .collect::>(); - if def_path[0] == "core"; - if def_path[1] == "num"; - if def_path[3] == "max_value"; - if def_path.len() == 4; + let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect(); + let def_path: Vec<&str> = def_path.iter().map(|s| &**s).collect(); + if let ["core", "num", int_impl, "max_value"] = *def_path; then { - let value = match &*def_path[2] { + let value = match int_impl { "" => i8::max_value() as u128, "" => i16::max_value() as u128, "" => i32::max_value() as u128, diff --git a/clippy_lints/src/utils/mod.rs b/clippy_lints/src/utils/mod.rs index 1d3b7ea2c..552a78d28 100644 --- a/clippy_lints/src/utils/mod.rs +++ b/clippy_lints/src/utils/mod.rs @@ -869,16 +869,11 @@ pub fn remove_blocks(expr: &Expr) -> &Expr { if let ExprKind::Block(ref block, _) = expr.kind { if block.stmts.is_empty() { if let Some(ref expr) = block.expr { - remove_blocks(expr) - } else { - expr + return remove_blocks(expr); } - } else { - expr } - } else { - expr } + expr } pub fn is_self(slf: &Param) -> bool { @@ -1228,12 +1223,13 @@ pub fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block; } pub fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool { - let parent_id = cx.tcx.hir().get_parent_node(expr.hir_id); - let parent_node = cx.tcx.hir().get(parent_id); + let map = cx.tcx.hir(); + let parent_id = map.get_parent_node(expr.hir_id); + let parent_node = map.get(parent_id); match parent_node { - rustc::hir::Node::Expr(e) => higher::if_block(&e).is_some(), - rustc::hir::Node::Arm(e) => higher::if_block(&e.body).is_some(), + Node::Expr(e) => higher::if_block(&e).is_some(), + Node::Arm(e) => higher::if_block(&e.body).is_some(), _ => false, } } diff --git a/clippy_workspace_tests/src/main.rs b/clippy_workspace_tests/src/main.rs index 0dcdf6383..b322eca1d 100644 --- a/clippy_workspace_tests/src/main.rs +++ b/clippy_workspace_tests/src/main.rs @@ -1,4 +1,3 @@ #![deny(rust_2018_idioms)] -fn main() { -} +fn main() {} diff --git a/clippy_workspace_tests/subcrate/src/lib.rs b/clippy_workspace_tests/subcrate/src/lib.rs index e69de29bb..8b1378917 100644 --- a/clippy_workspace_tests/subcrate/src/lib.rs +++ b/clippy_workspace_tests/subcrate/src/lib.rs @@ -0,0 +1 @@ + diff --git a/tests/fmt.rs b/tests/fmt.rs index ba35abbfb..962425d95 100644 --- a/tests/fmt.rs +++ b/tests/fmt.rs @@ -1,3 +1,4 @@ +use std::path::PathBuf; use std::process::Command; #[test] @@ -17,7 +18,7 @@ fn fmt() { return; } - let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")); + let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR")); let dev_dir = root_dir.join("clippy_dev"); let target_dir = root_dir.join("target"); let target_dir = target_dir.to_str().unwrap();