Skip to content

Commit bfa3343

Browse files
committed
Auto merge of rust-lang#5191 - JohnTitor:clean-up, r=flip1995
Minor cleanup - Use `Vec::with_capacity()` as possible - Clean up imports changelog: none
2 parents 0da4dd0 + 06cb96e commit bfa3343

12 files changed

+22
-33
lines changed

clippy_lints/src/booleans.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ use crate::utils::{
55
use if_chain::if_chain;
66
use rustc::hir::map::Map;
77
use rustc_errors::Applicability;
8-
use rustc_hir::intravisit;
98
use rustc_hir::intravisit::*;
109
use rustc_hir::*;
1110
use rustc_lint::{LateContext, LateLintPass};
@@ -60,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
6059
fn check_fn(
6160
&mut self,
6261
cx: &LateContext<'a, 'tcx>,
63-
_: intravisit::FnKind<'tcx>,
62+
_: FnKind<'tcx>,
6463
_: &'tcx FnDecl<'_>,
6564
body: &'tcx Body<'_>,
6665
_: Span,
@@ -359,7 +358,7 @@ impl<'a, 'tcx> NonminimalBoolVisitor<'a, 'tcx> {
359358
}
360359
simplified.push(simple_negated);
361360
}
362-
let mut improvements = Vec::new();
361+
let mut improvements = Vec::with_capacity(simplified.len());
363362
'simplified: for suggestion in &simplified {
364363
let simplified_stats = terminal_stats(suggestion);
365364
let mut improvement = false;

clippy_lints/src/consts.rs

-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ use rustc_hir::*;
1111
use rustc_lint::LateContext;
1212
use rustc_span::symbol::Symbol;
1313
use std::cmp::Ordering::{self, Equal};
14-
use std::cmp::PartialOrd;
1514
use std::convert::TryInto;
1615
use std::hash::{Hash, Hasher};
1716
use syntax::ast::{FloatTy, LitKind};

clippy_lints/src/escape.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use rustc::ty::layout::LayoutOf;
22
use rustc::ty::{self, Ty};
3-
use rustc_hir::intravisit as visit;
4-
use rustc_hir::HirIdSet;
3+
use rustc_hir::intravisit;
54
use rustc_hir::{self, *};
65
use rustc_infer::infer::TyCtxtInferExt;
76
use rustc_lint::{LateContext, LateLintPass};
@@ -54,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
5453
fn check_fn(
5554
&mut self,
5655
cx: &LateContext<'a, 'tcx>,
57-
_: visit::FnKind<'tcx>,
56+
_: intravisit::FnKind<'tcx>,
5857
_: &'tcx FnDecl<'_>,
5958
body: &'tcx Body<'_>,
6059
_: Span,

clippy_lints/src/indexing_slicing.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
//! lint on indexing and slicing operations
22
33
use crate::consts::{constant, Constant};
4-
use crate::utils;
5-
use crate::utils::higher;
6-
use crate::utils::higher::Range;
4+
use crate::utils::{higher, span_lint, span_lint_and_help};
75
use rustc::ty;
86
use rustc_hir::*;
97
use rustc_lint::{LateContext, LateLintPass};
@@ -100,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
10098

10199
if let (Some(start), _) = const_range {
102100
if start > size {
103-
utils::span_lint(
101+
span_lint(
104102
cx,
105103
OUT_OF_BOUNDS_INDEXING,
106104
range.start.map_or(expr.span, |start| start.span),
@@ -112,7 +110,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
112110

113111
if let (_, Some(end)) = const_range {
114112
if end > size {
115-
utils::span_lint(
113+
span_lint(
116114
cx,
117115
OUT_OF_BOUNDS_INDEXING,
118116
range.end.map_or(expr.span, |end| end.span),
@@ -136,7 +134,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
136134
(None, None) => return, // [..] is ok.
137135
};
138136

139-
utils::span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
137+
span_lint_and_help(cx, INDEXING_SLICING, expr.span, "slicing may panic.", help_msg);
140138
} else {
141139
// Catchall non-range index, i.e., [n] or [n << m]
142140
if let ty::Array(..) = ty.kind {
@@ -147,7 +145,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
147145
}
148146
}
149147

150-
utils::span_lint_and_help(
148+
span_lint_and_help(
151149
cx,
152150
INDEXING_SLICING,
153151
expr.span,
@@ -163,7 +161,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
163161
/// the range. If the start or end is not constant, None is returned.
164162
fn to_const_range<'a, 'tcx>(
165163
cx: &LateContext<'a, 'tcx>,
166-
range: Range<'_>,
164+
range: higher::Range<'_>,
167165
array_size: u128,
168166
) -> (Option<u128>, Option<u128>) {
169167
let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c));

clippy_lints/src/loops.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use rustc::ty::{self, Ty};
1818
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
1919
use rustc_errors::Applicability;
2020
use rustc_hir::def::{DefKind, Res};
21-
use rustc_hir::def_id;
2221
use rustc_hir::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
2322
use rustc_hir::*;
2423
use rustc_infer::infer::TyCtxtInferExt;

clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ fn is_panic_block(block: &Block<'_>) -> bool {
724724

725725
fn check_match_ref_pats(cx: &LateContext<'_, '_>, ex: &Expr<'_>, arms: &[Arm<'_>], expr: &Expr<'_>) {
726726
if has_only_ref_pats(arms) {
727-
let mut suggs = Vec::new();
727+
let mut suggs = Vec::with_capacity(arms.len() + 1);
728728
let (title, msg) = if let ExprKind::AddrOf(BorrowKind::Ref, Mutability::Not, ref inner) = ex.kind {
729729
let span = ex.span.source_callsite();
730730
suggs.push((span, Sugg::hir_with_macro_callsite(cx, inner, "..").to_string()));

clippy_lints/src/ptr.rs

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::utils::{
88
use if_chain::if_chain;
99
use rustc::ty;
1010
use rustc_errors::Applicability;
11-
use rustc_hir::QPath;
1211
use rustc_hir::*;
1312
use rustc_lint::{LateContext, LateLintPass};
1413
use rustc_session::{declare_lint_pass, declare_tool_lint};

clippy_lints/src/ptr_offset_with_cast.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use crate::utils;
1+
use crate::utils::{snippet_opt, span_lint, span_lint_and_sugg};
22
use rustc_errors::Applicability;
33
use rustc_hir::{Expr, ExprKind};
44
use rustc_lint::{LateContext, LateLintPass};
@@ -59,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
5959

6060
let msg = format!("use of `{}` with a `usize` casted to an `isize`", method);
6161
if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
62-
utils::span_lint_and_sugg(
62+
span_lint_and_sugg(
6363
cx,
6464
PTR_OFFSET_WITH_CAST,
6565
expr.span,
@@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
6969
Applicability::MachineApplicable,
7070
);
7171
} else {
72-
utils::span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
72+
span_lint(cx, PTR_OFFSET_WITH_CAST, expr.span, &msg);
7373
}
7474
}
7575
}
@@ -119,8 +119,8 @@ fn build_suggestion<'a, 'tcx>(
119119
receiver_expr: &Expr<'_>,
120120
cast_lhs_expr: &Expr<'_>,
121121
) -> Option<String> {
122-
let receiver = utils::snippet_opt(cx, receiver_expr.span)?;
123-
let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?;
122+
let receiver = snippet_opt(cx, receiver_expr.span)?;
123+
let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?;
124124
Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs))
125125
}
126126

clippy_lints/src/shadow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Shadow {
101101
}
102102

103103
fn check_fn<'a, 'tcx>(cx: &LateContext<'a, 'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Body<'_>) {
104-
let mut bindings = Vec::new();
104+
let mut bindings = Vec::with_capacity(decl.inputs.len());
105105
for arg in iter_input_pats(decl, body) {
106106
if let PatKind::Binding(.., ident, _) = arg.pat.kind {
107107
bindings.push((ident.name, ident.span))

clippy_lints/src/temporary_assignment.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use crate::utils::is_adjusted;
2-
use crate::utils::span_lint;
1+
use crate::utils::{is_adjusted, span_lint};
32
use rustc_hir::def::{DefKind, Res};
43
use rustc_hir::{Expr, ExprKind};
54
use rustc_lint::{LateContext, LateLintPass};

clippy_lints/src/utils/internal_lints.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,10 @@ use rustc_hir::def::{DefKind, Res};
1111
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
1212
use rustc_hir::*;
1313
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
14-
use rustc_session::declare_tool_lint;
15-
use rustc_session::{declare_lint_pass, impl_lint_pass};
14+
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1615
use rustc_span::source_map::{Span, Spanned};
1716
use rustc_span::symbol::SymbolStr;
18-
use syntax::ast;
19-
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name};
17+
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
2018
use syntax::visit::FnKind;
2119

2220
declare_clippy_lint! {
@@ -380,7 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass {
380378
declare_lint_pass!(ProduceIce => [PRODUCE_ICE]);
381379

382380
impl EarlyLintPass for ProduceIce {
383-
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: ast::NodeId) {
381+
fn check_fn(&mut self, _: &EarlyContext<'_>, fn_kind: FnKind<'_>, _: Span, _: NodeId) {
384382
if is_trigger_fn(fn_kind) {
385383
panic!("Would you like some help with that?");
386384
}

clippy_lints/src/utils/sugg.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ use rustc_span::{BytePos, Pos};
1212
use std::borrow::Cow;
1313
use std::convert::TryInto;
1414
use std::fmt::Display;
15-
use syntax::ast;
16-
use syntax::token;
1715
use syntax::util::parser::AssocOp;
16+
use syntax::{ast, token};
1817

1918
pub use crate::literal_representation::format_numeric_literal;
2019

0 commit comments

Comments
 (0)