mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-12 14:22:45 +00:00
Rollup merge of #5856 - phansch:remove-symbol-reexport, r=flip1995
Remove old Symbol reexport I couldn't really tell what it was meant to improve. It seems more clear without the renaming to `Name`? changelog: none
This commit is contained in:
commit
fb7ad956f6
6 changed files with 28 additions and 36 deletions
|
@ -1,6 +1,5 @@
|
||||||
//! checks for attributes
|
//! checks for attributes
|
||||||
|
|
||||||
use crate::reexport::Name;
|
|
||||||
use crate::utils::{
|
use crate::utils::{
|
||||||
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_help,
|
first_line_of_span, is_present_in_source, match_def_path, paths, snippet_opt, span_lint, span_lint_and_help,
|
||||||
span_lint_and_sugg, span_lint_and_then, without_block_comments,
|
span_lint_and_sugg, span_lint_and_then, without_block_comments,
|
||||||
|
@ -517,7 +516,7 @@ fn is_relevant_expr(cx: &LateContext<'_>, typeck_results: &ty::TypeckResults<'_>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_attrs(cx: &LateContext<'_>, span: Span, name: Name, attrs: &[Attribute]) {
|
fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribute]) {
|
||||||
if span.from_expansion() {
|
if span.from_expansion() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -322,10 +322,6 @@ mod zero_div_zero;
|
||||||
|
|
||||||
pub use crate::utils::conf::Conf;
|
pub use crate::utils::conf::Conf;
|
||||||
|
|
||||||
mod reexport {
|
|
||||||
pub use rustc_span::Symbol as Name;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Register all pre expansion lints
|
/// Register all pre expansion lints
|
||||||
///
|
///
|
||||||
/// Pre-expansion lints run before any macro expansion has happened.
|
/// Pre-expansion lints run before any macro expansion has happened.
|
||||||
|
|
|
@ -13,9 +13,8 @@ use rustc_lint::{LateContext, LateLintPass};
|
||||||
use rustc_middle::hir::map::Map;
|
use rustc_middle::hir::map::Map;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
use rustc_span::symbol::kw;
|
use rustc_span::symbol::{kw, Symbol};
|
||||||
|
|
||||||
use crate::reexport::Name;
|
|
||||||
use crate::utils::{in_macro, last_path_segment, span_lint, trait_ref_of_method};
|
use crate::utils::{in_macro, last_path_segment, span_lint, trait_ref_of_method};
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
|
@ -113,7 +112,7 @@ impl<'tcx> LateLintPass<'tcx> for Lifetimes {
|
||||||
enum RefLt {
|
enum RefLt {
|
||||||
Unnamed,
|
Unnamed,
|
||||||
Static,
|
Static,
|
||||||
Named(Name),
|
Named(Symbol),
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_fn_inner<'tcx>(
|
fn check_fn_inner<'tcx>(
|
||||||
|
@ -456,7 +455,7 @@ fn has_where_lifetimes<'tcx>(cx: &LateContext<'tcx>, where_clause: &'tcx WhereCl
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LifetimeChecker {
|
struct LifetimeChecker {
|
||||||
map: FxHashMap<Name, Span>,
|
map: FxHashMap<Symbol, Span>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for LifetimeChecker {
|
impl<'tcx> Visitor<'tcx> for LifetimeChecker {
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use crate::consts::constant;
|
use crate::consts::constant;
|
||||||
use crate::reexport::Name;
|
|
||||||
use crate::utils::paths;
|
use crate::utils::paths;
|
||||||
use crate::utils::sugg::Sugg;
|
use crate::utils::sugg::Sugg;
|
||||||
use crate::utils::usage::{is_unused, mutated_variables};
|
use crate::utils::usage::{is_unused, mutated_variables};
|
||||||
|
@ -1184,7 +1183,7 @@ fn check_for_loop_range<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_len_call(expr: &Expr<'_>, var: Name) -> bool {
|
fn is_len_call(expr: &Expr<'_>, var: Symbol) -> bool {
|
||||||
if_chain! {
|
if_chain! {
|
||||||
if let ExprKind::MethodCall(ref method, _, ref len_args, _) = expr.kind;
|
if let ExprKind::MethodCall(ref method, _, ref len_args, _) = expr.kind;
|
||||||
if len_args.len() == 1;
|
if len_args.len() == 1;
|
||||||
|
@ -1640,15 +1639,15 @@ struct VarVisitor<'a, 'tcx> {
|
||||||
/// var name to look for as index
|
/// var name to look for as index
|
||||||
var: HirId,
|
var: HirId,
|
||||||
/// indexed variables that are used mutably
|
/// indexed variables that are used mutably
|
||||||
indexed_mut: FxHashSet<Name>,
|
indexed_mut: FxHashSet<Symbol>,
|
||||||
/// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global
|
/// indirectly indexed variables (`v[(i + 4) % N]`), the extend is `None` for global
|
||||||
indexed_indirectly: FxHashMap<Name, Option<region::Scope>>,
|
indexed_indirectly: FxHashMap<Symbol, Option<region::Scope>>,
|
||||||
/// subset of `indexed` of vars that are indexed directly: `v[i]`
|
/// subset of `indexed` of vars that are indexed directly: `v[i]`
|
||||||
/// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]`
|
/// this will not contain cases like `v[calc_index(i)]` or `v[(i + 4) % N]`
|
||||||
indexed_directly: FxHashMap<Name, (Option<region::Scope>, Ty<'tcx>)>,
|
indexed_directly: FxHashMap<Symbol, (Option<region::Scope>, Ty<'tcx>)>,
|
||||||
/// Any names that are used outside an index operation.
|
/// Any names that are used outside an index operation.
|
||||||
/// Used to detect things like `&mut vec` used together with `vec[i]`
|
/// Used to detect things like `&mut vec` used together with `vec[i]`
|
||||||
referenced: FxHashSet<Name>,
|
referenced: FxHashSet<Symbol>,
|
||||||
/// has the loop variable been used in expressions other than the index of
|
/// has the loop variable been used in expressions other than the index of
|
||||||
/// an index op?
|
/// an index op?
|
||||||
nonindex: bool,
|
nonindex: bool,
|
||||||
|
@ -2004,7 +2003,7 @@ struct InitializeVisitor<'a, 'tcx> {
|
||||||
end_expr: &'tcx Expr<'tcx>, // the for loop. Stop scanning here.
|
end_expr: &'tcx Expr<'tcx>, // the for loop. Stop scanning here.
|
||||||
var_id: HirId,
|
var_id: HirId,
|
||||||
state: VarState,
|
state: VarState,
|
||||||
name: Option<Name>,
|
name: Option<Symbol>,
|
||||||
depth: u32, // depth of conditional expressions
|
depth: u32, // depth of conditional expressions
|
||||||
past_loop: bool,
|
past_loop: bool,
|
||||||
}
|
}
|
||||||
|
@ -2167,7 +2166,7 @@ use self::Nesting::{LookFurther, RuledOut, Unknown};
|
||||||
|
|
||||||
struct LoopNestVisitor {
|
struct LoopNestVisitor {
|
||||||
hir_id: HirId,
|
hir_id: HirId,
|
||||||
iterator: Name,
|
iterator: Symbol,
|
||||||
nesting: Nesting,
|
nesting: Nesting,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2218,7 +2217,7 @@ impl<'tcx> Visitor<'tcx> for LoopNestVisitor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_name(e: &Expr<'_>) -> Option<Name> {
|
fn path_name(e: &Expr<'_>) -> Option<Symbol> {
|
||||||
if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.kind {
|
if let ExprKind::Path(QPath::Resolved(_, ref path)) = e.kind {
|
||||||
let segments = &path.segments;
|
let segments = &path.segments;
|
||||||
if segments.len() == 1 {
|
if segments.len() == 1 {
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use crate::reexport::Name;
|
|
||||||
use crate::utils::{contains_name, higher, iter_input_pats, snippet, span_lint_and_then};
|
use crate::utils::{contains_name, higher, iter_input_pats, snippet, span_lint_and_then};
|
||||||
use rustc_hir::intravisit::FnKind;
|
use rustc_hir::intravisit::FnKind;
|
||||||
use rustc_hir::{
|
use rustc_hir::{
|
||||||
|
@ -10,6 +9,7 @@ use rustc_middle::lint::in_external_macro;
|
||||||
use rustc_middle::ty;
|
use rustc_middle::ty;
|
||||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||||
use rustc_span::source_map::Span;
|
use rustc_span::source_map::Span;
|
||||||
|
use rustc_span::symbol::Symbol;
|
||||||
|
|
||||||
declare_clippy_lint! {
|
declare_clippy_lint! {
|
||||||
/// **What it does:** Checks for bindings that shadow other bindings already in
|
/// **What it does:** Checks for bindings that shadow other bindings already in
|
||||||
|
@ -123,7 +123,7 @@ fn check_fn<'tcx>(cx: &LateContext<'tcx>, decl: &'tcx FnDecl<'_>, body: &'tcx Bo
|
||||||
check_expr(cx, &body.value, &mut bindings);
|
check_expr(cx, &body.value, &mut bindings);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>, bindings: &mut Vec<(Name, Span)>) {
|
fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>, bindings: &mut Vec<(Symbol, Span)>) {
|
||||||
let len = bindings.len();
|
let len = bindings.len();
|
||||||
for stmt in block.stmts {
|
for stmt in block.stmts {
|
||||||
match stmt.kind {
|
match stmt.kind {
|
||||||
|
@ -138,7 +138,7 @@ fn check_block<'tcx>(cx: &LateContext<'tcx>, block: &'tcx Block<'_>, bindings: &
|
||||||
bindings.truncate(len);
|
bindings.truncate(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Name, Span)>) {
|
fn check_local<'tcx>(cx: &LateContext<'tcx>, local: &'tcx Local<'_>, bindings: &mut Vec<(Symbol, Span)>) {
|
||||||
if in_external_macro(cx.sess(), local.span) {
|
if in_external_macro(cx.sess(), local.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -173,7 +173,7 @@ fn check_pat<'tcx>(
|
||||||
pat: &'tcx Pat<'_>,
|
pat: &'tcx Pat<'_>,
|
||||||
init: Option<&'tcx Expr<'_>>,
|
init: Option<&'tcx Expr<'_>>,
|
||||||
span: Span,
|
span: Span,
|
||||||
bindings: &mut Vec<(Name, Span)>,
|
bindings: &mut Vec<(Symbol, Span)>,
|
||||||
) {
|
) {
|
||||||
// TODO: match more stuff / destructuring
|
// TODO: match more stuff / destructuring
|
||||||
match pat.kind {
|
match pat.kind {
|
||||||
|
@ -254,7 +254,7 @@ fn check_pat<'tcx>(
|
||||||
|
|
||||||
fn lint_shadow<'tcx>(
|
fn lint_shadow<'tcx>(
|
||||||
cx: &LateContext<'tcx>,
|
cx: &LateContext<'tcx>,
|
||||||
name: Name,
|
name: Symbol,
|
||||||
span: Span,
|
span: Span,
|
||||||
pattern_span: Span,
|
pattern_span: Span,
|
||||||
init: Option<&'tcx Expr<'_>>,
|
init: Option<&'tcx Expr<'_>>,
|
||||||
|
@ -315,7 +315,7 @@ fn lint_shadow<'tcx>(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut Vec<(Name, Span)>) {
|
fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut Vec<(Symbol, Span)>) {
|
||||||
if in_external_macro(cx.sess(), expr.span) {
|
if in_external_macro(cx.sess(), expr.span) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -351,7 +351,7 @@ fn check_expr<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, bindings: &mut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(Name, Span)>) {
|
fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(Symbol, Span)>) {
|
||||||
match ty.kind {
|
match ty.kind {
|
||||||
TyKind::Slice(ref sty) => check_ty(cx, sty, bindings),
|
TyKind::Slice(ref sty) => check_ty(cx, sty, bindings),
|
||||||
TyKind::Array(ref fty, ref anon_const) => {
|
TyKind::Array(ref fty, ref anon_const) => {
|
||||||
|
@ -371,7 +371,7 @@ fn check_ty<'tcx>(cx: &LateContext<'tcx>, ty: &'tcx Ty<'_>, bindings: &mut Vec<(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_self_shadow(name: Name, expr: &Expr<'_>) -> bool {
|
fn is_self_shadow(name: Symbol, expr: &Expr<'_>) -> bool {
|
||||||
match expr.kind {
|
match expr.kind {
|
||||||
ExprKind::Box(ref inner) | ExprKind::AddrOf(_, _, ref inner) => is_self_shadow(name, inner),
|
ExprKind::Box(ref inner) | ExprKind::AddrOf(_, _, ref inner) => is_self_shadow(name, inner),
|
||||||
ExprKind::Block(ref block, _) => {
|
ExprKind::Block(ref block, _) => {
|
||||||
|
@ -383,6 +383,6 @@ fn is_self_shadow(name: Name, expr: &Expr<'_>) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn path_eq_name(name: Name, path: &Path<'_>) -> bool {
|
fn path_eq_name(name: Symbol, path: &Path<'_>) -> bool {
|
||||||
!path.is_global() && path.segments.len() == 1 && path.segments[0].ident.as_str() == name.as_str()
|
!path.is_global() && path.segments.len() == 1 && path.segments[0].ident.as_str() == name.as_str()
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,7 +52,6 @@ use rustc_trait_selection::traits::query::normalize::AtExt;
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
|
|
||||||
use crate::consts::{constant, Constant};
|
use crate::consts::{constant, Constant};
|
||||||
use crate::reexport::Name;
|
|
||||||
|
|
||||||
/// Returns `true` if the two spans come from differing expansions (i.e., one is
|
/// Returns `true` if the two spans come from differing expansions (i.e., one is
|
||||||
/// from a macro and one isn't).
|
/// from a macro and one isn't).
|
||||||
|
@ -150,7 +149,7 @@ pub fn match_trait_method(cx: &LateContext<'_>, expr: &Expr<'_>, path: &[&str])
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if an expression references a variable of the given name.
|
/// Checks if an expression references a variable of the given name.
|
||||||
pub fn match_var(expr: &Expr<'_>, var: Name) -> bool {
|
pub fn match_var(expr: &Expr<'_>, var: Symbol) -> bool {
|
||||||
if let ExprKind::Path(QPath::Resolved(None, ref path)) = expr.kind {
|
if let ExprKind::Path(QPath::Resolved(None, ref path)) = expr.kind {
|
||||||
if let [p] = path.segments {
|
if let [p] = path.segments {
|
||||||
return p.ident.name == var;
|
return p.ident.name == var;
|
||||||
|
@ -420,7 +419,7 @@ pub fn is_entrypoint_fn(cx: &LateContext<'_>, def_id: DefId) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the name of the item the expression is in, if available.
|
/// Gets the name of the item the expression is in, if available.
|
||||||
pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Name> {
|
pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Symbol> {
|
||||||
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
|
let parent_id = cx.tcx.hir().get_parent_item(expr.hir_id);
|
||||||
match cx.tcx.hir().find(parent_id) {
|
match cx.tcx.hir().find(parent_id) {
|
||||||
Some(
|
Some(
|
||||||
|
@ -433,7 +432,7 @@ pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Name> {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Gets the name of a `Pat`, if any.
|
/// Gets the name of a `Pat`, if any.
|
||||||
pub fn get_pat_name(pat: &Pat<'_>) -> Option<Name> {
|
pub fn get_pat_name(pat: &Pat<'_>) -> Option<Symbol> {
|
||||||
match pat.kind {
|
match pat.kind {
|
||||||
PatKind::Binding(.., ref spname, _) => Some(spname.name),
|
PatKind::Binding(.., ref spname, _) => Some(spname.name),
|
||||||
PatKind::Path(ref qpath) => single_segment_path(qpath).map(|ps| ps.ident.name),
|
PatKind::Path(ref qpath) => single_segment_path(qpath).map(|ps| ps.ident.name),
|
||||||
|
@ -443,14 +442,14 @@ pub fn get_pat_name(pat: &Pat<'_>) -> Option<Name> {
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ContainsName {
|
struct ContainsName {
|
||||||
name: Name,
|
name: Symbol,
|
||||||
result: bool,
|
result: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> Visitor<'tcx> for ContainsName {
|
impl<'tcx> Visitor<'tcx> for ContainsName {
|
||||||
type Map = Map<'tcx>;
|
type Map = Map<'tcx>;
|
||||||
|
|
||||||
fn visit_name(&mut self, _: Span, name: Name) {
|
fn visit_name(&mut self, _: Span, name: Symbol) {
|
||||||
if self.name == name {
|
if self.name == name {
|
||||||
self.result = true;
|
self.result = true;
|
||||||
}
|
}
|
||||||
|
@ -461,7 +460,7 @@ impl<'tcx> Visitor<'tcx> for ContainsName {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Checks if an `Expr` contains a certain name.
|
/// Checks if an `Expr` contains a certain name.
|
||||||
pub fn contains_name(name: Name, expr: &Expr<'_>) -> bool {
|
pub fn contains_name(name: Symbol, expr: &Expr<'_>) -> bool {
|
||||||
let mut cn = ContainsName { name, result: false };
|
let mut cn = ContainsName { name, result: false };
|
||||||
cn.visit_expr(expr);
|
cn.visit_expr(expr);
|
||||||
cn.result
|
cn.result
|
||||||
|
@ -1027,7 +1026,7 @@ pub fn is_allowed(cx: &LateContext<'_>, lint: &'static Lint, id: HirId) -> bool
|
||||||
cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow
|
cx.tcx.lint_level_at_node(lint, id).0 == Level::Allow
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_arg_name(pat: &Pat<'_>) -> Option<Name> {
|
pub fn get_arg_name(pat: &Pat<'_>) -> Option<Symbol> {
|
||||||
match pat.kind {
|
match pat.kind {
|
||||||
PatKind::Binding(.., ident, None) => Some(ident.name),
|
PatKind::Binding(.., ident, None) => Some(ident.name),
|
||||||
PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
|
PatKind::Ref(ref subpat, _) => get_arg_name(subpat),
|
||||||
|
|
Loading…
Reference in a new issue