Skip to content

Commit

Permalink
Auto merge of #4941 - lzutao:utils-mod, r=phansch
Browse files Browse the repository at this point in the history
a few small cleanups

changelog: none
  • Loading branch information
bors committed Dec 23, 2019
2 parents 2a76cd8 + 20a8bef commit 40881e7
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 57 deletions.
4 changes: 0 additions & 4 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
@@ -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::*;

Expand Down
2 changes: 1 addition & 1 deletion clippy_dummy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ keywords = ["clippy", "lint", "plugin"]
categories = ["development-tools", "development-tools::cargo-plugins"]

[build-dependencies]
term = "0.5.1"
term = "0.6"
54 changes: 27 additions & 27 deletions clippy_dummy/build.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
15 changes: 4 additions & 11 deletions clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
18 changes: 7 additions & 11 deletions clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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,
}
}
3 changes: 1 addition & 2 deletions clippy_workspace_tests/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#![deny(rust_2018_idioms)]

fn main() {
}
fn main() {}
1 change: 1 addition & 0 deletions clippy_workspace_tests/subcrate/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 2 additions & 1 deletion tests/fmt.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::path::PathBuf;
use std::process::Command;

#[test]
Expand All @@ -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();
Expand Down

0 comments on commit 40881e7

Please sign in to comment.