mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-11-10 23:24:24 +00:00
Auto merge of #91957 - nnethercote:rm-SymbolStr, r=oli-obk
Remove `SymbolStr` This was originally proposed in https://github.com/rust-lang/rust/pull/74554#discussion_r466203544. As well as removing the icky `SymbolStr` type, it allows the removal of a lot of `&` and `*` occurrences. Best reviewed one commit at a time. r? `@oli-obk`
This commit is contained in:
commit
879eccead7
40 changed files with 77 additions and 75 deletions
|
@ -17,7 +17,7 @@ use rustc_semver::RustcVersion;
|
|||
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::source_map::Span;
|
||||
use rustc_span::sym;
|
||||
use rustc_span::symbol::{Symbol, SymbolStr};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use semver::Version;
|
||||
|
||||
static UNIX_SYSTEMS: &[&str] = &[
|
||||
|
@ -310,8 +310,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
|||
|| is_word(lint, sym::deprecated)
|
||||
|| is_word(lint, sym!(unreachable_pub))
|
||||
|| is_word(lint, sym!(unused))
|
||||
|| extract_clippy_lint(lint).map_or(false, |s| s == "wildcard_imports")
|
||||
|| extract_clippy_lint(lint).map_or(false, |s| s == "enum_glob_use")
|
||||
|| extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "wildcard_imports")
|
||||
|| extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "enum_glob_use")
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -370,7 +370,7 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
|
|||
}
|
||||
|
||||
/// Returns the lint name if it is clippy lint.
|
||||
fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
|
||||
fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
|
||||
if_chain! {
|
||||
if let Some(meta_item) = lint.meta_item();
|
||||
if meta_item.path.segments.len() > 1;
|
||||
|
@ -378,7 +378,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
|
|||
if tool_name.name == sym::clippy;
|
||||
then {
|
||||
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
|
||||
return Some(lint_name.as_str());
|
||||
return Some(lint_name);
|
||||
}
|
||||
}
|
||||
None
|
||||
|
@ -387,7 +387,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
|
|||
fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
|
||||
for lint in items {
|
||||
if let Some(lint_name) = extract_clippy_lint(lint) {
|
||||
if lint_name == "restriction" && name != sym::allow {
|
||||
if lint_name.as_str() == "restriction" && name != sym::allow {
|
||||
span_lint_and_help(
|
||||
cx,
|
||||
BLANKET_CLIPPY_RESTRICTION_LINTS,
|
||||
|
@ -486,7 +486,7 @@ fn check_attrs(cx: &LateContext<'_>, span: Span, name: Symbol, attrs: &[Attribut
|
|||
|
||||
fn check_semver(cx: &LateContext<'_>, span: Span, lit: &Lit) {
|
||||
if let LitKind::Str(is, _) = lit.kind {
|
||||
if Version::parse(&is.as_str()).is_ok() {
|
||||
if Version::parse(is.as_str()).is_ok() {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
@ -619,7 +619,7 @@ fn check_mismatched_target_os(cx: &EarlyContext<'_>, attr: &Attribute) {
|
|||
MetaItemKind::Word => {
|
||||
if_chain! {
|
||||
if let Some(ident) = meta.ident();
|
||||
if let Some(os) = find_os(&*ident.name.as_str());
|
||||
if let Some(os) = find_os(ident.name.as_str());
|
||||
then {
|
||||
mismatched.push((os, ident.span));
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ fn simplify_not(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option<String> {
|
|||
.copied()
|
||||
.flat_map(|(a, b)| vec![(a, b), (b, a)])
|
||||
.find(|&(a, _)| {
|
||||
let path: &str = &path.ident.name.as_str();
|
||||
let path: &str = path.ident.name.as_str();
|
||||
a == path
|
||||
})
|
||||
.and_then(|(_, neg_method)| Some(format!("{}.{}()", snippet_opt(cx, args[0].span)?, neg_method)))
|
||||
|
|
|
@ -321,8 +321,8 @@ fn get_implementing_type<'a>(path: &QPath<'_>, candidates: &'a [&str], function:
|
|||
if let TyKind::Path(QPath::Resolved(None, tp)) = &ty.kind;
|
||||
if let [int] = &*tp.segments;
|
||||
then {
|
||||
let name = &int.ident.name.as_str();
|
||||
candidates.iter().find(|c| name == *c).copied()
|
||||
let name = int.ident.name.as_str();
|
||||
candidates.iter().find(|c| &name == *c).copied()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
@ -335,8 +335,8 @@ fn int_ty_to_sym<'tcx>(path: &QPath<'_>) -> Option<&'tcx str> {
|
|||
if let QPath::Resolved(_, path) = *path;
|
||||
if let [ty] = &*path.segments;
|
||||
then {
|
||||
let name = &ty.ident.name.as_str();
|
||||
INTS.iter().find(|c| name == *c).copied()
|
||||
let name = ty.ident.name.as_str();
|
||||
INTS.iter().find(|c| &name == *c).copied()
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
@ -437,7 +437,7 @@ fn check_attrs<'a>(cx: &LateContext<'_>, valid_idents: &FxHashSet<String>, attrs
|
|||
|
||||
for attr in attrs {
|
||||
if let AttrKind::DocComment(comment_kind, comment) = attr.kind {
|
||||
let (comment, current_spans) = strip_doc_comment_decoration(&comment.as_str(), comment_kind, attr.span);
|
||||
let (comment, current_spans) = strip_doc_comment_decoration(comment.as_str(), comment_kind, attr.span);
|
||||
spans.extend_from_slice(¤t_spans);
|
||||
doc.push_str(&comment);
|
||||
} else if attr.has_name(sym::doc) {
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
|
|||
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION);
|
||||
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
|
||||
then {
|
||||
let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) {
|
||||
let suggested_fn = match (method_path.ident.as_str(), divisor) {
|
||||
("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis",
|
||||
("subsec_nanos", 1_000) => "subsec_micros",
|
||||
_ => return,
|
||||
|
|
|
@ -153,7 +153,7 @@ fn check_variant(
|
|||
);
|
||||
}
|
||||
}
|
||||
let first = &def.variants[0].ident.name.as_str();
|
||||
let first = def.variants[0].ident.name.as_str();
|
||||
let mut pre = &first[..str_utils::camel_case_until(&*first).byte_index];
|
||||
let mut post = &first[str_utils::camel_case_start(&*first).byte_index..];
|
||||
for var in def.variants {
|
||||
|
|
|
@ -68,7 +68,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
|
|||
if let LitKind::Float(sym, lit_float_ty) = lit.node;
|
||||
then {
|
||||
let sym_str = sym.as_str();
|
||||
let formatter = FloatFormat::new(&sym_str);
|
||||
let formatter = FloatFormat::new(sym_str);
|
||||
// Try to bail out if the float is for sure fine.
|
||||
// If its within the 2 decimal digits of being out of precision we
|
||||
// check if the parsed representation is the same as the string
|
||||
|
|
|
@ -595,7 +595,7 @@ fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>
|
|||
return method_name_a.as_str() == method_name_b.as_str() &&
|
||||
args_a.len() == args_b.len() &&
|
||||
(
|
||||
["ln", "log2", "log10"].contains(&&*method_name_a.as_str()) ||
|
||||
["ln", "log2", "log10"].contains(&method_name_a.as_str()) ||
|
||||
method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1])
|
||||
);
|
||||
}
|
||||
|
@ -692,7 +692,7 @@ impl<'tcx> LateLintPass<'tcx> for FloatingPointArithmetic {
|
|||
let recv_ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
|
||||
if recv_ty.is_floating_point() {
|
||||
match &*path.ident.name.as_str() {
|
||||
match path.ident.name.as_str() {
|
||||
"ln" => check_ln1p(cx, expr, args),
|
||||
"log" => check_log_base(cx, expr, args),
|
||||
"powf" => check_powf(cx, expr, args),
|
||||
|
|
|
@ -42,7 +42,7 @@ declare_lint_pass!(IterNotReturningIterator => [ITER_NOT_RETURNING_ITERATOR]);
|
|||
|
||||
impl LateLintPass<'_> for IterNotReturningIterator {
|
||||
fn check_impl_item(&mut self, cx: &LateContext<'tcx>, impl_item: &'tcx ImplItem<'tcx>) {
|
||||
let name: &str = &impl_item.ident.name.as_str();
|
||||
let name = impl_item.ident.name.as_str();
|
||||
if_chain! {
|
||||
if let ImplItemKind::Fn(fn_sig, _) = &impl_item.kind;
|
||||
let ret_ty = return_ty(cx, impl_item.hir_id());
|
||||
|
|
|
@ -659,7 +659,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
|
|||
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
|
||||
|
||||
if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind {
|
||||
let method_name = &*method.ident.as_str();
|
||||
let method_name = method.ident.as_str();
|
||||
// check for looping over x.iter() or x.iter_mut(), could use &x or &mut x
|
||||
match method_name {
|
||||
"iter" | "iter_mut" => explicit_iter_loop::check(cx, self_arg, arg, method_name),
|
||||
|
|
|
@ -31,7 +31,7 @@ fn check_needless_collect_direct_usage<'tcx>(expr: &'tcx Expr<'_>, cx: &LateCont
|
|||
let ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
let mut applicability = Applicability::MaybeIncorrect;
|
||||
let is_empty_sugg = "next().is_none()".to_string();
|
||||
let method_name = &*method.ident.name.as_str();
|
||||
let method_name = method.ident.name.as_str();
|
||||
let sugg = if is_type_diagnostic_item(cx, ty, sym::Vec) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::VecDeque) ||
|
||||
is_type_diagnostic_item(cx, ty, sym::LinkedList) ||
|
||||
|
@ -210,7 +210,7 @@ impl<'tcx> Visitor<'tcx> for IterFunctionVisitor<'_, 'tcx> {
|
|||
if let Some(hir_id) = self.current_statement_hir_id {
|
||||
self.hir_id_uses_map.insert(hir_id, self.uses.len());
|
||||
}
|
||||
match &*method_name.ident.name.as_str() {
|
||||
match method_name.ident.name.as_str() {
|
||||
"into_iter" => self.uses.push(Some(IterFunction {
|
||||
func: IterFunctionKind::IntoIter,
|
||||
span: expr.span,
|
||||
|
|
|
@ -9,7 +9,7 @@ use rustc_middle::hir::map::Map;
|
|||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::symbol::SymbolStr;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, Span};
|
||||
|
||||
declare_clippy_lint! {
|
||||
|
@ -71,8 +71,8 @@ impl LateLintPass<'_> for MatchStrCaseMismatch {
|
|||
visitor.visit_expr(match_expr);
|
||||
|
||||
if let Some(case_method) = visitor.case_method {
|
||||
if let Some((bad_case_span, bad_case_str)) = verify_case(&case_method, arms) {
|
||||
lint(cx, &case_method, bad_case_span, &bad_case_str);
|
||||
if let Some((bad_case_span, bad_case_sym)) = verify_case(&case_method, arms) {
|
||||
lint(cx, &case_method, bad_case_span, bad_case_sym.as_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchExprVisitor<'a, 'tcx> {
|
|||
fn visit_expr(&mut self, ex: &'tcx Expr<'_>) {
|
||||
match ex.kind {
|
||||
ExprKind::MethodCall(segment, _, [receiver], _)
|
||||
if self.case_altered(&*segment.ident.as_str(), receiver) => {},
|
||||
if self.case_altered(segment.ident.as_str(), receiver) => {},
|
||||
_ => walk_expr(self, ex),
|
||||
}
|
||||
}
|
||||
|
@ -126,7 +126,7 @@ fn get_case_method(segment_ident_str: &str) -> Option<CaseMethod> {
|
|||
}
|
||||
}
|
||||
|
||||
fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, SymbolStr)> {
|
||||
fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, Symbol)> {
|
||||
let case_check = match case_method {
|
||||
CaseMethod::LowerCase => |input: &str| -> bool { input.chars().all(|c| c.to_lowercase().next() == Some(c)) },
|
||||
CaseMethod::AsciiLowerCase => |input: &str| -> bool { !input.chars().any(|c| c.is_ascii_uppercase()) },
|
||||
|
@ -144,7 +144,7 @@ fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(
|
|||
let input = symbol.as_str();
|
||||
if !case_check(&input);
|
||||
then {
|
||||
return Some((lit.span, input));
|
||||
return Some((lit.span, symbol));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -966,7 +966,7 @@ fn check_wild_err_arm<'tcx>(cx: &LateContext<'tcx>, ex: &Expr<'tcx>, arms: &[Arm
|
|||
for pat in inner.iter() {
|
||||
if let PatKind::Binding(_, id, ident, None) = pat.kind {
|
||||
if ident.as_str().starts_with('_') && !is_local_used(cx, arm.body, id) {
|
||||
ident_bind_name = (&ident.name.as_str()).to_string();
|
||||
ident_bind_name = ident.name.as_str().to_string();
|
||||
matching_wild = true;
|
||||
}
|
||||
}
|
||||
|
@ -1127,7 +1127,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
|
|||
if let CommonPrefixSearcher::Path(path_prefix) = path_prefix {
|
||||
let mut s = String::new();
|
||||
for seg in path_prefix {
|
||||
s.push_str(&seg.ident.as_str());
|
||||
s.push_str(seg.ident.as_str());
|
||||
s.push_str("::");
|
||||
}
|
||||
s
|
||||
|
|
|
@ -81,7 +81,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option<M
|
|||
if args.is_empty();
|
||||
if let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind;
|
||||
then {
|
||||
match &*segment.ident.as_str() {
|
||||
match segment.ident.as_str() {
|
||||
"max_value" => return Some(MinMax::Max),
|
||||
"min_value" => return Some(MinMax::Min),
|
||||
_ => {}
|
||||
|
|
|
@ -80,7 +80,7 @@ use rustc_middle::lint::in_external_macro;
|
|||
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_session::{declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::symbol::SymbolStr;
|
||||
use rustc_span::symbol::Symbol;
|
||||
use rustc_span::{sym, Span};
|
||||
use rustc_typeck::hir_ty_to_ty;
|
||||
|
||||
|
@ -1997,21 +1997,21 @@ impl_lint_pass!(Methods => [
|
|||
]);
|
||||
|
||||
/// Extracts a method call name, args, and `Span` of the method name.
|
||||
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(SymbolStr, &'tcx [hir::Expr<'tcx>], Span)> {
|
||||
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(Symbol, &'tcx [hir::Expr<'tcx>], Span)> {
|
||||
if let ExprKind::MethodCall(path, span, args, _) = recv.kind {
|
||||
if !args.iter().any(|e| e.span.from_expansion()) {
|
||||
return Some((path.ident.name.as_str(), args, span));
|
||||
return Some((path.ident.name, args, span));
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
/// Same as `method_call` but the `SymbolStr` is dereferenced into a temporary `&str`
|
||||
/// Same as `method_call` but the `Symbol` is dereferenced into a temporary `&str`
|
||||
macro_rules! method_call {
|
||||
($expr:expr) => {
|
||||
method_call($expr)
|
||||
.as_ref()
|
||||
.map(|&(ref name, args, span)| (&**name, args, span))
|
||||
.map(|&(ref name, args, span)| (name.as_str(), args, span))
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -2028,8 +2028,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
|||
from_iter_instead_of_collect::check(cx, expr, args, func);
|
||||
},
|
||||
hir::ExprKind::MethodCall(method_call, ref method_span, args, _) => {
|
||||
or_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args);
|
||||
expect_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args);
|
||||
or_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args);
|
||||
expect_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args);
|
||||
clone_on_copy::check(cx, expr, method_call.ident.name, args);
|
||||
clone_on_ref_ptr::check(cx, expr, method_call.ident.name, args);
|
||||
inefficient_to_string::check(cx, expr, method_call.ident.name, args);
|
||||
|
@ -2184,7 +2184,7 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
|
|||
let self_ty = TraitRef::identity(cx.tcx, item.def_id.to_def_id()).self_ty().skip_binder();
|
||||
wrong_self_convention::check(
|
||||
cx,
|
||||
&item.ident.name.as_str(),
|
||||
item.ident.name.as_str(),
|
||||
self_ty,
|
||||
first_arg_ty,
|
||||
first_arg_span,
|
||||
|
|
|
@ -140,7 +140,7 @@ fn parse_iter_usage(
|
|||
let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?;
|
||||
let iter_id = cx.tcx.get_diagnostic_item(sym::Iterator)?;
|
||||
|
||||
match (&*name.ident.as_str(), args) {
|
||||
match (name.ident.as_str(), args) {
|
||||
("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
|
||||
if reverse {
|
||||
(IterUsageKind::Second, e.span)
|
||||
|
@ -298,7 +298,7 @@ fn check_iter(
|
|||
if let Some(did) = cx.typeck_results().type_dependent_def_id(e.hir_id);
|
||||
if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator);
|
||||
then {
|
||||
match (&*name.ident.as_str(), args) {
|
||||
match (name.ident.as_str(), args) {
|
||||
("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
|
||||
return true;
|
||||
},
|
||||
|
|
|
@ -407,6 +407,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
|
|||
// Don't lint things expanded by #[derive(...)], etc or `await` desugaring
|
||||
return;
|
||||
}
|
||||
let sym;
|
||||
let binding = match expr.kind {
|
||||
ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => {
|
||||
let binding = last_path_segment(qpath).ident.as_str();
|
||||
|
@ -423,7 +424,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
|
|||
}
|
||||
},
|
||||
ExprKind::Field(_, ident) => {
|
||||
let name = ident.as_str();
|
||||
sym = ident.name;
|
||||
let name = sym.as_str();
|
||||
if name.starts_with('_') && !name.starts_with("__") {
|
||||
Some(name)
|
||||
} else {
|
||||
|
|
|
@ -75,7 +75,7 @@ impl LateLintPass<'_> for ImportRename {
|
|||
if let Some(import) = match snip.split_once(" as ") {
|
||||
None => Some(snip.as_str()),
|
||||
Some((import, rename)) => {
|
||||
if rename.trim() == &*name.as_str() {
|
||||
if rename.trim() == name.as_str() {
|
||||
None
|
||||
} else {
|
||||
Some(import.trim())
|
||||
|
|
|
@ -48,7 +48,7 @@ impl LateLintPass<'_> for MultipleCrateVersions {
|
|||
}
|
||||
|
||||
let metadata = unwrap_cargo_metadata!(cx, MULTIPLE_CRATE_VERSIONS, true);
|
||||
let local_name = cx.tcx.crate_name(LOCAL_CRATE).as_str();
|
||||
let local_name = cx.tcx.crate_name(LOCAL_CRATE);
|
||||
let mut packages = metadata.packages;
|
||||
packages.sort_by(|a, b| a.name.cmp(&b.name));
|
||||
|
||||
|
@ -56,7 +56,7 @@ impl LateLintPass<'_> for MultipleCrateVersions {
|
|||
if let Some(resolve) = &metadata.resolve;
|
||||
if let Some(local_id) = packages
|
||||
.iter()
|
||||
.find_map(|p| if p.name == *local_name { Some(&p.id) } else { None });
|
||||
.find_map(|p| if p.name == local_name.as_str() { Some(&p.id) } else { None });
|
||||
then {
|
||||
for (name, group) in &packages.iter().group_by(|p| p.name.clone()) {
|
||||
let group: Vec<&Package> = group.collect();
|
||||
|
|
|
@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
|
|||
let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap();
|
||||
let substs = cx.typeck_results().node_substs(e.hir_id);
|
||||
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
|
||||
check_arguments(cx, arguments, method_type, &path.ident.as_str(), "method");
|
||||
check_arguments(cx, arguments, method_type, path.ident.as_str(), "method");
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref {
|
|||
if is_type_diagnostic_item(cx,outer_ty,sym::Option);
|
||||
if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind;
|
||||
let symbol = path.ident.as_str();
|
||||
if symbol=="as_deref" || symbol=="as_deref_mut";
|
||||
if symbol == "as_deref" || symbol == "as_deref_mut";
|
||||
if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) );
|
||||
then{
|
||||
span_lint_and_sugg(
|
||||
|
|
|
@ -224,14 +224,14 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
|
|||
match existing_name.len.cmp(&count) {
|
||||
Ordering::Greater => {
|
||||
if existing_name.len - count != 1
|
||||
|| levenstein_not_1(&interned_name, &existing_name.interned.as_str())
|
||||
|| levenstein_not_1(&interned_name, existing_name.interned.as_str())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
},
|
||||
Ordering::Less => {
|
||||
if count - existing_name.len != 1
|
||||
|| levenstein_not_1(&existing_name.interned.as_str(), &interned_name)
|
||||
|| levenstein_not_1(existing_name.interned.as_str(), &interned_name)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -104,7 +104,7 @@ fn is_offending_macro<'a>(cx: &EarlyContext<'_>, span: Span, mac_braces: &'a Mac
|
|||
};
|
||||
if_chain! {
|
||||
if let ExpnKind::Macro(MacroKind::Bang, mac_name) = span.ctxt().outer_expn_data().kind;
|
||||
let name = &*mac_name.as_str();
|
||||
let name = mac_name.as_str();
|
||||
if let Some(braces) = mac_braces.macro_braces.get(name);
|
||||
if let Some(snip) = snippet_opt(cx, span.ctxt().outer_expn_data().call_site);
|
||||
// we must check only invocation sites
|
||||
|
|
|
@ -82,7 +82,7 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec
|
|||
_ => Argument::Unknown,
|
||||
};
|
||||
|
||||
match &*path.ident.as_str() {
|
||||
match path.ident.as_str() {
|
||||
"create" => {
|
||||
options.push((OpenOption::Create, argument_option));
|
||||
},
|
||||
|
|
|
@ -53,7 +53,7 @@ impl<'tcx> LateLintPass<'tcx> for PathBufPushOverwrite {
|
|||
if let Some(get_index_arg) = args.get(1);
|
||||
if let ExprKind::Lit(ref lit) = get_index_arg.kind;
|
||||
if let LitKind::Str(ref path_lit, _) = lit.node;
|
||||
if let pushed_path = Path::new(&*path_lit.as_str());
|
||||
if let pushed_path = Path::new(path_lit.as_str());
|
||||
if let Some(pushed_path_lit) = pushed_path.to_str();
|
||||
if pushed_path.has_root();
|
||||
if let Some(root) = pushed_path.components().next();
|
||||
|
|
|
@ -150,7 +150,7 @@ fn check_regex<'tcx>(cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>, utf8: bool) {
|
|||
|
||||
if let ExprKind::Lit(ref lit) = expr.kind {
|
||||
if let LitKind::Str(ref r, style) = lit.node {
|
||||
let r = &r.as_str();
|
||||
let r = r.as_str();
|
||||
let offset = if let StrStyle::Raw(n) = style { 2 + n } else { 1 };
|
||||
match parser.parse(r) {
|
||||
Ok(r) => {
|
||||
|
|
|
@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for SerdeApi {
|
|||
let mut seen_str = None;
|
||||
let mut seen_string = None;
|
||||
for item in items {
|
||||
match &*item.ident.as_str() {
|
||||
match item.ident.as_str() {
|
||||
"visit_str" => seen_str = Some(item.span),
|
||||
"visit_string" => seen_string = Some(item.span),
|
||||
_ => {},
|
||||
|
|
|
@ -89,7 +89,7 @@ fn detect_stable_sort_primitive(cx: &LateContext<'_>, expr: &Expr<'_>) -> Option
|
|||
if_chain! {
|
||||
if let ExprKind::MethodCall(method_name, _, args, _) = &expr.kind;
|
||||
if let Some(slice) = &args.get(0);
|
||||
if let Some(method) = SortingKind::from_stable_name(&method_name.ident.name.as_str());
|
||||
if let Some(method) = SortingKind::from_stable_name(method_name.ident.name.as_str());
|
||||
if let Some(slice_type) = is_slice_of_primitives(cx, slice);
|
||||
then {
|
||||
let args_str = args.iter().skip(1).map(|arg| Sugg::hir(cx, arg, "..").to_string()).collect::<Vec<String>>().join(", ");
|
||||
|
|
|
@ -327,7 +327,7 @@ impl<'tcx> LateLintPass<'tcx> for StringLitAsBytes {
|
|||
if let ExprKind::MethodCall(path, _, [recv], _) = &e.kind;
|
||||
if path.ident.name == sym!(into_bytes);
|
||||
if let ExprKind::MethodCall(path, _, [recv], _) = &recv.kind;
|
||||
if matches!(&*path.ident.name.as_str(), "to_owned" | "to_string");
|
||||
if matches!(path.ident.name.as_str(), "to_owned" | "to_string");
|
||||
if let ExprKind::Lit(lit) = &recv.kind;
|
||||
if let LitKind::Str(lit_content, _) = &lit.node;
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>) {
|
|||
if let ExprKind::Binary(ref cmp, left, _) = expr.kind {
|
||||
let op = cmp.node;
|
||||
if op.is_comparison() && cx.typeck_results().expr_ty(left).is_unit() {
|
||||
let result = match &*symbol.as_str() {
|
||||
let result = match symbol.as_str() {
|
||||
"assert_eq" | "debug_assert_eq" => "succeed",
|
||||
"assert_ne" | "debug_assert_ne" => "fail",
|
||||
_ => return,
|
||||
|
|
|
@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
|
|||
check_map_error(cx, res, expr);
|
||||
}
|
||||
},
|
||||
hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match &*path.ident.as_str() {
|
||||
hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match path.ident.as_str() {
|
||||
"expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => {
|
||||
check_map_error(cx, arg_0, expr);
|
||||
},
|
||||
|
@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
|
|||
fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
|
||||
let mut call = call;
|
||||
while let hir::ExprKind::MethodCall(path, _, args, _) = call.kind {
|
||||
if matches!(&*path.ident.as_str(), "or" | "or_else" | "ok") {
|
||||
if matches!(path.ident.as_str(), "or" | "or_else" | "ok") {
|
||||
call = &args[0];
|
||||
} else {
|
||||
break;
|
||||
|
@ -82,7 +82,7 @@ fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<
|
|||
|
||||
fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
|
||||
if let hir::ExprKind::MethodCall(path, _, _, _) = call.kind {
|
||||
let symbol = &*path.ident.as_str();
|
||||
let symbol = path.ident.as_str();
|
||||
let read_trait = match_trait_method(cx, call, &paths::IO_READ);
|
||||
let write_trait = match_trait_method(cx, call, &paths::IO_WRITE);
|
||||
|
||||
|
|
|
@ -94,7 +94,7 @@ impl EarlyLintPass for UnusedUnit {
|
|||
|
||||
if_chain! {
|
||||
if segments.len() == 1;
|
||||
if ["Fn", "FnMut", "FnOnce"].contains(&&*segments[0].ident.name.as_str());
|
||||
if ["Fn", "FnMut", "FnOnce"].contains(&segments[0].ident.name.as_str());
|
||||
if let Some(args) = &segments[0].args;
|
||||
if let ast::GenericArgs::Parenthesized(generic_args) = &**args;
|
||||
if let ast::FnRetTy::Ty(ty) = &generic_args.output;
|
||||
|
|
|
@ -158,7 +158,7 @@ fn collect_unwrap_info<'tcx>(
|
|||
if let Some(local_id) = path_to_local(&args[0]);
|
||||
let ty = cx.typeck_results().expr_ty(&args[0]);
|
||||
let name = method_name.ident.as_str();
|
||||
if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name);
|
||||
if is_relevant_option_call(cx, ty, name) || is_relevant_result_call(cx, ty, name);
|
||||
then {
|
||||
assert!(args.len() == 1);
|
||||
let unwrappable = match name.as_ref() {
|
||||
|
|
|
@ -79,7 +79,7 @@ fn correct_ident(ident: &str) -> String {
|
|||
|
||||
fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) {
|
||||
let span = ident.span;
|
||||
let ident = &ident.as_str();
|
||||
let ident = ident.as_str();
|
||||
let corrected = correct_ident(ident);
|
||||
// warn if we have pure-uppercase idents
|
||||
// assume that two-letter words are some kind of valid abbreviation like FP for false positive
|
||||
|
|
|
@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
|
|||
},
|
||||
|
||||
ExprKind::MethodCall(name, .., args, _) => {
|
||||
if is_trait_method(cx, e, sym::Into) && &*name.ident.as_str() == "into" {
|
||||
if is_trait_method(cx, e, sym::Into) && name.ident.as_str() == "into" {
|
||||
let a = cx.typeck_results().expr_ty(e);
|
||||
let b = cx.typeck_results().expr_ty(&args[0]);
|
||||
if same_type_and_consts(a, b) {
|
||||
|
|
|
@ -371,9 +371,9 @@ impl EarlyLintPass for Write {
|
|||
/// Return this and a boolean indicating whether it only consisted of a newline.
|
||||
fn newline_span(fmtstr: &StrLit) -> (Span, bool) {
|
||||
let sp = fmtstr.span;
|
||||
let contents = &fmtstr.symbol.as_str();
|
||||
let contents = fmtstr.symbol.as_str();
|
||||
|
||||
if *contents == r"\n" {
|
||||
if contents == r"\n" {
|
||||
return (sp, true);
|
||||
}
|
||||
|
||||
|
@ -484,7 +484,7 @@ impl Write {
|
|||
StrStyle::Raw(n) => Some(n as usize),
|
||||
};
|
||||
|
||||
let mut parser = Parser::new(&str_sym, style, snippet_opt(cx, str_lit.span), false, ParseMode::Format);
|
||||
let mut parser = Parser::new(str_sym, style, snippet_opt(cx, str_lit.span), false, ParseMode::Format);
|
||||
let mut args = SimpleFormatArgs::default();
|
||||
|
||||
while let Some(arg) = parser.next() {
|
||||
|
@ -589,7 +589,7 @@ impl Write {
|
|||
lit.token.symbol.as_str().replace('{', "{{").replace('}', "}}")
|
||||
},
|
||||
LitKind::StrRaw(_) | LitKind::Str | LitKind::ByteStrRaw(_) | LitKind::ByteStr => continue,
|
||||
LitKind::Byte | LitKind::Char => match &*lit.token.symbol.as_str() {
|
||||
LitKind::Byte | LitKind::Char => match lit.token.symbol.as_str() {
|
||||
"\"" if matches!(fmtstr.style, StrStyle::Cooked) => "\\\"",
|
||||
"\"" if matches!(fmtstr.style, StrStyle::Raw(0)) => continue,
|
||||
"\\\\" if matches!(fmtstr.style, StrStyle::Raw(_)) => "\\",
|
||||
|
@ -671,7 +671,7 @@ fn check_newlines(fmtstr: &StrLit) -> bool {
|
|||
let mut last_was_cr = false;
|
||||
let mut should_lint = false;
|
||||
|
||||
let contents = &fmtstr.symbol.as_str();
|
||||
let contents = fmtstr.symbol.as_str();
|
||||
|
||||
let mut cb = |r: Range<usize>, c: Result<char, EscapeError>| {
|
||||
let c = c.unwrap();
|
||||
|
|
|
@ -113,7 +113,7 @@ pub fn get_attr<'a>(
|
|||
fn parse_attrs<F: FnMut(u64)>(sess: &Session, attrs: &[ast::Attribute], name: &'static str, mut f: F) {
|
||||
for attr in get_attr(sess, attrs, name) {
|
||||
if let Some(ref value) = attr.value_str() {
|
||||
if let Ok(value) = FromStr::from_str(&value.as_str()) {
|
||||
if let Ok(value) = FromStr::from_str(value.as_str()) {
|
||||
f(value);
|
||||
} else {
|
||||
sess.span_err(attr.span, "not a number");
|
||||
|
|
|
@ -319,8 +319,8 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
|
|||
if let ExprKind::Path(qpath) = &callee.kind;
|
||||
let res = self.typeck_results.qpath_res(qpath, callee.hir_id);
|
||||
if let Some(def_id) = res.opt_def_id();
|
||||
let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect();
|
||||
let def_path: Vec<&str> = def_path.iter().take(4).map(|s| &**s).collect();
|
||||
let def_path = self.lcx.get_def_path(def_id);
|
||||
let def_path: Vec<&str> = def_path.iter().take(4).map(|s| s.as_str()).collect();
|
||||
if let ["core", "num", int_impl, "max_value"] = *def_path;
|
||||
then {
|
||||
let value = match int_impl {
|
||||
|
|
|
@ -47,7 +47,7 @@ impl ops::BitOrAssign for EagernessSuggestion {
|
|||
/// Determine the eagerness of the given function call.
|
||||
fn fn_eagerness(cx: &LateContext<'tcx>, fn_id: DefId, name: Symbol, args: &'tcx [Expr<'_>]) -> EagernessSuggestion {
|
||||
use EagernessSuggestion::{Eager, Lazy, NoChange};
|
||||
let name = &*name.as_str();
|
||||
let name = name.as_str();
|
||||
|
||||
let ty = match cx.tcx.impl_of_method(fn_id) {
|
||||
Some(id) => cx.tcx.type_of(id),
|
||||
|
|
|
@ -372,7 +372,7 @@ fn is_const_fn(tcx: TyCtxt<'_>, def_id: DefId, msrv: Option<&RustcVersion>) -> b
|
|||
// as a part of an unimplemented MSRV check https://github.com/rust-lang/rust/issues/65262.
|
||||
crate::meets_msrv(
|
||||
msrv,
|
||||
&RustcVersion::parse(&since.as_str())
|
||||
&RustcVersion::parse(since.as_str())
|
||||
.expect("`rustc_attr::StabilityLevel::Stable::since` is ill-formatted"),
|
||||
)
|
||||
} else {
|
||||
|
|
Loading…
Reference in a new issue