Skip to content

Commit b1c934e

Browse files
committed
Remove unnecessary sigils around Ident::as_str() calls.
1 parent 056d48a commit b1c934e

File tree

31 files changed

+41
-42
lines changed

31 files changed

+41
-42
lines changed

compiler/rustc_ast_passes/src/ast_validation.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -580,8 +580,7 @@ impl<'a> AstValidator<'a> {
580580

581581
/// An item in `extern { ... }` cannot use non-ascii identifier.
582582
fn check_foreign_item_ascii_only(&self, ident: Ident) {
583-
let symbol_str = ident.as_str();
584-
if !symbol_str.is_ascii() {
583+
if !ident.as_str().is_ascii() {
585584
let n = 83942;
586585
self.err_handler()
587586
.struct_span_err(

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ enum VariantInfo<'a, 'tcx> {
19221922
impl<'tcx> VariantInfo<'_, 'tcx> {
19231923
fn map_struct_name<R>(&self, f: impl FnOnce(&str) -> R) -> R {
19241924
match self {
1925-
VariantInfo::Adt(variant) => f(&variant.ident.as_str()),
1925+
VariantInfo::Adt(variant) => f(variant.ident.as_str()),
19261926
VariantInfo::Generator { variant_index, .. } => {
19271927
f(&GeneratorSubsts::variant_name(*variant_index))
19281928
}

compiler/rustc_expand/src/module.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -103,10 +103,10 @@ crate fn mod_dir_path(
103103
if let DirOwnership::Owned { relative } = &mut dir_ownership {
104104
if let Some(ident) = relative.take() {
105105
// Remove the relative offset.
106-
dir_path.push(&*ident.as_str());
106+
dir_path.push(ident.as_str());
107107
}
108108
}
109-
dir_path.push(&*ident.as_str());
109+
dir_path.push(ident.as_str());
110110

111111
(dir_path, dir_ownership)
112112
}

compiler/rustc_middle/src/mir/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2444,7 +2444,7 @@ impl<'tcx> Debug for Rvalue<'tcx> {
24442444
CtorKind::Fictive => {
24452445
let mut struct_fmt = fmt.debug_struct(&name);
24462446
for (field, place) in iter::zip(&variant_def.fields, places) {
2447-
struct_fmt.field(&field.ident.as_str(), place);
2447+
struct_fmt.field(field.ident.as_str(), place);
24482448
}
24492449
struct_fmt.finish()
24502450
}

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ impl<'a> Resolver<'a> {
11851185
("", " from prelude")
11861186
} else if b.is_extern_crate()
11871187
&& !b.is_import()
1188-
&& self.session.opts.externs.get(&ident.as_str()).is_some()
1188+
&& self.session.opts.externs.get(ident.as_str()).is_some()
11891189
{
11901190
("", " passed with `--extern`")
11911191
} else if add_built_in {

compiler/rustc_resolve/src/late/diagnostics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
231231

232232
let is_assoc_fn = self.self_type_is_available(span);
233233
// Emit help message for fake-self from other languages (e.g., `this` in Javascript).
234-
if ["this", "my"].contains(&&*item_str.as_str()) && is_assoc_fn {
234+
if ["this", "my"].contains(&item_str.as_str()) && is_assoc_fn {
235235
err.span_suggestion_short(
236236
span,
237237
"you might have meant to use `self` here instead",
@@ -1372,7 +1372,7 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
13721372
fn likely_rust_type(path: &[Segment]) -> Option<Symbol> {
13731373
let name = path[path.len() - 1].ident.as_str();
13741374
// Common Java types
1375-
Some(match &*name {
1375+
Some(match name {
13761376
"byte" => sym::u8, // In Java, bytes are signed, but in practice one almost always wants unsigned bytes.
13771377
"short" => sym::i16,
13781378
"boolean" => sym::bool,

compiler/rustc_resolve/src/macros.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ fn fast_print_path(path: &ast::Path) -> Symbol {
105105
path_str.push_str("::");
106106
}
107107
if segment.ident.name != kw::PathRoot {
108-
path_str.push_str(&segment.ident.as_str())
108+
path_str.push_str(segment.ident.as_str())
109109
}
110110
}
111111
Symbol::intern(&path_str)

compiler/rustc_save_analysis/src/sig.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'hir> Sig for hir::Generics<'hir> {
616616
if let hir::GenericParamKind::Const { .. } = param.kind {
617617
param_text.push_str("const ");
618618
}
619-
param_text.push_str(&param.name.ident().as_str());
619+
param_text.push_str(param.name.ident().as_str());
620620
defs.push(SigElement {
621621
id: id_from_hir_id(param.hir_id, scx),
622622
start: offset + text.len(),

compiler/rustc_symbol_mangling/src/v0.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ impl Printer<'tcx> for &mut SymbolMangler<'tcx> {
560560
ty::ExistentialPredicate::Projection(projection) => {
561561
let name = cx.tcx.associated_item(projection.item_def_id).ident;
562562
cx.push("p");
563-
cx.push_ident(&name.as_str());
563+
cx.push_ident(name.as_str());
564564
cx = projection.ty.print(cx)?;
565565
}
566566
ty::ExistentialPredicate::AutoTrait(def_id) => {

compiler/rustc_typeck/src/check/method/probe.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1908,7 +1908,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
19081908
.associated_items(def_id)
19091909
.in_definition_order()
19101910
.filter(|x| {
1911-
let dist = lev_distance(&*name.as_str(), &x.ident.as_str());
1911+
let dist = lev_distance(name.as_str(), x.ident.as_str());
19121912
x.kind.namespace() == Namespace::ValueNS && dist > 0 && dist <= max_dist
19131913
})
19141914
.copied()

src/librustdoc/clean/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ crate fn qpath_to_string(p: &hir::QPath<'_>) -> String {
167167
s.push_str("::");
168168
}
169169
if seg.ident.name != kw::PathRoot {
170-
s.push_str(&seg.ident.as_str());
170+
s.push_str(seg.ident.as_str());
171171
}
172172
}
173173
s

src/test/ui-fulldeps/auxiliary/lint-group-plugin-test.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ declare_lint_pass!(Pass => [TEST_LINT, PLEASE_LINT]);
2121

2222
impl<'tcx> LateLintPass<'tcx> for Pass {
2323
fn check_item(&mut self, cx: &LateContext, it: &rustc_hir::Item) {
24-
match &*it.ident.as_str() {
24+
match it.ident.as_str() {
2525
"lintme" => cx.lint(TEST_LINT, |lint| {
2626
lint.build("item is named 'lintme'").set_span(it.span).emit()
2727
}),

src/tools/clippy/clippy_lints/src/duration_subsec.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for DurationSubsec {
4949
if match_type(cx, cx.typeck_results().expr_ty(&args[0]).peel_refs(), &paths::DURATION);
5050
if let Some((Constant::Int(divisor), _)) = constant(cx, cx.typeck_results(), right);
5151
then {
52-
let suggested_fn = match (method_path.ident.as_str().as_ref(), divisor) {
52+
let suggested_fn = match (method_path.ident.as_str(), divisor) {
5353
("subsec_micros", 1_000) | ("subsec_nanos", 1_000_000) => "subsec_millis",
5454
("subsec_nanos", 1_000) => "subsec_micros",
5555
_ => return,

src/tools/clippy/clippy_lints/src/floating_point_arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ fn are_same_base_logs(cx: &LateContext<'_>, expr_a: &Expr<'_>, expr_b: &Expr<'_>
599599
return method_name_a.as_str() == method_name_b.as_str() &&
600600
args_a.len() == args_b.len() &&
601601
(
602-
["ln", "log2", "log10"].contains(&&*method_name_a.as_str()) ||
602+
["ln", "log2", "log10"].contains(&method_name_a.as_str()) ||
603603
method_name_a.as_str() == "log" && args_a.len() == 2 && eq_expr_value(cx, &args_a[1], &args_b[1])
604604
);
605605
}

src/tools/clippy/clippy_lints/src/loops/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -659,7 +659,7 @@ fn check_for_loop_arg(cx: &LateContext<'_>, pat: &Pat<'_>, arg: &Expr<'_>) {
659659
let mut next_loop_linted = false; // whether or not ITER_NEXT_LOOP lint was used
660660

661661
if let ExprKind::MethodCall(method, _, [self_arg], _) = arg.kind {
662-
let method_name = &*method.ident.as_str();
662+
let method_name = method.ident.as_str();
663663
// check for looping over x.iter() or x.iter_mut(), could use &x or &mut x
664664
match method_name {
665665
"iter" | "iter_mut" => explicit_iter_loop::check(cx, self_arg, arg, method_name),

src/tools/clippy/clippy_lints/src/match_str_case_mismatch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ impl<'a, 'tcx> Visitor<'tcx> for MatchExprVisitor<'a, 'tcx> {
9595
fn visit_expr(&mut self, ex: &'tcx Expr<'_>) {
9696
match ex.kind {
9797
ExprKind::MethodCall(segment, _, [receiver], _)
98-
if self.case_altered(&*segment.ident.as_str(), receiver) => {},
98+
if self.case_altered(segment.ident.as_str(), receiver) => {},
9999
_ => walk_expr(self, ex),
100100
}
101101
}

src/tools/clippy/clippy_lints/src/matches.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1127,7 +1127,7 @@ fn check_wild_enum_match(cx: &LateContext<'_>, ex: &Expr<'_>, arms: &[Arm<'_>])
11271127
if let CommonPrefixSearcher::Path(path_prefix) = path_prefix {
11281128
let mut s = String::new();
11291129
for seg in path_prefix {
1130-
s.push_str(&seg.ident.as_str());
1130+
s.push_str(seg.ident.as_str());
11311131
s.push_str("::");
11321132
}
11331133
s

src/tools/clippy/clippy_lints/src/methods/manual_saturating_arithmetic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ fn is_min_or_max<'tcx>(cx: &LateContext<'tcx>, expr: &hir::Expr<'_>) -> Option<M
8181
if args.is_empty();
8282
if let hir::ExprKind::Path(hir::QPath::TypeRelative(_, segment)) = &func.kind;
8383
then {
84-
match &*segment.ident.as_str() {
84+
match segment.ident.as_str() {
8585
"max_value" => return Some(MinMax::Max),
8686
"min_value" => return Some(MinMax::Min),
8787
_ => {}

src/tools/clippy/clippy_lints/src/methods/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1999,8 +1999,8 @@ impl<'tcx> LateLintPass<'tcx> for Methods {
19991999
from_iter_instead_of_collect::check(cx, expr, args, func);
20002000
},
20012001
hir::ExprKind::MethodCall(method_call, ref method_span, args, _) => {
2002-
or_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args);
2003-
expect_fun_call::check(cx, expr, *method_span, &method_call.ident.as_str(), args);
2002+
or_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args);
2003+
expect_fun_call::check(cx, expr, *method_span, method_call.ident.as_str(), args);
20042004
clone_on_copy::check(cx, expr, method_call.ident.name, args);
20052005
clone_on_ref_ptr::check(cx, expr, method_call.ident.name, args);
20062006
inefficient_to_string::check(cx, expr, method_call.ident.name, args);

src/tools/clippy/clippy_lints/src/methods/str_splitn.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ fn parse_iter_usage(
140140
let did = cx.typeck_results().type_dependent_def_id(e.hir_id)?;
141141
let iter_id = cx.tcx.get_diagnostic_item(sym::Iterator)?;
142142

143-
match (&*name.ident.as_str(), args) {
143+
match (name.ident.as_str(), args) {
144144
("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
145145
if reverse {
146146
(IterUsageKind::Second, e.span)
@@ -298,7 +298,7 @@ fn check_iter(
298298
if let Some(did) = cx.typeck_results().type_dependent_def_id(e.hir_id);
299299
if let Some(iter_id) = cx.tcx.get_diagnostic_item(sym::Iterator);
300300
then {
301-
match (&*name.ident.as_str(), args) {
301+
match (name.ident.as_str(), args) {
302302
("next", []) if cx.tcx.trait_of_item(did) == Some(iter_id) => {
303303
return true;
304304
},

src/tools/clippy/clippy_lints/src/mut_reference.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ impl<'tcx> LateLintPass<'tcx> for UnnecessaryMutPassed {
4949
let def_id = cx.typeck_results().type_dependent_def_id(e.hir_id).unwrap();
5050
let substs = cx.typeck_results().node_substs(e.hir_id);
5151
let method_type = cx.tcx.type_of(def_id).subst(cx.tcx, substs);
52-
check_arguments(cx, arguments, method_type, &path.ident.as_str(), "method");
52+
check_arguments(cx, arguments, method_type, path.ident.as_str(), "method");
5353
},
5454
_ => (),
5555
}

src/tools/clippy/clippy_lints/src/needless_option_as_deref.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl<'tcx> LateLintPass<'tcx> for OptionNeedlessDeref {
4848
if is_type_diagnostic_item(cx,outer_ty,sym::Option);
4949
if let ExprKind::MethodCall(path, _, [sub_expr], _) = expr.kind;
5050
let symbol = path.ident.as_str();
51-
if symbol=="as_deref" || symbol=="as_deref_mut";
51+
if symbol == "as_deref" || symbol == "as_deref_mut";
5252
if TyS::same_type( outer_ty, typeck.expr_ty(sub_expr) );
5353
then{
5454
span_lint_and_sugg(

src/tools/clippy/clippy_lints/src/open_options.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ fn get_open_options(cx: &LateContext<'_>, argument: &Expr<'_>, options: &mut Vec
8282
_ => Argument::Unknown,
8383
};
8484

85-
match &*path.ident.as_str() {
85+
match path.ident.as_str() {
8686
"create" => {
8787
options.push((OpenOption::Create, argument_option));
8888
},

src/tools/clippy/clippy_lints/src/serde_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl<'tcx> LateLintPass<'tcx> for SerdeApi {
3737
let mut seen_str = None;
3838
let mut seen_string = None;
3939
for item in items {
40-
match &*item.ident.as_str() {
40+
match item.ident.as_str() {
4141
"visit_str" => seen_str = Some(item.span),
4242
"visit_string" => seen_string = Some(item.span),
4343
_ => {},

src/tools/clippy/clippy_lints/src/unused_io_amount.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
5757
check_map_error(cx, res, expr);
5858
}
5959
},
60-
hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match &*path.ident.as_str() {
60+
hir::ExprKind::MethodCall(path, _, [ref arg_0, ..], _) => match path.ident.as_str() {
6161
"expect" | "unwrap" | "unwrap_or" | "unwrap_or_else" => {
6262
check_map_error(cx, arg_0, expr);
6363
},
@@ -71,7 +71,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedIoAmount {
7171
fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
7272
let mut call = call;
7373
while let hir::ExprKind::MethodCall(path, _, args, _) = call.kind {
74-
if matches!(&*path.ident.as_str(), "or" | "or_else" | "ok") {
74+
if matches!(path.ident.as_str(), "or" | "or_else" | "ok") {
7575
call = &args[0];
7676
} else {
7777
break;
@@ -82,7 +82,7 @@ fn check_map_error(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<
8282

8383
fn check_method_call(cx: &LateContext<'_>, call: &hir::Expr<'_>, expr: &hir::Expr<'_>) {
8484
if let hir::ExprKind::MethodCall(path, _, _, _) = call.kind {
85-
let symbol = &*path.ident.as_str();
85+
let symbol = path.ident.as_str();
8686
let read_trait = match_trait_method(cx, call, &paths::IO_READ);
8787
let write_trait = match_trait_method(cx, call, &paths::IO_WRITE);
8888

src/tools/clippy/clippy_lints/src/unwrap.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ fn collect_unwrap_info<'tcx>(
158158
if let Some(local_id) = path_to_local(&args[0]);
159159
let ty = cx.typeck_results().expr_ty(&args[0]);
160160
let name = method_name.ident.as_str();
161-
if is_relevant_option_call(cx, ty, &name) || is_relevant_result_call(cx, ty, &name);
161+
if is_relevant_option_call(cx, ty, name) || is_relevant_result_call(cx, ty, name);
162162
then {
163163
assert!(args.len() == 1);
164164
let unwrappable = match name.as_ref() {

src/tools/clippy/clippy_lints/src/upper_case_acronyms.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ fn correct_ident(ident: &str) -> String {
7979

8080
fn check_ident(cx: &LateContext<'_>, ident: &Ident, be_aggressive: bool) {
8181
let span = ident.span;
82-
let ident = &ident.as_str();
82+
let ident = ident.as_str();
8383
let corrected = correct_ident(ident);
8484
// warn if we have pure-uppercase idents
8585
// assume that two-letter words are some kind of valid abbreviation like FP for false positive

src/tools/clippy/clippy_lints/src/useless_conversion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'tcx> LateLintPass<'tcx> for UselessConversion {
6464
},
6565

6666
ExprKind::MethodCall(name, .., args, _) => {
67-
if is_trait_method(cx, e, sym::Into) && &*name.ident.as_str() == "into" {
67+
if is_trait_method(cx, e, sym::Into) && name.ident.as_str() == "into" {
6868
let a = cx.typeck_results().expr_ty(e);
6969
let b = cx.typeck_results().expr_ty(&args[0]);
7070
if same_type_and_consts(a, b) {

src/tools/rustfmt/src/items.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -616,10 +616,10 @@ impl<'a> FmtVisitor<'a> {
616616
(TyAlias(lty), TyAlias(rty))
617617
if both_type(&lty.ty, &rty.ty) || both_opaque(&lty.ty, &rty.ty) =>
618618
{
619-
a.ident.as_str().cmp(&b.ident.as_str())
619+
a.ident.as_str().cmp(b.ident.as_str())
620620
}
621621
(Const(..), Const(..)) | (MacCall(..), MacCall(..)) => {
622-
a.ident.as_str().cmp(&b.ident.as_str())
622+
a.ident.as_str().cmp(b.ident.as_str())
623623
}
624624
(Fn(..), Fn(..)) => a.span.lo().cmp(&b.span.lo()),
625625
(TyAlias(ty), _) if is_type(&ty.ty) => Ordering::Less,
@@ -1029,7 +1029,7 @@ pub(crate) fn format_trait(
10291029
if !bounds.is_empty() {
10301030
let ident_hi = context
10311031
.snippet_provider
1032-
.span_after(item.span, &item.ident.as_str());
1032+
.span_after(item.span, item.ident.as_str());
10331033
let bound_hi = bounds.last().unwrap().span().hi();
10341034
let snippet = context.snippet(mk_sp(ident_hi, bound_hi));
10351035
if contains_comment(snippet) {

src/tools/rustfmt/src/modules.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -467,10 +467,10 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
467467
if let DirectoryOwnership::Owned { relative } = &mut self.directory.ownership {
468468
if let Some(ident) = relative.take() {
469469
// remove the relative offset
470-
self.directory.path.push(&*ident.as_str());
470+
self.directory.path.push(ident.as_str());
471471
}
472472
}
473-
self.directory.path.push(&*id.as_str());
473+
self.directory.path.push(id.as_str());
474474
}
475475
}
476476

src/tools/rustfmt/src/reorder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use crate::visitor::FmtVisitor;
2626
fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
2727
match (&a.kind, &b.kind) {
2828
(&ast::ItemKind::Mod(..), &ast::ItemKind::Mod(..)) => {
29-
a.ident.as_str().cmp(&b.ident.as_str())
29+
a.ident.as_str().cmp(b.ident.as_str())
3030
}
3131
(&ast::ItemKind::ExternCrate(ref a_name), &ast::ItemKind::ExternCrate(ref b_name)) => {
3232
// `extern crate foo as bar;`
@@ -44,7 +44,7 @@ fn compare_items(a: &ast::Item, b: &ast::Item) -> Ordering {
4444
(Some(..), None) => Ordering::Greater,
4545
(None, Some(..)) => Ordering::Less,
4646
(None, None) => Ordering::Equal,
47-
(Some(..), Some(..)) => a.ident.as_str().cmp(&b.ident.as_str()),
47+
(Some(..), Some(..)) => a.ident.as_str().cmp(b.ident.as_str()),
4848
}
4949
}
5050
_ => unreachable!(),

0 commit comments

Comments
 (0)