Auto merge of #5191 - JohnTitor:clean-up, r=flip1995
Minor cleanup - Use `Vec::with_capacity()` as possible - Clean up imports changelog: none
This commit is contained in:
commit
bfa334391b
12 changed files with 22 additions and 33 deletions
|
|
@ -5,7 +5,6 @@ use crate::utils::{
|
|||
use if_chain::if_chain;
|
||||
use rustc::hir::map::Map;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::intravisit::*;
|
||||
use rustc_hir::*;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -60,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
|
|||
fn check_fn(
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: intravisit::FnKind<'tcx>,
|
||||
_: FnKind<'tcx>,
|
||||
_: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
|
|
@ -359,7 +358,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
|
|||
}
|
||||
simplified.push(simple_negated);
|
||||
}
|
||||
let mut improvements = Vec::new();
|
||||
let mut improvements = Vec::with_capacity(simplified.len());
|
||||
'simplified: for suggestion in &simplified {
|
||||
let simplified_stats = terminal_stats(suggestion);
|
||||
let mut improvement = false;
|
||||
|
|
|
|||
|
|
@ -11,7 +11,6 @@ use rustc_hir::*;
|
|||
use rustc_lint::LateContext;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use std::cmp::Ordering::{self, Equal};
|
||||
use std::cmp::PartialOrd;
|
||||
use std::convert::TryInto;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use syntax::ast::{FloatTy, LitKind};
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use rustc::ty::layout::LayoutOf;
|
||||
use rustc::ty::{self, Ty};
|
||||
use rustc_hir::intravisit as visit;
|
||||
use rustc_hir::HirIdSet;
|
||||
use rustc_hir::intravisit;
|
||||
use rustc_hir::{self, *};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -54,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
|
|||
fn check_fn(
|
||||
&mut self,
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
_: visit::FnKind<'tcx>,
|
||||
_: intravisit::FnKind<'tcx>,
|
||||
_: &'tcx FnDecl<'_>,
|
||||
body: &'tcx Body<'_>,
|
||||
_: Span,
|
||||
|
|
|
|||
|
|
@ -1,9 +1,7 @@
|
|||
//! lint on indexing and slicing operations
|
||||
|
||||
use crate::consts::{constant, Constant};
|
||||
use crate::utils;
|
||||
use crate::utils::higher;
|
||||
use crate::utils::higher::Range;
|
||||
use crate::utils::{higher, span_lint, span_lint_and_help};
|
||||
use rustc::ty;
|
||||
use rustc_hir::*;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -100,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
|||
|
||||
if let (Some(start), _) = const_range {
|
||||
if start > size {
|
||||
utils::span_lint(
|
||||
span_lint(
|
||||
cx,
|
||||
OUT_OF_BOUNDS_INDEXING,
|
||||
range.start.map_or(expr.span, |start| start.span),
|
||||
|
|
@ -112,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
|||
|
||||
if let (_, Some(end)) = const_range {
|
||||
if end > size {
|
||||
utils::span_lint(
|
||||
span_lint(
|
||||
cx,
|
||||
OUT_OF_BOUNDS_INDEXING,
|
||||
range.end.map_or(expr.span, |end| end.span),
|
||||
|
|
@ -136,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
|||
(None, None) => return, // [..] is ok.
|
||||
};
|
||||
|
||||
utils::span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
|
||||
span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
|
||||
} else {
|
||||
// Catchall non-range index, i.e., [n] or [n << m]
|
||||
if let ty::Array(..) = ty.kind {
|
||||
|
|
@ -147,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
|||
}
|
||||
}
|
||||
|
||||
utils::span_lint_and_help(
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
INDEXING_SLICING,
|
||||
expr.span,
|
||||
|
|
@ -163,7 +161,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
|
|||
/// the range. If the start or end is not constant, None is returned.
|
||||
fn to_const_range<'a, 'tcx>(
|
||||
cx: &LateContext<'a, 'tcx>,
|
||||
range: Range<'_>,
|
||||
range: higher::Range<'_>,
|
||||
array_size: u128,
|
||||
) -> (Option<u128>, Option<u128>) {
|
||||
let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c));
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ use rustc::ty::{self, Ty};
|
|||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id;
|
||||
use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::*;
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
|
|
|
|||
|
|
@ -724,7 +724,7 @@ fn is_panic_block(block: &Block<'_>) -> bool {
|
|||
|
||||
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
|
||||
if has_only_ref_pats(arms) {
|
||||
let mut suggs = Vec::new();
|
||||
let mut suggs = Vec::with_capacity(arms.len() + 1);
|
||||
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
|
||||
let span = ex.span.source_callsite();
|
||||
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use crate::utils::{
|
|||
use if_chain::if_chain;
|
||||
use rustc::ty;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::QPath;
|
||||
use rustc_hir::*;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::utils;
|
||||
use crate::utils::{snippet_opt, span_lint, span_lint_and_sugg};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
|
|||
|
||||
let msg = format!("use of `{}` with a `usize` casted to an `isize`", method);
|
||||
if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
|
||||
utils::span_lint_and_sugg(
|
||||
span_lint_and_sugg(
|
||||
cx,
|
||||
PTR_OFFSET_WITH_CAST,
|
||||
expr.span,
|
||||
|
|
@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
|
|||
Applicability::MachineApplicable,
|
||||
);
|
||||
} else {
|
||||
utils::span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
|
||||
span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -119,8 +119,8 @@ fn build_suggestion<'a, 'tcx>(
|
|||
receiver_expr: &Expr<'_>,
|
||||
cast_lhs_expr: &Expr<'_>,
|
||||
) -> Option<String> {
|
||||
let receiver = utils::snippet_opt(cx, receiver_expr.span)?;
|
||||
let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?;
|
||||
let receiver = snippet_opt(cx, receiver_expr.span)?;
|
||||
let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?;
|
||||
Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs))
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
|
|||
}
|
||||
|
||||
fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) {
|
||||
let mut bindings = Vec::new();
|
||||
let mut bindings = Vec::with_capacity(decl.inputs.len());
|
||||
for arg in iter_input_pats(decl, body) {
|
||||
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
|
||||
bindings.push((ident.name, ident.span))
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
use crate::utils::is_adjusted;
|
||||
use crate::utils::span_lint;
|
||||
use crate::utils::{is_adjusted, span_lint};
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{Expr, ExprKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
|
|
|
|||
|
|
@ -11,12 +11,10 @@ use rustc_hir::def::{DefKind, Res};
|
|||
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
|
||||
use rustc_hir::*;
|
||||
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
|
||||
use rustc_session::declare_tool_lint;
|
||||
use rustc_session::{declare_lint_pass, impl_lint_pass};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::source_map::{Span, Spanned};
|
||||
use rustc_span::symbol::SymbolStr;
|
||||
use syntax::ast;
|
||||
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name};
|
||||
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
|
||||
use syntax::visit::FnKind;
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
|
@ -380,7 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass {
|
|||
declare_lint_pass!(ProduceIce => [PRODUCE_ICE]);
|
||||
|
||||
impl EarlyLintPass for ProduceIce {
|
||||
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: ast::NodeId) {
|
||||
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
|
||||
if is_trigger_fn(fn_kind) {
|
||||
panic!("Would you like some help with that?");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,9 +12,8 @@ use rustc_span::{BytePos, Pos};
|
|||
use std::borrow::Cow;
|
||||
use std::convert::TryInto;
|
||||
use std::fmt::Display;
|
||||
use syntax::ast;
|
||||
use syntax::token;
|
||||
use syntax::util::parser::AssocOp;
|
||||
use syntax::{ast, token};
|
||||
|
||||
pub use crate::literal_representation::format_numeric_literal;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue