Skip to content

Commit 40881e7

Browse files
committed
Auto merge of #4941 - lzutao:utils-mod, r=phansch
a few small cleanups changelog: none
2 parents 2a76cd8 + 20a8bef commit 40881e7

File tree

8 files changed

+43
-57
lines changed

8 files changed

+43
-57
lines changed

clippy_dev/src/main.rs

-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,5 @@
11
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
22

3-
extern crate clap;
4-
extern crate clippy_dev;
5-
extern crate regex;
6-
73
use clap::{App, Arg, SubCommand};
84
use clippy_dev::*;
95

clippy_dummy/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ keywords = ["clippy", "lint", "plugin"]
1414
categories = ["development-tools", "development-tools::cargo-plugins"]
1515

1616
[build-dependencies]
17-
term = "0.5.1"
17+
term = "0.6"

clippy_dummy/build.rs

+27-27
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
1-
extern crate term;
1+
use term::color::{GREEN, RED, WHITE};
2+
use term::{Attr, Error, Result};
23

34
fn main() {
4-
if let Err(_) = foo() {
5-
eprintln!("error: Clippy is no longer available via crates.io\n");
6-
eprintln!("help: please run `rustup component add clippy` instead");
5+
if foo().is_err() {
6+
eprintln!(
7+
"error: Clippy is no longer available via crates.io\n\n\
8+
help: please run `rustup component add clippy` instead"
9+
);
710
}
811
std::process::exit(1);
912
}
1013

11-
fn foo() -> Result<(), ()> {
12-
let mut t = term::stderr().ok_or(())?;
14+
fn foo() -> Result<()> {
15+
let mut t = term::stderr().ok_or(Error::NotSupported)?;
1316

14-
t.attr(term::Attr::Bold).map_err(|_| ())?;
15-
t.fg(term::color::RED).map_err(|_| ())?;
16-
write!(t, "\nerror: ").map_err(|_| ())?;
17+
t.attr(Attr::Bold)?;
18+
t.fg(RED)?;
19+
write!(t, "\nerror: ")?;
1720

21+
t.reset()?;
22+
t.fg(WHITE)?;
23+
writeln!(t, "Clippy is no longer available via crates.io\n")?;
1824

19-
t.reset().map_err(|_| ())?;
20-
t.fg(term::color::WHITE).map_err(|_| ())?;
21-
writeln!(t, "Clippy is no longer available via crates.io\n").map_err(|_| ())?;
25+
t.attr(Attr::Bold)?;
26+
t.fg(GREEN)?;
27+
write!(t, "help: ")?;
2228

29+
t.reset()?;
30+
t.fg(WHITE)?;
31+
write!(t, "please run `")?;
2332

24-
t.attr(term::Attr::Bold).map_err(|_| ())?;
25-
t.fg(term::color::GREEN).map_err(|_| ())?;
26-
write!(t, "help: ").map_err(|_| ())?;
33+
t.attr(Attr::Bold)?;
34+
write!(t, "rustup component add clippy")?;
2735

36+
t.reset()?;
37+
t.fg(WHITE)?;
38+
writeln!(t, "` instead")?;
2839

29-
t.reset().map_err(|_| ())?;
30-
t.fg(term::color::WHITE).map_err(|_| ())?;
31-
write!(t, "please run `").map_err(|_| ())?;
32-
33-
t.attr(term::Attr::Bold).map_err(|_| ())?;
34-
write!(t, "rustup component add clippy").map_err(|_| ())?;
35-
36-
t.reset().map_err(|_| ())?;
37-
t.fg(term::color::WHITE).map_err(|_| ())?;
38-
writeln!(t, "` instead").map_err(|_| ())?;
39-
40-
t.reset().map_err(|_| ())?;
40+
t.reset()?;
4141
Ok(())
4242
}

clippy_lints/src/consts.rs

+4-11
Original file line numberDiff line numberDiff line change
@@ -252,18 +252,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
252252
if let ExprKind::Path(qpath) = &callee.kind;
253253
let res = self.tables.qpath_res(qpath, callee.hir_id);
254254
if let Some(def_id) = res.opt_def_id();
255-
let get_def_path = self.lcx.get_def_path(def_id, );
256-
let def_path = get_def_path
257-
.iter()
258-
.copied()
259-
.map(Symbol::as_str)
260-
.collect::<Vec<_>>();
261-
if def_path[0] == "core";
262-
if def_path[1] == "num";
263-
if def_path[3] == "max_value";
264-
if def_path.len() == 4;
255+
let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect();
256+
let def_path: Vec<&str> = def_path.iter().map(|s| &**s).collect();
257+
if let ["core", "num", int_impl, "max_value"] = *def_path;
265258
then {
266-
let value = match &*def_path[2] {
259+
let value = match int_impl {
267260
"<impl i8>" => i8::max_value() as u128,
268261
"<impl i16>" => i16::max_value() as u128,
269262
"<impl i32>" => i32::max_value() as u128,

clippy_lints/src/utils/mod.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -869,16 +869,11 @@ pub fn remove_blocks(expr: &Expr) -> &Expr {
869869
if let ExprKind::Block(ref block, _) = expr.kind {
870870
if block.stmts.is_empty() {
871871
if let Some(ref expr) = block.expr {
872-
remove_blocks(expr)
873-
} else {
874-
expr
872+
return remove_blocks(expr);
875873
}
876-
} else {
877-
expr
878874
}
879-
} else {
880-
expr
881875
}
876+
expr
882877
}
883878

884879
pub fn is_self(slf: &Param) -> bool {
@@ -1228,12 +1223,13 @@ pub fn if_sequence(mut expr: &Expr) -> (SmallVec<[&Expr; 1]>, SmallVec<[&Block;
12281223
}
12291224

12301225
pub fn parent_node_is_if_expr<'a, 'b>(expr: &Expr, cx: &LateContext<'a, 'b>) -> bool {
1231-
let parent_id = cx.tcx.hir().get_parent_node(expr.hir_id);
1232-
let parent_node = cx.tcx.hir().get(parent_id);
1226+
let map = cx.tcx.hir();
1227+
let parent_id = map.get_parent_node(expr.hir_id);
1228+
let parent_node = map.get(parent_id);
12331229

12341230
match parent_node {
1235-
rustc::hir::Node::Expr(e) => higher::if_block(&e).is_some(),
1236-
rustc::hir::Node::Arm(e) => higher::if_block(&e.body).is_some(),
1231+
Node::Expr(e) => higher::if_block(&e).is_some(),
1232+
Node::Arm(e) => higher::if_block(&e.body).is_some(),
12371233
_ => false,
12381234
}
12391235
}

clippy_workspace_tests/src/main.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
#![deny(rust_2018_idioms)]
22

3-
fn main() {
4-
}
3+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

tests/fmt.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use std::path::PathBuf;
12
use std::process::Command;
23

34
#[test]
@@ -17,7 +18,7 @@ fn fmt() {
1718
return;
1819
}
1920

20-
let root_dir = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"));
21+
let root_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
2122
let dev_dir = root_dir.join("clippy_dev");
2223
let target_dir = root_dir.join("target");
2324
let target_dir = target_dir.to_str().unwrap();

0 commit comments

Comments
 (0)