Skip to content

Commit

Permalink
Fix clippy.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot authored and flip1995 committed May 11, 2020
1 parent 01662d3 commit 8ab3224
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 31 deletions.
7 changes: 4 additions & 3 deletions clippy_lints/src/bytecount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ use crate::utils::{
span_lint_and_sugg, walk_ptrs_ty,
};
use if_chain::if_chain;
use rustc_ast::ast::{Name, UintTy};
use rustc_ast::ast::{UintTy};
use rustc_errors::Applicability;
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::Symbol;

declare_clippy_lint! {
/// **What it does:** Checks for naive byte counts
Expand Down Expand Up @@ -95,11 +96,11 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for ByteCount {
}
}

fn check_arg(name: Name, arg: Name, needle: &Expr<'_>) -> bool {
fn check_arg(name: Symbol, arg: Symbol, needle: &Expr<'_>) -> bool {
name == arg && !contains_name(name, needle)
}

fn get_path_name(expr: &Expr<'_>) -> Option<Name> {
fn get_path_name(expr: &Expr<'_>) -> Option<Symbol> {
match expr.kind {
ExprKind::Box(ref e) | ExprKind::AddrOf(BorrowKind::Ref, _, ref e) | ExprKind::Unary(UnOp::UnDeref, ref e) => {
get_path_name(e)
Expand Down
5 changes: 3 additions & 2 deletions clippy_lints/src/inline_fn_without_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@
use crate::utils::span_lint_and_then;
use crate::utils::sugg::DiagnosticBuilderExt;
use rustc_ast::ast::{Attribute, Name};
use rustc_ast::ast::Attribute;
use rustc_errors::Applicability;
use rustc_hir::{TraitFn, TraitItem, TraitItemKind};
use rustc_lint::{LateContext, LateLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::Symbol;

declare_clippy_lint! {
/// **What it does:** Checks for `#[inline]` on trait methods without bodies
Expand Down Expand Up @@ -38,7 +39,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for InlineFnWithoutBody {
}
}

fn check_attrs(cx: &LateContext<'_, '_>, name: Name, attrs: &[Attribute]) {
fn check_attrs(cx: &LateContext<'_, '_>, name: Symbol, attrs: &[Attribute]) {
for attr in attrs {
if !attr.check_name(sym!(inline)) {
continue;
Expand Down
6 changes: 3 additions & 3 deletions clippy_lints/src/len_zero.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::utils::{get_item_name, snippet_with_applicability, span_lint, span_lint_and_sugg, walk_ptrs_ty};
use rustc_ast::ast::{LitKind, Name};
use rustc_ast::ast::LitKind;
use rustc_data_structures::fx::FxHashSet;
use rustc_errors::Applicability;
use rustc_hir::def_id::DefId;
use rustc_hir::{AssocItemKind, BinOpKind, Expr, ExprKind, ImplItemRef, Item, ItemKind, TraitItemRef};
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::{Span, Spanned};
use rustc_span::source_map::{Span, Spanned, Symbol};

declare_clippy_lint! {
/// **What it does:** Checks for getting the length of something via `.len()`
Expand Down Expand Up @@ -226,7 +226,7 @@ fn check_cmp(cx: &LateContext<'_, '_>, span: Span, method: &Expr<'_>, lit: &Expr
fn check_len(
cx: &LateContext<'_, '_>,
span: Span,
method_name: Name,
method_name: Symbol,
args: &[Expr<'_>],
lit: &LitKind,
op: &str,
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ mod zero_div_zero;
pub use crate::utils::conf::Conf;

mod reexport {
pub use rustc_ast::ast::Name;
pub use rustc_span::Symbol as Name;
}

/// Register all pre expansion lints
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/map_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ use crate::utils::{
is_copy, is_type_diagnostic_item, match_trait_method, remove_blocks, snippet_with_applicability, span_lint_and_sugg,
};
use if_chain::if_chain;
use rustc_ast::ast::Ident;
use rustc_errors::Applicability;
use rustc_hir as hir;
use rustc_lint::{LateContext, LateLintPass};
use rustc_middle::mir::Mutability;
use rustc_middle::ty;
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::Span;
use rustc_span::symbol::Ident;

declare_clippy_lint! {
/// **What it does:** Checks for usage of `iterator.map(|x| x.clone())` and suggests
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/non_expressive_names.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
use crate::utils::{span_lint, span_lint_and_then};
use rustc_ast::ast::{
Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Ident, Item, ItemKind, Local, MacCall, Pat, PatKind,
Arm, AssocItem, AssocItemKind, Attribute, Block, FnDecl, Item, ItemKind, Local, MacCall, Pat, PatKind,
};
use rustc_ast::attr;
use rustc_ast::visit::{walk_block, walk_expr, walk_pat, Visitor};
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::source_map::Span;
use rustc_span::symbol::SymbolStr;
use rustc_span::symbol::{Ident, SymbolStr};
use std::cmp::Ordering;

declare_clippy_lint! {
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/unsafe_removed_from_name.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use crate::utils::span_lint;
use rustc_ast::ast::{Ident, Item, ItemKind, UseTree, UseTreeKind};
use rustc_ast::ast::{Item, ItemKind, UseTree, UseTreeKind};
use rustc_lint::{EarlyContext, EarlyLintPass};
use rustc_session::{declare_lint_pass, declare_tool_lint};
use rustc_span::source_map::Span;
use rustc_span::symbol::SymbolStr;
use rustc_span::symbol::{Ident, SymbolStr};

declare_clippy_lint! {
/// **What it does:** Checks for imports that remove "unsafe" from an item's
Expand Down
4 changes: 2 additions & 2 deletions clippy_lints/src/utils/hir_utils.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use crate::consts::{constant_context, constant_simple};
use crate::utils::differing_macro_contexts;
use rustc_ast::ast::Name;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
use rustc_hir::{
BinOpKind, Block, BlockCheckMode, BodyId, BorrowKind, CaptureBy, Expr, ExprKind, Field, FnRetTy, GenericArg,
Expand All @@ -10,6 +9,7 @@ use rustc_hir::{
use rustc_lint::LateContext;
use rustc_middle::ich::StableHashingContextProvider;
use rustc_middle::ty::TypeckTables;
use rustc_span::Symbol;
use std::hash::Hash;

/// Type used to check whether two ast are the same. This is different from the
Expand Down Expand Up @@ -544,7 +544,7 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> {
}
}

pub fn hash_name(&mut self, n: Name) {
pub fn hash_name(&mut self, n: Symbol) {
n.as_str().hash(&mut self.s);
}

Expand Down
10 changes: 5 additions & 5 deletions clippy_lints/src/utils/internal_lints.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::utils::{
span_lint_and_help, span_lint_and_sugg, walk_ptrs_ty,
};
use if_chain::if_chain;
use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, Name, NodeId};
use rustc_ast::ast::{Crate as AstCrate, ItemKind, LitKind, NodeId};
use rustc_ast::visit::FnKind;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_errors::Applicability;
Expand All @@ -17,7 +17,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass, LateContext, LateLintPass};
use rustc_middle::hir::map::Map;
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 rustc_span::symbol::{Symbol, SymbolStr};

use std::borrow::{Borrow, Cow};

Expand Down Expand Up @@ -245,8 +245,8 @@ impl EarlyLintPass for ClippyLintsInternal {

#[derive(Clone, Debug, Default)]
pub struct LintWithoutLintPass {
declared_lints: FxHashMap<Name, Span>,
registered_lints: FxHashSet<Name>,
declared_lints: FxHashMap<Symbol, Span>,
registered_lints: FxHashSet<Symbol>,
}

impl_lint_pass!(LintWithoutLintPass => [DEFAULT_LINT, LINT_WITHOUT_LINT_PASS]);
Expand Down Expand Up @@ -357,7 +357,7 @@ fn is_lint_ref_type<'tcx>(cx: &LateContext<'_, 'tcx>, ty: &Ty<'_>) -> bool {
}

struct LintCollector<'a, 'tcx> {
output: &'a mut FxHashSet<Name>,
output: &'a mut FxHashSet<Symbol>,
cx: &'a LateContext<'a, 'tcx>,
}

Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@ pub fn is_allowed(cx: &LateContext<'_, '_>, lint: &'static Lint, id: HirId) -> b
cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow
}

pub fn get_arg_name(pat: &Pat<'_>) -> Option<ast::Name> {
pub fn get_arg_name(pat: &Pat<'_>) -> Option<Name> {
match pat.kind {
PatKind::Binding(.., ident, None) => Some(ident.name),
PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
Expand Down
9 changes: 4 additions & 5 deletions clippy_lints/src/utils/ptr.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
use crate::utils::{get_pat_name, match_var, snippet};
use rustc_ast::ast::Name;
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
use rustc_hir::{Body, BodyId, Expr, ExprKind, Param};
use rustc_lint::LateContext;
use rustc_middle::hir::map::Map;
use rustc_span::source_map::Span;
use rustc_span::{Span, Symbol};
use std::borrow::Cow;

pub fn get_spans(
Expand All @@ -25,7 +24,7 @@ pub fn get_spans(

fn extract_clone_suggestions<'a, 'tcx>(
cx: &LateContext<'a, 'tcx>,
name: Name,
name: Symbol,
replace: &[(&'static str, &'static str)],
body: &'tcx Body<'_>,
) -> Option<Vec<(Span, Cow<'static, str>)>> {
Expand All @@ -46,7 +45,7 @@ fn extract_clone_suggestions<'a, 'tcx>(

struct PtrCloneVisitor<'a, 'tcx> {
cx: &'a LateContext<'a, 'tcx>,
name: Name,
name: Symbol,
replace: &'a [(&'static str, &'static str)],
spans: Vec<(Span, Cow<'static, str>)>,
abort: bool,
Expand Down Expand Up @@ -83,6 +82,6 @@ impl<'a, 'tcx> Visitor<'tcx> for PtrCloneVisitor<'a, 'tcx> {
}
}

fn get_binding_name(arg: &Param<'_>) -> Option<Name> {
fn get_binding_name(arg: &Param<'_>) -> Option<Symbol> {
get_pat_name(&arg.pat)
}
5 changes: 2 additions & 3 deletions clippy_lints/src/utils/usage.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use crate::utils::match_var;
use rustc_ast::ast;
use rustc_data_structures::fx::FxHashSet;
use rustc_hir::def::Res;
use rustc_hir::intravisit::{walk_expr, NestedVisitorMap, Visitor};
Expand All @@ -8,7 +7,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_lint::LateContext;
use rustc_middle::hir::map::Map;
use rustc_middle::ty;
use rustc_span::symbol::Ident;
use rustc_span::symbol::{Ident, Symbol};
use rustc_typeck::expr_use_visitor::{ConsumeMode, Delegate, ExprUseVisitor, Place, PlaceBase};

/// Returns a set of mutated local variable IDs, or `None` if mutations could not be determined.
Expand Down Expand Up @@ -78,7 +77,7 @@ impl<'tcx> Delegate<'tcx> for MutVarsDelegate {
}

pub struct UsedVisitor {
pub var: ast::Name, // var to look for
pub var: Symbol, // var to look for
pub used: bool, // has the var been used otherwise?
}

Expand Down

0 comments on commit 8ab3224

Please sign in to comment.