Replace Symbol::as_str usage in match expressions

This commit is contained in:
Alex Macleod 2025-05-07 13:52:11 +00:00
parent cf6bebb343
commit 5aac708398
25 changed files with 281 additions and 148 deletions

View file

@ -4,9 +4,10 @@ error: interning a string literal
LL | let _ = Symbol::intern("f32");
| ^^^^^^^^^^^^^^^^^^^^^
|
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
= note: `-D clippy::interning-literals` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::interning_literals)]`
help: use the preinterned symbol
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("f32");
LL + let _ = sym::f32;
@ -18,7 +19,8 @@ error: interning a string literal
LL | let _ = Symbol::intern("proc-macro");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("proc-macro");
LL + let _ = sym::proc_dash_macro;
@ -30,7 +32,8 @@ error: interning a string literal
LL | let _ = Symbol::intern("self");
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("self");
LL + let _ = kw::SelfLower;
@ -42,7 +45,8 @@ error: interning a string literal
LL | let _ = Symbol::intern("msrv");
| ^^^^^^^^^^^^^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("msrv");
LL + let _ = sym::msrv;
@ -54,7 +58,8 @@ error: interning a string literal
LL | let _ = Symbol::intern("Cargo.toml");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("Cargo.toml");
LL + let _ = sym::Cargo_toml;

View file

@ -4,9 +4,10 @@ error: interning a string literal
LL | let _ = Symbol::intern("xyz123");
| ^^^^^^^^^^^^^^^^^^^^^^^^
|
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
= note: `-D clippy::interning-literals` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::interning_literals)]`
help: add the symbol to `clippy_utils/src/sym.rs` and use it
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("xyz123");
LL + let _ = sym::xyz123;
@ -18,7 +19,8 @@ error: interning a string literal
LL | let _ = Symbol::intern("with-dash");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: add the symbol to `clippy_utils/src/sym.rs` and use it
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("with-dash");
LL + let _ = sym::with_dash;
@ -30,7 +32,8 @@ error: interning a string literal
LL | let _ = Symbol::intern("with.dot");
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
help: add the symbol to `clippy_utils/src/sym.rs` and use it
= help: add the symbol to `clippy_utils/src/sym.rs` if needed
help: use a preinterned symbol instead
|
LL - let _ = Symbol::intern("with.dot");
LL + let _ = sym::with_dot;

View file

@ -18,4 +18,11 @@ fn f(s: Symbol) {
//~^ symbol_as_str
sym::get == s;
//~^ symbol_as_str
let _ = match s {
//~^ symbol_as_str
sym::unwrap_err => 1,
sym::unwrap_or_default | sym::unwrap_or_else => 2,
_ => 3,
};
}

View file

@ -18,4 +18,11 @@ fn f(s: Symbol) {
//~^ symbol_as_str
"get" == s.as_str();
//~^ symbol_as_str
let _ = match s.as_str() {
//~^ symbol_as_str
"unwrap_err" => 1,
"unwrap_or_default" | "unwrap_or_else" => 2,
_ => 3,
};
}

View file

@ -4,9 +4,10 @@ error: converting a Symbol to a string
LL | s.as_str() == "f32";
| ^^^^^^^^^^
|
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
= note: `-D clippy::symbol-as-str` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::symbol_as_str)]`
help: use the preinterned symbol
help: use preinterned symbols instead
|
LL - s.as_str() == "f32";
LL + s == sym::f32;
@ -18,7 +19,8 @@ error: converting a Symbol to a string
LL | s.as_str() == "proc-macro";
| ^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL - s.as_str() == "proc-macro";
LL + s == sym::proc_dash_macro;
@ -30,7 +32,8 @@ error: converting a Symbol to a string
LL | s.as_str() == "self";
| ^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL - s.as_str() == "self";
LL + s == kw::SelfLower;
@ -42,7 +45,8 @@ error: converting a Symbol to a string
LL | s.as_str() == "msrv";
| ^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL - s.as_str() == "msrv";
LL + s == sym::msrv;
@ -54,7 +58,8 @@ error: converting a Symbol to a string
LL | s.as_str() == "Cargo.toml";
| ^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL - s.as_str() == "Cargo.toml";
LL + s == sym::Cargo_toml;
@ -66,11 +71,27 @@ error: converting a Symbol to a string
LL | "get" == s.as_str();
| ^^^^^^^^^^
|
help: use the preinterned symbol
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL - "get" == s.as_str();
LL + sym::get == s;
|
error: aborting due to 6 previous errors
error: converting a Symbol to a string
--> tests/ui-internal/symbol_as_str.rs:22:19
|
LL | let _ = match s.as_str() {
| ^^^^^^^^^^
|
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL ~ let _ = match s {
LL |
LL ~ sym::unwrap_err => 1,
LL ~ sym::unwrap_or_default | sym::unwrap_or_else => 2,
|
error: aborting due to 7 previous errors

View file

@ -4,9 +4,10 @@ error: converting a Symbol to a string
LL | s.as_str() == "xyz123";
| ^^^^^^^^^^
|
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
= note: `-D clippy::symbol-as-str` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(clippy::symbol_as_str)]`
help: add the symbol to `clippy_utils/src/sym.rs` and use it
help: use preinterned symbols instead
|
LL - s.as_str() == "xyz123";
LL + s == sym::xyz123;
@ -18,7 +19,8 @@ error: converting a Symbol to a string
LL | s.as_str() == "with-dash";
| ^^^^^^^^^^
|
help: add the symbol to `clippy_utils/src/sym.rs` and use it
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL - s.as_str() == "with-dash";
LL + s == sym::with_dash;
@ -30,7 +32,8 @@ error: converting a Symbol to a string
LL | s.as_str() == "with.dot";
| ^^^^^^^^^^
|
help: add the symbol to `clippy_utils/src/sym.rs` and use it
= help: add the symbols to `clippy_utils/src/sym.rs` if needed
help: use preinterned symbols instead
|
LL - s.as_str() == "with.dot";
LL + s == sym::with_dot;