Clean up imports

This commit is contained in:
Yuki Okushi
2020-02-18 22:28:18 +09:00
parent f4b80394d7
commit 06cb96ed72
10 changed files with 19 additions and 30 deletions

View File

@@ -5,7 +5,6 @@ use crate::utils::{
use if_chain::if_chain; use if_chain::if_chain;
use rustc::hir::map::Map; use rustc::hir::map::Map;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::intravisit;
use rustc_hir::intravisit::*; use rustc_hir::intravisit::*;
use rustc_hir::*; use rustc_hir::*;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@@ -60,7 +59,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for NonminimalBool {
fn check_fn( fn check_fn(
&mut self, &mut self,
cx: &LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,
_: intravisit::FnKind<'tcx>, _: FnKind<'tcx>,
_: &'tcx FnDecl<'_>, _: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>, body: &'tcx Body<'_>,
_: Span, _: Span,

View File

@@ -11,7 +11,6 @@ use rustc_hir::*;
use rustc_lint::LateContext; use rustc_lint::LateContext;
use rustc_span::symbol::Symbol; use rustc_span::symbol::Symbol;
use std::cmp::Ordering::{self, Equal}; use std::cmp::Ordering::{self, Equal};
use std::cmp::PartialOrd;
use std::convert::TryInto; use std::convert::TryInto;
use std::hash::{Hash, Hasher}; use std::hash::{Hash, Hasher};
use syntax::ast::{FloatTy, LitKind}; use syntax::ast::{FloatTy, LitKind};

View File

@@ -1,7 +1,6 @@
use rustc::ty::layout::LayoutOf; use rustc::ty::layout::LayoutOf;
use rustc::ty::{self, Ty}; use rustc::ty::{self, Ty};
use rustc_hir::intravisit as visit; use rustc_hir::intravisit;
use rustc_hir::HirIdSet;
use rustc_hir::{self, *}; use rustc_hir::{self, *};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@@ -54,7 +53,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for BoxedLocal {
fn check_fn( fn check_fn(
&mut self, &mut self,
cx: &LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,
_: visit::FnKind<'tcx>, _: intravisit::FnKind<'tcx>,
_: &'tcx FnDecl<'_>, _: &'tcx FnDecl<'_>,
body: &'tcx Body<'_>, body: &'tcx Body<'_>,
_: Span, _: Span,

View File

@@ -1,9 +1,7 @@
//! lint on indexing and slicing operations //! lint on indexing and slicing operations
use crate::consts::{constant, Constant}; use crate::consts::{constant, Constant};
use crate::utils; use crate::utils::{higher, span_lint, span_lint_and_help};
use crate::utils::higher;
use crate::utils::higher::Range;
use rustc::ty; use rustc::ty;
use rustc_hir::*; use rustc_hir::*;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
@@ -100,7 +98,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for IndexingSlicing {
if let (Some(start), _) = const_range { if let (Some(start), _) = const_range {
if start > size { if start > size {
utils::span_lint( span_lint(
cx, cx,
OUT_OF_BOUNDS_INDEXING, OUT_OF_BOUNDS_INDEXING,
range.start.map_or(expr.span, |start| start.span), 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 let (_, Some(end)) = const_range {
if end > size { if end > size {
utils::span_lint( span_lint(
cx, cx,
OUT_OF_BOUNDS_INDEXING, OUT_OF_BOUNDS_INDEXING,
range.end.map_or(expr.span, |end| end.span), 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. (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 { } else {
// Catchall non-range index, i.e., [n] or [n << m] // Catchall non-range index, i.e., [n] or [n << m]
if let ty::Array(..) = ty.kind { 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, cx,
INDEXING_SLICING, INDEXING_SLICING,
expr.span, 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. /// the range. If the start or end is not constant, None is returned.
fn to_const_range<'a, 'tcx>( fn to_const_range<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>, cx: &LateContext<'a, 'tcx>,
range: Range<'_>, range: higher::Range<'_>,
array_size: u128, array_size: u128,
) -> (Option<u128>, Option<u128>) { ) -> (Option<u128>, Option<u128>) {
let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c)); let s = range.start.map(|expr| constant(cx, cx.tables, expr).map(|(c, _)| c));

View File

@@ -18,7 +18,6 @@ use rustc::ty::{self, Ty};
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::def::{DefKind, Res}; 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::intravisit::{walk_block, walk_expr, walk_pat, walk_stmt, NestedVisitorMap, Visitor};
use rustc_hir::*; use rustc_hir::*;
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;

View File

@@ -8,7 +8,6 @@ use crate::utils::{
use if_chain::if_chain; use if_chain::if_chain;
use rustc::ty; use rustc::ty;
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::QPath;
use rustc_hir::*; use rustc_hir::*;
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint}; use rustc_session::{declare_lint_pass, declare_tool_lint};

View File

@@ -1,4 +1,4 @@
use crate::utils; use crate::utils::{snippet_opt, span_lint, span_lint_and_sugg};
use rustc_errors::Applicability; use rustc_errors::Applicability;
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass}; 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); 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) { if let Some(sugg) = build_suggestion(cx, method, receiver_expr, cast_lhs_expr) {
utils::span_lint_and_sugg( span_lint_and_sugg(
cx, cx,
PTR_OFFSET_WITH_CAST, PTR_OFFSET_WITH_CAST,
expr.span, expr.span,
@@ -69,7 +69,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for PtrOffsetWithCast {
Applicability::MachineApplicable, Applicability::MachineApplicable,
); );
} else { } 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<'_>, receiver_expr: &Expr<'_>,
cast_lhs_expr: &Expr<'_>, cast_lhs_expr: &Expr<'_>,
) -> Option<String> { ) -> Option<String> {
let receiver = utils::snippet_opt(cx, receiver_expr.span)?; let receiver = snippet_opt(cx, receiver_expr.span)?;
let cast_lhs = utils::snippet_opt(cx, cast_lhs_expr.span)?; let cast_lhs = snippet_opt(cx, cast_lhs_expr.span)?;
Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs)) Some(format!("{}.{}({})", receiver, method.suggestion(), cast_lhs))
} }

View File

@@ -1,5 +1,4 @@
use crate::utils::is_adjusted; use crate::utils::{is_adjusted, span_lint};
use crate::utils::span_lint;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::{Expr, ExprKind}; use rustc_hir::{Expr, ExprKind};
use rustc_lint::{LateContext, LateLintPass}; use rustc_lint::{LateContext, LateLintPass};

View File

@@ -11,12 +11,10 @@ use rustc_hir::def::{DefKind, Res};
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor}; use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc_hir::*; use rustc_hir::*;
use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass}; use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
use rustc_session::declare_tool_lint; use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
use rustc_session::{declare_lint_pass, impl_lint_pass};
use rustc_span::source_map::{Span, Spanned}; use rustc_span::source_map::{Span, Spanned};
use rustc_span::symbol::SymbolStr; use rustc_span::symbol::SymbolStr;
use syntax::ast; use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
use syntax::ast::{Crate as AstCrate, ItemKind, LitKind, Name};
use syntax::visit::FnKind; use syntax::visit::FnKind;
declare_clippy_lint! { declare_clippy_lint! {
@@ -380,7 +378,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for OuterExpnDataPass {
declare_lint_pass!(ProduceIce => [PRODUCE_ICE]); declare_lint_pass!(ProduceIce => [PRODUCE_ICE]);
impl EarlyLintPass for ProduceIce { 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) { if is_trigger_fn(fn_kind) {
panic!("Would you like some help with that?"); panic!("Would you like some help with that?");
} }

View File

@@ -12,9 +12,8 @@ use rustc_span::{BytePos, Pos};
use std::borrow::Cow; use std::borrow::Cow;
use std::convert::TryInto; use std::convert::TryInto;
use std::fmt::Display; use std::fmt::Display;
use syntax::ast;
use syntax::token;
use syntax::util::parser::AssocOp; use syntax::util::parser::AssocOp;
use syntax::{ast, token};
pub use crate::literal_representation::format_numeric_literal; pub use crate::literal_representation::format_numeric_literal;