about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--clippy_lints/src/arbitrary_source_item_ordering.rs24
1 files changed, 8 insertions, 16 deletions
diff --git a/clippy_lints/src/arbitrary_source_item_ordering.rs b/clippy_lints/src/arbitrary_source_item_ordering.rs
index 9113c20c795..4111fd10c13 100644
--- a/clippy_lints/src/arbitrary_source_item_ordering.rs
+++ b/clippy_lints/src/arbitrary_source_item_ordering.rs
@@ -344,7 +344,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
         struct CurItem<'a> {
             item: &'a Item<'a>,
             order: usize,
-            name: String,
+            name: Option<String>,
         }
         let mut cur_t: Option<CurItem<'_>> = None;
 
@@ -368,7 +368,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
             let ident = if let Some(ident) = item.kind.ident() {
                 ident
             } else if let ItemKind::Impl(_) = item.kind
-                && !get_item_name(item).is_empty()
+                && get_item_name(item).is_some()
             {
                 rustc_span::Ident::empty() // FIXME: a bit strange, is there a better way to do it?
             } else {
@@ -495,7 +495,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte
 /// further in the [Rust Reference, Paths Chapter][rust_ref].
 ///
 /// [rust_ref]: https://doc.rust-lang.org/reference/paths.html#crate-1
-fn get_item_name(item: &Item<'_>) -> String {
+fn get_item_name(item: &Item<'_>) -> Option<String> {
     match item.kind {
         ItemKind::Impl(im) => {
             if let TyKind::Path(path) = im.self_ty.kind {
@@ -515,27 +515,19 @@ fn get_item_name(item: &Item<'_>) -> String {
                         }
 
                         segs.push(String::new());
-                        segs.join("!!")
+                        Some(segs.join("!!"))
                     },
                     QPath::TypeRelative(_, _path_seg) => {
                         // This case doesn't exist in the clippy tests codebase.
-                        String::new()
+                        None
                     },
-                    QPath::LangItem(_, _) => String::new(),
+                    QPath::LangItem(_, _) => None,
                 }
             } else {
                 // Impls for anything that isn't a named type can be skipped.
-                String::new()
+                None
             }
         },
-        // FIXME: `Ident::empty` for anonymous items is a bit strange, is there
-        // a better way to do it?
-        _ => item
-            .kind
-            .ident()
-            .unwrap_or(rustc_span::Ident::empty())
-            .name
-            .as_str()
-            .to_owned(),
+        _ => item.kind.ident().map(|name| name.as_str().to_owned()),
     }
 }