File tree Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Expand file tree Collapse file tree 3 files changed +71
-0
lines changed Original file line number Diff line number Diff line change 1+ #![feature(rustc_private)]
2+ #![warn(clippy::slow_symbol_comparisons)]
3+
4+ extern crate rustc_span;
5+
6+ use clippy_utils::sym;
7+ use rustc_span::Symbol;
8+
9+ fn main() {
10+ let symbol = sym!(example);
11+ let other_symbol = sym!(other_example);
12+
13+ // Should lint
14+ let slow_comparison = symbol.as_str() == "example";
15+ //~^ error: comparing `Symbol` via `Symbol::intern`
16+ let slow_comparison_macro = symbol.as_str() == "example";
17+ //~^ error: comparing `Symbol` via `Symbol::intern`
18+ let slow_comparison_backwards = symbol.as_str() == "example";
19+ //~^ error: comparing `Symbol` via `Symbol::intern`
20+
21+ // Should not lint
22+ let faster_comparison = symbol.as_str() == "other_example";
23+ let preinterned_comparison = symbol == other_symbol;
24+ }
Original file line number Diff line number Diff line change 1+ #![ feature( rustc_private) ]
2+ #![ warn( clippy:: slow_symbol_comparisons) ]
3+
4+ extern crate rustc_span;
5+
6+ use clippy_utils:: sym;
7+ use rustc_span:: Symbol ;
8+
9+ fn main ( ) {
10+ let symbol = sym ! ( example) ;
11+ let other_symbol = sym ! ( other_example) ;
12+
13+ // Should lint
14+ let slow_comparison = symbol == Symbol :: intern ( "example" ) ;
15+ //~^ error: comparing `Symbol` via `Symbol::intern`
16+ let slow_comparison_macro = symbol == sym ! ( example) ;
17+ //~^ error: comparing `Symbol` via `Symbol::intern`
18+ let slow_comparison_backwards = sym ! ( example) == symbol;
19+ //~^ error: comparing `Symbol` via `Symbol::intern`
20+
21+ // Should not lint
22+ let faster_comparison = symbol. as_str ( ) == "other_example" ;
23+ let preinterned_comparison = symbol == other_symbol;
24+ }
Original file line number Diff line number Diff line change 1+ error: comparing `Symbol` via `Symbol::intern`
2+ --> tests/ui-internal/slow_symbol_comparisons.rs:14:27
3+ |
4+ LL | let slow_comparison = symbol == Symbol::intern("example");
5+ | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use `Symbol::as_str` and check the string instead: `symbol.as_str() == "example"`
6+ |
7+ = note: `-D clippy::slow-symbol-comparisons` implied by `-D warnings`
8+ = help: to override `-D warnings` add `#[allow(clippy::slow_symbol_comparisons)]`
9+
10+ error: comparing `Symbol` via `Symbol::intern`
11+ --> tests/ui-internal/slow_symbol_comparisons.rs:16:33
12+ |
13+ LL | let slow_comparison_macro = symbol == sym!(example);
14+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `Symbol::as_str` and check the string instead: `symbol.as_str() == "example"`
15+
16+ error: comparing `Symbol` via `Symbol::intern`
17+ --> tests/ui-internal/slow_symbol_comparisons.rs:18:37
18+ |
19+ LL | let slow_comparison_backwards = sym!(example) == symbol;
20+ | ^^^^^^^^^^^^^^^^^^^^^^^ help: use `Symbol::as_str` and check the string instead: `symbol.as_str() == "example"`
21+
22+ error: aborting due to 3 previous errors
23+
You can’t perform that action at this time.
0 commit comments