@@ -344,7 +344,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
344344 struct CurItem < ' a > {
345345 item : & ' a Item < ' a > ,
346346 order : usize ,
347- name : String ,
347+ name : Option < String > ,
348348 }
349349 let mut cur_t: Option < CurItem < ' _ > > = None ;
350350
@@ -365,28 +365,26 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
365365 continue ;
366366 }
367367
368- let ident = if let Some ( ident) = item. kind . ident ( ) {
369- ident
368+ if let Some ( ident) = item. kind . ident ( ) {
369+ if ident. name . as_str ( ) . starts_with ( '_' ) {
370+ // Filters out unnamed macro-like impls for various derives,
371+ // e.g. serde::Serialize or num_derive::FromPrimitive.
372+ continue ;
373+ }
374+
375+ if ident. name == rustc_span:: sym:: std && item. span . is_dummy ( ) {
376+ if let ItemKind :: ExternCrate ( None , _) = item. kind {
377+ // Filters the auto-included Rust standard library.
378+ continue ;
379+ }
380+ println ! ( "Unknown item: {item:?}" ) ;
381+ }
370382 } else if let ItemKind :: Impl ( _) = item. kind
371- && ! get_item_name ( item) . is_empty ( )
383+ && get_item_name ( item) . is_some ( )
372384 {
373- rustc_span :: Ident :: empty ( ) // FIXME: a bit strange, is there a better way to do it?
385+ // keep going below
374386 } else {
375387 continue ;
376- } ;
377-
378- if ident. name . as_str ( ) . starts_with ( '_' ) {
379- // Filters out unnamed macro-like impls for various derives,
380- // e.g. serde::Serialize or num_derive::FromPrimitive.
381- continue ;
382- }
383-
384- if ident. name == rustc_span:: sym:: std && item. span . is_dummy ( ) {
385- if let ItemKind :: ExternCrate ( None , _) = item. kind {
386- // Filters the auto-included Rust standard library.
387- continue ;
388- }
389- println ! ( "Unknown item: {item:?}" ) ;
390388 }
391389
392390 let item_kind = convert_module_item_kind ( & item. kind ) ;
@@ -495,7 +493,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte
495493/// further in the [Rust Reference, Paths Chapter][rust_ref].
496494///
497495/// [rust_ref]: https://doc.rust-lang.org/reference/paths.html#crate-1
498- fn get_item_name ( item : & Item < ' _ > ) -> String {
496+ fn get_item_name ( item : & Item < ' _ > ) -> Option < String > {
499497 match item. kind {
500498 ItemKind :: Impl ( im) => {
501499 if let TyKind :: Path ( path) = im. self_ty . kind {
@@ -515,27 +513,19 @@ fn get_item_name(item: &Item<'_>) -> String {
515513 }
516514
517515 segs. push ( String :: new ( ) ) ;
518- segs. join ( "!!" )
516+ Some ( segs. join ( "!!" ) )
519517 } ,
520518 QPath :: TypeRelative ( _, _path_seg) => {
521519 // This case doesn't exist in the clippy tests codebase.
522- String :: new ( )
520+ None
523521 } ,
524- QPath :: LangItem ( _, _) => String :: new ( ) ,
522+ QPath :: LangItem ( _, _) => None ,
525523 }
526524 } else {
527525 // Impls for anything that isn't a named type can be skipped.
528- String :: new ( )
526+ None
529527 }
530528 } ,
531- // FIXME: `Ident::empty` for anonymous items is a bit strange, is there
532- // a better way to do it?
533- _ => item
534- . kind
535- . ident ( )
536- . unwrap_or ( rustc_span:: Ident :: empty ( ) )
537- . name
538- . as_str ( )
539- . to_owned ( ) ,
529+ _ => item. kind . ident ( ) . map ( |name| name. as_str ( ) . to_owned ( ) ) ,
540530 }
541531}
0 commit comments