Add variant_name function to LangItem
Clippy has an internal lint that checks for the usage of hardcoded def paths and suggests to replace them with a lang or diagnostic item, if possible. This was implemented with a hack, by getting all the variants of the `LangItem` enum and then index into it with the position of the `LangItem` in the `items` list. This is no longer possible, because the `items` list can't be accessed anymore.
This commit is contained in:
parent
b6097f2e1b
commit
4e65f5ea82
6 changed files with 35 additions and 36 deletions
|
@ -95,6 +95,14 @@ macro_rules! language_item_table {
|
|||
}
|
||||
}
|
||||
|
||||
/// Returns the name of the `LangItem` enum variant.
|
||||
// This method is used by Clippy for internal lints.
|
||||
pub fn variant_name(self) -> &'static str {
|
||||
match self {
|
||||
$( LangItem::$variant => stringify!($variant), )*
|
||||
}
|
||||
}
|
||||
|
||||
pub fn target(self) -> Target {
|
||||
match self {
|
||||
$( LangItem::$variant => $target, )*
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue