]> git.lizzy.rs Git - rust.git/commitdiff
Eliminate string comparison from rustdoc keyword spacing logic
authorDavid Tolnay <dtolnay@gmail.com>
Fri, 14 Jan 2022 22:38:15 +0000 (14:38 -0800)
committerDavid Tolnay <dtolnay@gmail.com>
Tue, 18 Jan 2022 19:14:41 +0000 (11:14 -0800)
src/librustdoc/clean/render_macro_matchers.rs

index 14990c2e9e6e9a8a94fa44800204242620e2811c..a6faa0d6857550670b2492ed2c2f2f8c7a685732 100644 (file)
@@ -5,7 +5,7 @@
 use rustc_middle::ty::TyCtxt;
 use rustc_session::parse::ParseSess;
 use rustc_span::source_map::FilePathMapping;
-use rustc_span::symbol::Symbol;
+use rustc_span::symbol::{kw, Symbol};
 
 /// Render a macro matcher in a format suitable for displaying to the user
 /// as part of an item declaration.
@@ -181,11 +181,38 @@ enum State {
 // `f(0)` (no space between ident and paren) from tokens resembling `if let (0,
 // 0) = x` (space between ident and paren).
 fn usually_needs_space_between_keyword_and_open_delim(symbol: Symbol) -> bool {
-    match symbol.as_str() {
-        "as" | "box" | "break" | "const" | "continue" | "crate" | "else" | "enum" | "extern"
-        | "for" | "if" | "impl" | "in" | "let" | "loop" | "macro" | "match" | "mod" | "move"
-        | "mut" | "ref" | "return" | "static" | "struct" | "trait" | "type" | "unsafe" | "use"
-        | "where" | "while" | "yield" => true,
+    match symbol {
+        kw::As
+        | kw::Box
+        | kw::Break
+        | kw::Const
+        | kw::Continue
+        | kw::Crate
+        | kw::Else
+        | kw::Enum
+        | kw::Extern
+        | kw::For
+        | kw::If
+        | kw::Impl
+        | kw::In
+        | kw::Let
+        | kw::Loop
+        | kw::Macro
+        | kw::Match
+        | kw::Mod
+        | kw::Move
+        | kw::Mut
+        | kw::Ref
+        | kw::Return
+        | kw::Static
+        | kw::Struct
+        | kw::Trait
+        | kw::Type
+        | kw::Unsafe
+        | kw::Use
+        | kw::Where
+        | kw::While
+        | kw::Yield => true,
         _ => false,
     }
 }