Skip to content

Commit 002af4d

Browse files
committed
Avoid storing SymbolStr in a struct.
It's intended only for very temporary use.
1 parent 9f00808 commit 002af4d

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/tools/clippy/clippy_lints/src/non_expressive_names.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_lint::{EarlyContext, EarlyLintPass};
88
use rustc_middle::lint::in_external_macro;
99
use rustc_session::{declare_tool_lint, impl_lint_pass};
1010
use rustc_span::source_map::Span;
11-
use rustc_span::symbol::{Ident, SymbolStr};
11+
use rustc_span::symbol::{Ident, Symbol};
1212
use std::cmp::Ordering;
1313

1414
declare_clippy_lint! {
@@ -75,7 +75,7 @@ pub struct NonExpressiveNames {
7575
impl_lint_pass!(NonExpressiveNames => [SIMILAR_NAMES, MANY_SINGLE_CHAR_NAMES, JUST_UNDERSCORES_AND_DIGITS]);
7676

7777
struct ExistingName {
78-
interned: SymbolStr,
78+
interned: Symbol,
7979
span: Span,
8080
len: usize,
8181
exemptions: &'static [&'static str],
@@ -218,18 +218,19 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
218218
let mut split_at = None;
219219
match existing_name.len.cmp(&count) {
220220
Ordering::Greater => {
221-
if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned) {
221+
if existing_name.len - count != 1 || levenstein_not_1(&interned_name, &existing_name.interned.as_str()) {
222222
continue;
223223
}
224224
},
225225
Ordering::Less => {
226-
if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned, &interned_name) {
226+
if count - existing_name.len != 1 || levenstein_not_1(&existing_name.interned.as_str(), &interned_name) {
227227
continue;
228228
}
229229
},
230230
Ordering::Equal => {
231231
let mut interned_chars = interned_name.chars();
232-
let mut existing_chars = existing_name.interned.chars();
232+
let interned_str = existing_name.interned.as_str();
233+
let mut existing_chars = interned_str.chars();
233234
let first_i = interned_chars.next().expect("we know we have at least one char");
234235
let first_e = existing_chars.next().expect("we know we have at least one char");
235236
let eq_or_numeric = |(a, b): (char, char)| a == b || a.is_numeric() && b.is_numeric();
@@ -302,7 +303,7 @@ impl<'a, 'tcx, 'b> SimilarNamesNameVisitor<'a, 'tcx, 'b> {
302303
}
303304
self.0.names.push(ExistingName {
304305
exemptions: get_exemptions(&interned_name).unwrap_or(&[]),
305-
interned: interned_name,
306+
interned: ident.name,
306307
span: ident.span,
307308
len: count,
308309
});

src/tools/clippy/clippy_lints/src/unsafe_removed_from_name.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use rustc_ast::ast::{Item, ItemKind, UseTree, UseTreeKind};
33
use rustc_lint::{EarlyContext, EarlyLintPass};
44
use rustc_session::{declare_lint_pass, declare_tool_lint};
55
use rustc_span::source_map::Span;
6-
use rustc_span::symbol::{Ident, SymbolStr};
6+
use rustc_span::symbol::Ident;
77

88
declare_clippy_lint! {
99
/// **What it does:** Checks for imports that remove "unsafe" from an item's
@@ -73,6 +73,6 @@ fn unsafe_to_safe_check(old_name: Ident, new_name: Ident, cx: &EarlyContext<'_>,
7373
}
7474

7575
#[must_use]
76-
fn contains_unsafe(name: &SymbolStr) -> bool {
76+
fn contains_unsafe(name: &str) -> bool {
7777
name.contains("Unsafe") || name.contains("unsafe")
7878
}

0 commit comments

Comments
 (0)