mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-27 15:11:30 +00:00
Auto merge of #4941 - lzutao:utils-mod, r=phansch
a few small cleanups changelog: none
This commit is contained in:
commit
40881e7713
8 changed files with 43 additions and 57 deletions
|
@ -1,9 +1,5 @@
|
||||||
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
|
||||||
|
|
||||||
extern crate clap;
|
|
||||||
extern crate clippy_dev;
|
|
||||||
extern crate regex;
|
|
||||||
|
|
||||||
use clap::{App, Arg, SubCommand};
|
use clap::{App, Arg, SubCommand};
|
||||||
use clippy_dev::*;
|
use clippy_dev::*;
|
||||||
|
|
||||||
|
|
|
@ -14,4 +14,4 @@ keywords = ["clippy", "lint", "plugin"]
|
||||||
categories = ["development-tools", "development-tools::cargo-plugins"]
|
categories = ["development-tools", "development-tools::cargo-plugins"]
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
term = "0.5.1"
|
term = "0.6"
|
||||||
|
|
|
@ -1,42 +1,42 @@
|
||||||
extern crate term;
|
use term::color::{GREEN, RED, WHITE};
|
||||||
|
use term::{Attr, Error, Result};
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
if let Err(_) = foo() {
|
if foo().is_err() {
|
||||||
eprintln!("error: Clippy is no longer available via crates.io\n");
|
eprintln!(
|
||||||
eprintln!("help: please run `rustup component add clippy` instead");
|
"error: Clippy is no longer available via crates.io\n\n\
|
||||||
|
help: please run `rustup component add clippy` instead"
|
||||||
|
);
|
||||||
}
|
}
|
||||||
std::process::exit(1);
|
std::process::exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn foo() -> Result<(), ()> {
|
fn foo() -> Result<()> {
|
||||||
let mut t = term::stderr().ok_or(())?;
|
let mut t = term::stderr().ok_or(Error::NotSupported)?;
|
||||||
|
|
||||||
t.attr(term::Attr::Bold).map_err(|_| ())?;
|
t.attr(Attr::Bold)?;
|
||||||
t.fg(term::color::RED).map_err(|_| ())?;
|
t.fg(RED)?;
|
||||||
write!(t, "\nerror: ").map_err(|_| ())?;
|
write!(t, "\nerror: ")?;
|
||||||
|
|
||||||
|
t.reset()?;
|
||||||
|
t.fg(WHITE)?;
|
||||||
|
writeln!(t, "Clippy is no longer available via crates.io\n")?;
|
||||||
|
|
||||||
t.reset().map_err(|_| ())?;
|
t.attr(Attr::Bold)?;
|
||||||
t.fg(term::color::WHITE).map_err(|_| ())?;
|
t.fg(GREEN)?;
|
||||||
writeln!(t, "Clippy is no longer available via crates.io\n").map_err(|_| ())?;
|
write!(t, "help: ")?;
|
||||||
|
|
||||||
|
t.reset()?;
|
||||||
|
t.fg(WHITE)?;
|
||||||
|
write!(t, "please run `")?;
|
||||||
|
|
||||||
t.attr(term::Attr::Bold).map_err(|_| ())?;
|
t.attr(Attr::Bold)?;
|
||||||
t.fg(term::color::GREEN).map_err(|_| ())?;
|
write!(t, "rustup component add clippy")?;
|
||||||
write!(t, "help: ").map_err(|_| ())?;
|
|
||||||
|
|
||||||
|
t.reset()?;
|
||||||
|
t.fg(WHITE)?;
|
||||||
|
writeln!(t, "` instead")?;
|
||||||
|
|
||||||
t.reset().map_err(|_| ())?;
|
t.reset()?;
|
||||||
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(|_| ())?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -252,18 +252,11 @@ impl<'c, 'cc> ConstEvalLateContext<'c, 'cc> {
|
||||||
if let ExprKind::Path(qpath) = &callee.kind;
|
if let ExprKind::Path(qpath) = &callee.kind;
|
||||||
let res = self.tables.qpath_res(qpath, callee.hir_id);
|
let res = self.tables.qpath_res(qpath, callee.hir_id);
|
||||||
if let Some(def_id) = res.opt_def_id();
|
if let Some(def_id) = res.opt_def_id();
|
||||||
let get_def_path = self.lcx.get_def_path(def_id, );
|
let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect();
|
||||||
let def_path = get_def_path
|
let def_path: Vec<&str> = def_path.iter().map(|s| &**s).collect();
|
||||||
.iter()
|
if let ["core", "num", int_impl, "max_value"] = *def_path;
|
||||||
.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;
|
|
||||||
then {
|
then {
|
||||||
let value = match &*def_path[2] {
|
let value = match int_impl {
|
||||||
"<impl i8>" => i8::max_value() as u128,
|
"<impl i8>" => i8::max_value() as u128,
|
||||||
"<impl i16>" => i16::max_value() as u128,
|
"<impl i16>" => i16::max_value() as u128,
|
||||||
"<impl i32>" => i32::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 let ExprKind::Block(ref block, _) = expr.kind {
|
||||||
if block.stmts.is_empty() {
|
if block.stmts.is_empty() {
|
||||||
if let Some(ref expr) = block.expr {
|
if let Some(ref expr) = block.expr {
|
||||||
remove_blocks(expr)
|
return remove_blocks(expr);
|
||||||
} else {
|
|
||||||
expr
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
expr
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
expr
|
|
||||||
}
|
}
|
||||||
|
expr
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_self(slf: &Param) -> bool {
|
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 {
|
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 map = cx.tcx.hir();
|
||||||
let parent_node = cx.tcx.hir().get(parent_id);
|
let parent_id = map.get_parent_node(expr.hir_id);
|
||||||
|
let parent_node = map.get(parent_id);
|
||||||
|
|
||||||
match parent_node {
|
match parent_node {
|
||||||
rustc::hir::Node::Expr(e) => higher::if_block(&e).is_some(),
|
Node::Expr(e) => higher::if_block(&e).is_some(),
|
||||||
rustc::hir::Node::Arm(e) => higher::if_block(&e.body).is_some(),
|
Node::Arm(e) => higher::if_block(&e.body).is_some(),
|
||||||
_ => false,
|
_ => false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
#![deny(rust_2018_idioms)]
|
#![deny(rust_2018_idioms)]
|
||||||
|
|
||||||
fn main() {
|
fn main() {}
|
||||||
}
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
use std::path::PathBuf;
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -17,7 +18,7 @@ fn fmt() {
|
||||||
return;
|
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 dev_dir = root_dir.join("clippy_dev");
|
||||||
let target_dir = root_dir.join("target");
|
let target_dir = root_dir.join("target");
|
||||||
let target_dir = target_dir.to_str().unwrap();
|
let target_dir = target_dir.to_str().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue