mirror of https://github.com/rust-lang/rust.git
Remove unnecessary sigils around `Ident::as_str()` calls.
This commit is contained in:
parent
056d48a2c9
commit
b1c934ebb8
|
@ -580,8 +580,7 @@ impl<'a> AstValidator<'a> {
|
|||
|
||||
/// An item in `extern { ... }` cannot use non-ascii identifier.
|
||||
fn check_foreign_item_ascii_only(&self, ident: Ident) {
|
||||
let symbol_str = ident.as_str();
|
||||
if !symbol_str.is_ascii() {
|
||||
if !ident.as_str().is_ascii() {
|
||||
let n = 83942;
|
||||
self.err_handler()
|
||||
.struct_span_err(
|
||||
|
|
|
@ -1922,7 +1922,7 @@ enum VariantInfo<'a, 'tcx> {
|
|||
impl<'tcx> VariantInfo<'_, 'tcx> {
|
||||
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
|
||||
match self {
|
||||
VariantInfo::Adt(variant) => f(&variant.ident.as_str()),
|
||||
VariantInfo::Adt(variant) => f(variant.ident.as_str()),
|
||||
VariantInfo::Generator { variant_index, .. } => {
|
||||
f(&GeneratorSubsts::variant_name(*variant_index))
|
||||
}
|
||||
|
|
|
@ -103,10 +103,10 @@ crate fn mod_dir_path(
|
|||
if let DirOwnership::Owned { relative } = &mut dir_ownership {
|
||||
if let Some(ident) = relative.take() {
|
||||
// Remove the relative offset.
|
||||
dir_path.push(&*ident.as_str());
|
||||
dir_path.push(ident.as_str());
|
||||
}
|
||||
}
|
||||
dir_path.push(&*ident.as_str());
|
||||
dir_path.push(ident.as_str());
|
||||
|
||||
(dir_path, dir_ownership)
|
||||
}
|
||||
|
|
|
@ -2444,7 +2444,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
|
|||
CtorKind::Fictive => {
|
||||
let mut struct_fmt = fmt.debug_struct(&name);
|
||||
for (field, place) in iter::zip(&variant_def.fields, places) {
|
||||
struct_fmt.field(&field.ident.as_str(), place);
|
||||
struct_fmt.field(field.ident.as_str(), place);
|
||||
}
|
||||
struct_fmt.finish()
|
||||
}
|
||||
|
|
|
@ -1185,7 +1185,7 @@ impl<'a> Resolver<'a> {
|
|||
("", " from prelude")
|
||||
} else if b.is_extern_crate()
|
||||
&& !b.is_import()
|
||||
&& self.session.opts.externs.get(&ident.as_str()).is_some()
|
||||
&& self.session.opts.externs.get(ident.as_str()).is_some()
|
||||
{
|
||||
("", " passed with `--extern`")
|
||||
} else if add_built_in {
|
||||
|
|
|
@ -231,7 +231,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
|
||||
let is_assoc_fn = self.self_type_is_available(span);
|
||||
// Emit help message for fake-self from other languages (e.g., `this` in Javascript).
|
||||
if ["this", "my"].contains(&&*item_str.as_str()) && is_assoc_fn {
|
||||
if ["this", "my"].contains(&item_str.as_str()) && is_assoc_fn {
|
||||
err.span_suggestion_short(
|
||||
span,
|
||||
"you might have meant to use `self` here instead",
|
||||
|
@ -1372,7 +1372,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
|
|||
fn likely_rust_type(path: &[Segment]) -> Option<Symbol> {
|
||||
let name = path[path.len() - 1].ident.as_str();
|
||||
// Common Java types
|
||||
Some(match &*name {
|
||||
Some(match name {
|
||||
"byte" => sym::u8, // In Java, bytes are signed, but in practice one almost always wants unsigned bytes.
|
||||
"short" => sym::i16,
|
||||
"boolean" => sym::bool,
|
||||
|
|
|
@ -105,7 +105,7 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
|
|||
path_str.push_str("::");
|
||||
}
|
||||
if segment.ident.name != kw::PathRoot {
|
||||
path_str.push_str(&segment.ident.as_str())
|
||||
path_str.push_str(segment.ident.as_str())
|
||||
}
|
||||
}
|
||||
Symbol::intern(&path_str)
|
||||
|
|
|
@ -616,7 +616,7 @@ impl<'hir> Sig for hir::Generics<'hir> {
|
|||
if let hir::GenericParamKind::Const { .. } = param.kind {
|
||||
param_text.push_str("const ");
|
||||
}
|
||||
param_text.push_str(¶m.name.ident().as_str());
|
||||
param_text.push_str(param.name.ident().as_str());
|
||||
defs.push(SigElement {
|
||||
id: id_from_hir_id(param.hir_id, scx),
|
||||
start: offset + text.len(),
|
||||
|
|
|
@ -560,7 +560,7 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
|
|||
ty::ExistentialPredicate::Projection(projection) => {
|
||||
let name = cx.tcx.associated_item(projection.item_def_id).ident;
|
||||
cx.push("p");
|
||||
cx.push_ident(&name.as_str());
|
||||
cx.push_ident(name.as_str());
|
||||
cx = projection.ty.print(cx)?;
|
||||
}
|
||||
ty::ExistentialPredicate::AutoTrait(def_id) => {
|
||||
|
|
|
@ -1908,7 +1908,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
|||
.associated_items(def_id)
|
||||
.in_definition_order()
|
||||
.filter(|x| {
|
||||
let dist = lev_distance(&*name.as_str(), &x.ident.as_str());
|
||||
let dist = lev_distance(name.as_str(), x.ident.as_str());
|
||||
x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist
|
||||
})
|
||||
.copied()
|
||||
|
|
|
@ -167,7 +167,7 @@ crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {
|
|||
s.push_str("::");
|
||||
}
|
||||
if seg.ident.name != kw::PathRoot {
|
||||
s.push_str(&seg.ident.as_str());
|
||||
s.push_str(seg.ident.as_str());
|
||||
}
|
||||
}
|
||||
s
|
||||
|
|
|
@ -21,7 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
|
|||
|
||||
impl<'tcx> LateLintPass<'tcx> for Pass {
|
||||
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
|
||||
match &*it.ident.as_str() {
|
||||
match it.ident.as_str() {
|
||||
"lintme" => cx.lint(TEST_LINT, |lint| {
|
||||
lint.build("item is named 'lintme'").set_span(it.span).emit()
|
||||
}),
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -599,7 +599,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])
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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),
|
||||
_ => {}
|
||||
|
|
|
@ -1999,8 +1999,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);
|
||||
|
|
|
@ -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;
|
||||
},
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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));
|
||||
},
|
||||
|
|
|
@ -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),
|
||||
_ => {},
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -616,10 +616,10 @@ impl<'a> FmtVisitor<'a> {
|
|||
(TyAlias(lty), TyAlias(rty))
|
||||
if both_type(<y.ty, &rty.ty) || both_opaque(<y.ty, &rty.ty) =>
|
||||
{
|
||||
a.ident.as_str().cmp(&b.ident.as_str())
|
||||
a.ident.as_str().cmp(b.ident.as_str())
|
||||
}
|
||||
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
|
||||
a.ident.as_str().cmp(&b.ident.as_str())
|
||||
a.ident.as_str().cmp(b.ident.as_str())
|
||||
}
|
||||
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
|
||||
(TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less,
|
||||
|
@ -1029,7 +1029,7 @@ pub(crate) fn format_trait(
|
|||
if !bounds.is_empty() {
|
||||
let ident_hi = context
|
||||
.snippet_provider
|
||||
.span_after(item.span, &item.ident.as_str());
|
||||
.span_after(item.span, item.ident.as_str());
|
||||
let bound_hi = bounds.last().unwrap().span().hi();
|
||||
let snippet = context.snippet(mk_sp(ident_hi, bound_hi));
|
||||
if contains_comment(snippet) {
|
||||
|
|
|
@ -467,10 +467,10 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
|
|||
if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership {
|
||||
if let Some(ident) = relative.take() {
|
||||
// remove the relative offset
|
||||
self.directory.path.push(&*ident.as_str());
|
||||
self.directory.path.push(ident.as_str());
|
||||
}
|
||||
}
|
||||
self.directory.path.push(&*id.as_str());
|
||||
self.directory.path.push(id.as_str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ use crate::visitor::FmtVisitor;
|
|||
fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
|
||||
match (&a.kind, &b.kind) {
|
||||
(&ast::ItemKind::Mod(..), &ast::ItemKind::Mod(..)) => {
|
||||
a.ident.as_str().cmp(&b.ident.as_str())
|
||||
a.ident.as_str().cmp(b.ident.as_str())
|
||||
}
|
||||
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
|
||||
// `extern crate foo as bar;`
|
||||
|
@ -44,7 +44,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
|
|||
(Some(..), None) => Ordering::Greater,
|
||||
(None, Some(..)) => Ordering::Less,
|
||||
(None, None) => Ordering::Equal,
|
||||
(Some(..), Some(..)) => a.ident.as_str().cmp(&b.ident.as_str()),
|
||||
(Some(..), Some(..)) => a.ident.as_str().cmp(b.ident.as_str()),
|
||||
}
|
||||
}
|
||||
_ => unreachable!(),
|
||||
|
|
Loading…
Reference in New Issue