Auto merge of #4941 - lzutao:utils-mod, r=phansch

a few small cleanups

changelog: none
This commit is contained in:
bors 2019-12-23 06:00:54 +00:00
commit 40881e7713
8 changed files with 43 additions and 57 deletions

View file

@ -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::*;

View file

@ -14,4 +14,4 @@ keywords = ["clippy", "lint", "plugin"]
categories = ["development-tools", "development-tools::cargo-plugins"]
[build-dependencies]
term = "0.5.1"
term = "0.6"

View file

@ -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(())
}

View file

@ -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::<Vec<_>>();
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 {
"<impl i8>" => i8::max_value() as u128,
"<impl i16>" => i16::max_value() as u128,
"<impl i32>" => i32::max_value() as u128,

View file

@ -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,
}
}

View file

@ -1,4 +1,3 @@
#![deny(rust_2018_idioms)]
fn main() {
}
fn main() {}

View file

@ -0,0 +1 @@

View file

@ -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();