Skip to content

Commit

Permalink
Auto merge of #5191 - JohnTitor:clean-up, r=flip1995
Browse files Browse the repository at this point in the history
Minor cleanup

- Use `Vec::with_capacity()` as possible
- Clean up imports

changelog: none
  • Loading branch information
bors committed Feb 18, 2020
2 parents 0da4dd0 + 06cb96e commit bfa3343
Show file tree
Hide file tree
Showing 12 changed files with 22 additions and 33 deletions.
5 changes: 2 additions & 3 deletions clippy_lints/src/booleans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
5 changes: 2 additions & 3 deletions clippy_lints/src/escape.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 6 additions & 8 deletions clippy_lints/src/indexing_slicing.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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 {
Expand All @@ -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,
Expand All @@ -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));
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/loops.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/matches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()));
Expand Down
1 change: 0 additions & 1 deletion clippy_lints/src/ptr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/ptr_offset_with_cast.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down Expand Up @@ -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,
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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))
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/shadow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/temporary_assignment.rs
Original file line number Diff line number Diff line change
@@ -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};
Expand Down
8 changes: 3 additions & 5 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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! {
Expand Down Expand Up @@ -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?");
}
Expand Down
3 changes: 1 addition & 2 deletions clippy_lints/src/utils/sugg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit bfa3343

Please sign in to comment.