mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 14:55:26 +00:00
a few small cleanups
This commit is contained in:
parent
6d12259811
commit
185e608ae2
@ -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::*;
|
||||
|
||||
|
@ -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(())
|
||||
}
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
#![deny(rust_2018_idioms)]
|
||||
|
||||
fn main() {
|
||||
}
|
||||
fn main() {}
|
||||
|
@ -0,0 +1 @@
|
||||
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user