about summary refs log tree commit diff
path: root/tests
diff options
context:
space:
mode:
authorTimo <30553356+y21@users.noreply.github.com>2025-04-27 12:56:14 +0000
committerGitHub <noreply@github.com>2025-04-27 12:56:14 +0000
commit0dd9722cdc613c90ffc02f6bfb3185185c7ded3f (patch)
tree52e2b329e284151c58e0113717dec2b49e53de2d /tests
parent39a408664b383865a56a0a76bbef6e36654edf7d (diff)
parent7b337f6e259ce3ae19e1c0c22c8ff493ecb4a8a3 (diff)
downloadrust-0dd9722cdc613c90ffc02f6bfb3185185c7ded3f.tar.gz
rust-0dd9722cdc613c90ffc02f6bfb3185185c7ded3f.zip
Replace some `Symbol::as_str` usage (#14679)
Follow up to https://github.com/rust-lang/rust-clippy/pull/14650

Replaces uses in the form `s.as_str() == "literal"`

r? @y21

changelog: none
Diffstat (limited to 'tests')
-rw-r--r--tests/ui-internal/symbol_as_str.fixed21
-rw-r--r--tests/ui-internal/symbol_as_str.rs21
-rw-r--r--tests/ui-internal/symbol_as_str.stderr76
-rw-r--r--tests/ui-internal/symbol_as_str_unfixable.rs15
-rw-r--r--tests/ui-internal/symbol_as_str_unfixable.stderr40
5 files changed, 173 insertions, 0 deletions
diff --git a/tests/ui-internal/symbol_as_str.fixed b/tests/ui-internal/symbol_as_str.fixed
new file mode 100644
index 00000000000..3e26732836c
--- /dev/null
+++ b/tests/ui-internal/symbol_as_str.fixed
@@ -0,0 +1,21 @@
+#![feature(rustc_private)]
+
+extern crate rustc_span;
+
+use clippy_utils::sym;
+use rustc_span::{Symbol, kw};
+
+fn f(s: Symbol) {
+    s == sym::f32;
+    //~^ symbol_as_str
+    s == sym::proc_dash_macro;
+    //~^ symbol_as_str
+    s == kw::SelfLower;
+    //~^ symbol_as_str
+    s == sym::msrv;
+    //~^ symbol_as_str
+    s == sym::Cargo_toml;
+    //~^ symbol_as_str
+    sym::get == s;
+    //~^ symbol_as_str
+}
diff --git a/tests/ui-internal/symbol_as_str.rs b/tests/ui-internal/symbol_as_str.rs
new file mode 100644
index 00000000000..334c32d1898
--- /dev/null
+++ b/tests/ui-internal/symbol_as_str.rs
@@ -0,0 +1,21 @@
+#![feature(rustc_private)]
+
+extern crate rustc_span;
+
+use clippy_utils::sym;
+use rustc_span::{Symbol, kw};
+
+fn f(s: Symbol) {
+    s.as_str() == "f32";
+    //~^ symbol_as_str
+    s.as_str() == "proc-macro";
+    //~^ symbol_as_str
+    s.as_str() == "self";
+    //~^ symbol_as_str
+    s.as_str() == "msrv";
+    //~^ symbol_as_str
+    s.as_str() == "Cargo.toml";
+    //~^ symbol_as_str
+    "get" == s.as_str();
+    //~^ symbol_as_str
+}
diff --git a/tests/ui-internal/symbol_as_str.stderr b/tests/ui-internal/symbol_as_str.stderr
new file mode 100644
index 00000000000..39f81f3833c
--- /dev/null
+++ b/tests/ui-internal/symbol_as_str.stderr
@@ -0,0 +1,76 @@
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str.rs:9:5
+   |
+LL |     s.as_str() == "f32";
+   |     ^^^^^^^^^^
+   |
+   = 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
+   |
+LL -     s.as_str() == "f32";
+LL +     s == sym::f32;
+   |
+
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str.rs:11:5
+   |
+LL |     s.as_str() == "proc-macro";
+   |     ^^^^^^^^^^
+   |
+help: use the preinterned symbol
+   |
+LL -     s.as_str() == "proc-macro";
+LL +     s == sym::proc_dash_macro;
+   |
+
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str.rs:13:5
+   |
+LL |     s.as_str() == "self";
+   |     ^^^^^^^^^^
+   |
+help: use the preinterned symbol
+   |
+LL -     s.as_str() == "self";
+LL +     s == kw::SelfLower;
+   |
+
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str.rs:15:5
+   |
+LL |     s.as_str() == "msrv";
+   |     ^^^^^^^^^^
+   |
+help: use the preinterned symbol
+   |
+LL -     s.as_str() == "msrv";
+LL +     s == sym::msrv;
+   |
+
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str.rs:17:5
+   |
+LL |     s.as_str() == "Cargo.toml";
+   |     ^^^^^^^^^^
+   |
+help: use the preinterned symbol
+   |
+LL -     s.as_str() == "Cargo.toml";
+LL +     s == sym::Cargo_toml;
+   |
+
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str.rs:19:14
+   |
+LL |     "get" == s.as_str();
+   |              ^^^^^^^^^^
+   |
+help: use the preinterned symbol
+   |
+LL -     "get" == s.as_str();
+LL +     sym::get == s;
+   |
+
+error: aborting due to 6 previous errors
+
diff --git a/tests/ui-internal/symbol_as_str_unfixable.rs b/tests/ui-internal/symbol_as_str_unfixable.rs
new file mode 100644
index 00000000000..635f28007e9
--- /dev/null
+++ b/tests/ui-internal/symbol_as_str_unfixable.rs
@@ -0,0 +1,15 @@
+//@no-rustfix: paths that don't exist yet
+#![feature(rustc_private)]
+
+extern crate rustc_span;
+
+use rustc_span::Symbol;
+
+fn f(s: Symbol) {
+    s.as_str() == "xyz123";
+    //~^ symbol_as_str
+    s.as_str() == "with-dash";
+    //~^ symbol_as_str
+    s.as_str() == "with.dot";
+    //~^ symbol_as_str
+}
diff --git a/tests/ui-internal/symbol_as_str_unfixable.stderr b/tests/ui-internal/symbol_as_str_unfixable.stderr
new file mode 100644
index 00000000000..5349983ca51
--- /dev/null
+++ b/tests/ui-internal/symbol_as_str_unfixable.stderr
@@ -0,0 +1,40 @@
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str_unfixable.rs:9:5
+   |
+LL |     s.as_str() == "xyz123";
+   |     ^^^^^^^^^^
+   |
+   = 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
+   |
+LL -     s.as_str() == "xyz123";
+LL +     s == sym::xyz123;
+   |
+
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str_unfixable.rs:11:5
+   |
+LL |     s.as_str() == "with-dash";
+   |     ^^^^^^^^^^
+   |
+help: add the symbol to `clippy_utils/src/sym.rs` and use it
+   |
+LL -     s.as_str() == "with-dash";
+LL +     s == sym::with_dash;
+   |
+
+error: converting a Symbol to a string
+  --> tests/ui-internal/symbol_as_str_unfixable.rs:13:5
+   |
+LL |     s.as_str() == "with.dot";
+   |     ^^^^^^^^^^
+   |
+help: add the symbol to `clippy_utils/src/sym.rs` and use it
+   |
+LL -     s.as_str() == "with.dot";
+LL +     s == sym::with_dot;
+   |
+
+error: aborting due to 3 previous errors
+