Skip to content

Commit a89a063

Browse files
committed
Remove SymbolStr.
By changing `as_str()` to take `&self` instead of `self`, we can just return `&str`. We're still lying about lifetimes, but it's a smaller lie than before, where `SymbolStr` contained a (fake) `&'static str`!
1 parent 41c48bd commit a89a063

File tree

6 files changed

+23
-21
lines changed

6 files changed

+23
-21
lines changed

clippy_lints/src/attrs.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_semver::RustcVersion;
1717
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
1818
use rustc_span::source_map::Span;
1919
use rustc_span::sym;
20-
use rustc_span::symbol::{Symbol, SymbolStr};
20+
use rustc_span::symbol::Symbol;
2121
use semver::Version;
2222

2323
static UNIX_SYSTEMS: &[&str] = &[
@@ -310,8 +310,8 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
310310
|| is_word(lint, sym::deprecated)
311311
|| is_word(lint, sym!(unreachable_pub))
312312
|| is_word(lint, sym!(unused))
313-
|| extract_clippy_lint(lint).map_or(false, |s| s == "wildcard_imports")
314-
|| extract_clippy_lint(lint).map_or(false, |s| s == "enum_glob_use")
313+
|| extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "wildcard_imports")
314+
|| extract_clippy_lint(lint).map_or(false, |s| s.as_str() == "enum_glob_use")
315315
{
316316
return;
317317
}
@@ -370,15 +370,15 @@ impl<'tcx> LateLintPass<'tcx> for Attributes {
370370
}
371371

372372
/// Returns the lint name if it is clippy lint.
373-
fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
373+
fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<Symbol> {
374374
if_chain! {
375375
if let Some(meta_item) = lint.meta_item();
376376
if meta_item.path.segments.len() > 1;
377377
if let tool_name = meta_item.path.segments[0].ident;
378378
if tool_name.name == sym::clippy;
379379
then {
380380
let lint_name = meta_item.path.segments.last().unwrap().ident.name;
381-
return Some(lint_name.as_str());
381+
return Some(lint_name);
382382
}
383383
}
384384
None
@@ -387,7 +387,7 @@ fn extract_clippy_lint(lint: &NestedMetaItem) -> Option<SymbolStr> {
387387
fn check_clippy_lint_names(cx: &LateContext<'_>, name: Symbol, items: &[NestedMetaItem]) {
388388
for lint in items {
389389
if let Some(lint_name) = extract_clippy_lint(lint) {
390-
if lint_name == "restriction" && name != sym::allow {
390+
if lint_name.as_str() == "restriction" && name != sym::allow {
391391
span_lint_and_help(
392392
cx,
393393
BLANKET_CLIPPY_RESTRICTION_LINTS,

clippy_lints/src/match_str_case_mismatch.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_middle::hir::map::Map;
99
use rustc_middle::lint::in_external_macro;
1010
use rustc_middle::ty;
1111
use rustc_session::{declare_lint_pass, declare_tool_lint};
12-
use rustc_span::symbol::SymbolStr;
12+
use rustc_span::symbol::Symbol;
1313
use rustc_span::{sym, Span};
1414

1515
declare_clippy_lint! {
@@ -71,8 +71,8 @@ impl LateLintPass<'_> for MatchStrCaseMismatch {
7171
visitor.visit_expr(match_expr);
7272

7373
if let Some(case_method) = visitor.case_method {
74-
if let Some((bad_case_span, bad_case_str)) = verify_case(&case_method, arms) {
75-
lint(cx, &case_method, bad_case_span, &bad_case_str);
74+
if let Some((bad_case_span, bad_case_sym)) = verify_case(&case_method, arms) {
75+
lint(cx, &case_method, bad_case_span, bad_case_sym.as_str());
7676
}
7777
}
7878
}
@@ -126,7 +126,7 @@ fn get_case_method(segment_ident_str: &str) -> Option<CaseMethod> {
126126
}
127127
}
128128

129-
fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, SymbolStr)> {
129+
fn verify_case<'a>(case_method: &'a CaseMethod, arms: &'a [Arm<'_>]) -> Option<(Span, Symbol)> {
130130
let case_check = match case_method {
131131
CaseMethod::LowerCase => |input: &str| -> bool { input.chars().all(|c| c.to_lowercase().next() == Some(c)) },
132132
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<(
144144
let input = symbol.as_str();
145145
if !case_check(&input);
146146
then {
147-
return Some((lit.span, input));
147+
return Some((lit.span, symbol));
148148
}
149149
}
150150
}

clippy_lints/src/methods/mod.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ use rustc_middle::lint::in_external_macro;
7878
use rustc_middle::ty::{self, TraitRef, Ty, TyS};
7979
use rustc_semver::RustcVersion;
8080
use rustc_session::{declare_tool_lint, impl_lint_pass};
81-
use rustc_span::symbol::SymbolStr;
81+
use rustc_span::symbol::Symbol;
8282
use rustc_span::{sym, Span};
8383
use rustc_typeck::hir_ty_to_ty;
8484

@@ -1968,21 +1968,21 @@ impl_lint_pass!(Methods => [
19681968
]);
19691969

19701970
/// Extracts a method call name, args, and `Span` of the method name.
1971-
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(SymbolStr, &'tcx [hir::Expr<'tcx>], Span)> {
1971+
fn method_call<'tcx>(recv: &'tcx hir::Expr<'tcx>) -> Option<(Symbol, &'tcx [hir::Expr<'tcx>], Span)> {
19721972
if let ExprKind::MethodCall(path, span, args, _) = recv.kind {
19731973
if !args.iter().any(|e| e.span.from_expansion()) {
1974-
return Some((path.ident.name.as_str(), args, span));
1974+
return Some((path.ident.name, args, span));
19751975
}
19761976
}
19771977
None
19781978
}
19791979

1980-
/// Same as `method_call` but the `SymbolStr` is dereferenced into a temporary `&str`
1980+
/// Same as `method_call` but the `Symbol` is dereferenced into a temporary `&str`
19811981
macro_rules! method_call {
19821982
($expr:expr) => {
19831983
method_call($expr)
19841984
.as_ref()
1985-
.map(|&(ref name, args, span)| (&**name, args, span))
1985+
.map(|&(ref name, args, span)| (name.as_str(), args, span))
19861986
};
19871987
}
19881988

clippy_lints/src/misc.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,7 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
407407
// Don't lint things expanded by #[derive(...)], etc or `await` desugaring
408408
return;
409409
}
410+
let sym;
410411
let binding = match expr.kind {
411412
ExprKind::Path(ref qpath) if !matches!(qpath, hir::QPath::LangItem(..)) => {
412413
let binding = last_path_segment(qpath).ident.as_str();
@@ -423,7 +424,8 @@ impl<'tcx> LateLintPass<'tcx> for MiscLints {
423424
}
424425
},
425426
ExprKind::Field(_, ident) => {
426-
let name = ident.as_str();
427+
sym = ident.name;
428+
let name = sym.as_str();
427429
if name.starts_with('_') && !name.starts_with("__") {
428430
Some(name)
429431
} else {

clippy_lints/src/multiple_crate_versions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ impl LateLintPass<'_> for MultipleCrateVersions {
4848
}
4949

5050
let metadata = unwrap_cargo_metadata!(cx, MULTIPLE_CRATE_VERSIONS, true);
51-
let local_name = cx.tcx.crate_name(LOCAL_CRATE).as_str();
51+
let local_name = cx.tcx.crate_name(LOCAL_CRATE);
5252
let mut packages = metadata.packages;
5353
packages.sort_by(|a, b| a.name.cmp(&b.name));
5454

5555
if_chain! {
5656
if let Some(resolve) = &metadata.resolve;
5757
if let Some(local_id) = packages
5858
.iter()
59-
.find_map(|p| if p.name == *local_name { Some(&p.id) } else { None });
59+
.find_map(|p| if p.name == local_name.as_str() { Some(&p.id) } else { None });
6060
then {
6161
for (name, group) in &packages.iter().group_by(|p| p.name.clone()) {
6262
let group: Vec<&Package> = group.collect();

clippy_utils/src/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,8 +319,8 @@ impl<'a, 'tcx> ConstEvalLateContext<'a, 'tcx> {
319319
if let ExprKind::Path(qpath) = &callee.kind;
320320
let res = self.typeck_results.qpath_res(qpath, callee.hir_id);
321321
if let Some(def_id) = res.opt_def_id();
322-
let def_path: Vec<_> = self.lcx.get_def_path(def_id).into_iter().map(Symbol::as_str).collect();
323-
let def_path: Vec<&str> = def_path.iter().take(4).map(|s| &**s).collect();
322+
let def_path = self.lcx.get_def_path(def_id);
323+
let def_path: Vec<&str> = def_path.iter().take(4).map(|s| s.as_str()).collect();
324324
if let ["core", "num", int_impl, "max_value"] = *def_path;
325325
then {
326326
let value = match int_impl {

0 commit comments

Comments
 (0)