Replace some Symbol::as_str usage (#14679)
Follow up to https://github.com/rust-lang/rust-clippy/pull/14650 Replaces uses in the form `s.as_str() == "literal"` r? @y21 changelog: none
This commit is contained in:
commit
0dd9722cdc
55 changed files with 448 additions and 179 deletions
|
|
@ -3,14 +3,14 @@
|
|||
#![deny(clippy::missing_docs_in_private_items)]
|
||||
|
||||
use crate::consts::{ConstEvalCtxt, Constant};
|
||||
use crate::is_expn_of;
|
||||
use crate::ty::is_type_diagnostic_item;
|
||||
use crate::{is_expn_of, sym};
|
||||
|
||||
use rustc_ast::ast;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::{Arm, Block, Expr, ExprKind, HirId, LoopSource, MatchSource, Node, Pat, QPath, StructTailExpr};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_span::{Span, sym, symbol};
|
||||
use rustc_span::{Span, symbol};
|
||||
|
||||
/// The essential nodes of a desugared for loop as well as the entire span:
|
||||
/// `for pat in arg { body }` becomes `(pat, arg, body)`. Returns `(pat, arg, body, span)`.
|
||||
|
|
@ -474,7 +474,7 @@ pub fn get_vec_init_kind<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) -
|
|||
return Some(VecInitKind::New);
|
||||
} else if name.ident.name == symbol::kw::Default {
|
||||
return Some(VecInitKind::Default);
|
||||
} else if name.ident.name.as_str() == "with_capacity" {
|
||||
} else if name.ident.name == sym::with_capacity {
|
||||
let arg = args.first()?;
|
||||
return match ConstEvalCtxt::new(cx).eval_simple(arg) {
|
||||
Some(Constant::Int(num)) => Some(VecInitKind::WithConstCapacity(num)),
|
||||
|
|
|
|||
|
|
@ -1412,7 +1412,7 @@ pub fn is_in_panic_handler(cx: &LateContext<'_>, e: &Expr<'_>) -> bool {
|
|||
}
|
||||
|
||||
/// Gets the name of the item the expression is in, if available.
|
||||
pub fn get_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Symbol> {
|
||||
pub fn parent_item_name(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<Symbol> {
|
||||
let parent_id = cx.tcx.hir_get_parent_item(expr.hir_id).def_id;
|
||||
match cx.tcx.hir_node_by_def_id(parent_id) {
|
||||
Node::Item(item) => item.kind.ident().map(|ident| ident.name),
|
||||
|
|
@ -2088,7 +2088,7 @@ pub fn match_libc_symbol(cx: &LateContext<'_>, did: DefId, name: &str) -> bool {
|
|||
let path = cx.get_def_path(did);
|
||||
// libc is meant to be used as a flat list of names, but they're all actually defined in different
|
||||
// modules based on the target platform. Ignore everything but crate name and the item name.
|
||||
path.first().is_some_and(|s| s.as_str() == "libc") && path.last().is_some_and(|s| s.as_str() == name)
|
||||
path.first().is_some_and(|s| *s == sym::libc) && path.last().is_some_and(|s| s.as_str() == name)
|
||||
}
|
||||
|
||||
/// Returns the list of condition expressions and the list of blocks in a
|
||||
|
|
|
|||
|
|
@ -30,33 +30,75 @@ macro_rules! generate {
|
|||
}
|
||||
|
||||
generate! {
|
||||
abs,
|
||||
as_bytes,
|
||||
as_deref_mut,
|
||||
as_deref,
|
||||
as_mut,
|
||||
Binary,
|
||||
build_hasher,
|
||||
cargo_clippy: "cargo-clippy",
|
||||
Cargo_toml: "Cargo.toml",
|
||||
cast,
|
||||
chars,
|
||||
CLIPPY_ARGS,
|
||||
CLIPPY_CONF_DIR,
|
||||
clone_into,
|
||||
cloned,
|
||||
collect,
|
||||
contains,
|
||||
copied,
|
||||
CRLF: "\r\n",
|
||||
Current,
|
||||
ends_with,
|
||||
exp,
|
||||
extend,
|
||||
finish_non_exhaustive,
|
||||
finish,
|
||||
flat_map,
|
||||
for_each,
|
||||
from_raw,
|
||||
from_str_radix,
|
||||
get,
|
||||
insert,
|
||||
int_roundings,
|
||||
into_bytes,
|
||||
into_owned,
|
||||
IntoIter,
|
||||
is_ascii,
|
||||
is_empty,
|
||||
is_err,
|
||||
is_none,
|
||||
is_ok,
|
||||
is_some,
|
||||
last,
|
||||
LF: "\n",
|
||||
LowerExp,
|
||||
LowerHex,
|
||||
max,
|
||||
min,
|
||||
mode,
|
||||
msrv,
|
||||
Octal,
|
||||
or_default,
|
||||
parse,
|
||||
push,
|
||||
regex,
|
||||
reserve,
|
||||
resize,
|
||||
restriction,
|
||||
rustfmt_skip,
|
||||
set_len,
|
||||
set_mode,
|
||||
set_readonly,
|
||||
signum,
|
||||
split_whitespace,
|
||||
split,
|
||||
Start,
|
||||
take,
|
||||
TBD,
|
||||
then_some,
|
||||
to_digit,
|
||||
to_owned,
|
||||
unused_extern_crates,
|
||||
unwrap_err,
|
||||
|
|
@ -66,4 +108,6 @@ generate! {
|
|||
V4,
|
||||
V6,
|
||||
Weak,
|
||||
with_capacity,
|
||||
wrapping_offset,
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue