Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New internal lint: interning_defined_symbol
- Loading branch information
Michael Wright
committed
Dec 13, 2020
1 parent
89c282f
commit 3af09b8
Showing
6 changed files
with
183 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// run-rustfix | ||
#![deny(clippy::internal)] | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_span; | ||
|
||
use rustc_span::symbol::Symbol; | ||
|
||
macro_rules! sym { | ||
($tt:tt) => { | ||
rustc_span::symbol::Symbol::intern(stringify!($tt)) | ||
}; | ||
} | ||
|
||
fn main() { | ||
// Direct use of Symbol::intern | ||
let _ = rustc_span::symbol::sym::f32; | ||
|
||
// Using a sym macro | ||
let _ = rustc_span::symbol::sym::f32; | ||
|
||
// Correct suggestion when symbol isn't stringified constant name | ||
let _ = rustc_span::symbol::sym::proc_dash_macro; | ||
|
||
// Interning a symbol that is not defined | ||
let _ = Symbol::intern("xyz123"); | ||
let _ = sym!(xyz123); | ||
|
||
// Using a different `intern` function | ||
let _ = intern("f32"); | ||
} | ||
|
||
fn intern(_: &str) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// run-rustfix | ||
#![deny(clippy::internal)] | ||
#![feature(rustc_private)] | ||
|
||
extern crate rustc_span; | ||
|
||
use rustc_span::symbol::Symbol; | ||
|
||
macro_rules! sym { | ||
($tt:tt) => { | ||
rustc_span::symbol::Symbol::intern(stringify!($tt)) | ||
}; | ||
} | ||
|
||
fn main() { | ||
// Direct use of Symbol::intern | ||
let _ = Symbol::intern("f32"); | ||
|
||
// Using a sym macro | ||
let _ = sym!(f32); | ||
|
||
// Correct suggestion when symbol isn't stringified constant name | ||
let _ = Symbol::intern("proc-macro"); | ||
|
||
// Interning a symbol that is not defined | ||
let _ = Symbol::intern("xyz123"); | ||
let _ = sym!(xyz123); | ||
|
||
// Using a different `intern` function | ||
let _ = intern("f32"); | ||
} | ||
|
||
fn intern(_: &str) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: interning a defined symbol | ||
--> $DIR/interning_defined_symbol.rs:17:13 | ||
| | ||
LL | let _ = Symbol::intern("f32"); | ||
| ^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::symbol::sym::f32` | ||
| | ||
note: the lint level is defined here | ||
--> $DIR/interning_defined_symbol.rs:2:9 | ||
| | ||
LL | #![deny(clippy::internal)] | ||
| ^^^^^^^^^^^^^^^^ | ||
= note: `#[deny(clippy::interning_defined_symbol)]` implied by `#[deny(clippy::internal)]` | ||
|
||
error: interning a defined symbol | ||
--> $DIR/interning_defined_symbol.rs:20:13 | ||
| | ||
LL | let _ = sym!(f32); | ||
| ^^^^^^^^^ help: try: `rustc_span::symbol::sym::f32` | ||
|
||
error: interning a defined symbol | ||
--> $DIR/interning_defined_symbol.rs:23:13 | ||
| | ||
LL | let _ = Symbol::intern("proc-macro"); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try: `rustc_span::symbol::sym::proc_dash_macro` | ||
|
||
error: aborting due to 3 previous errors | ||
|