@@ -344,7 +344,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
344
344
struct CurItem < ' a > {
345
345
item : & ' a Item < ' a > ,
346
346
order : usize ,
347
- name : String ,
347
+ name : Option < String > ,
348
348
}
349
349
let mut cur_t: Option < CurItem < ' _ > > = None ;
350
350
@@ -365,28 +365,26 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
365
365
continue ;
366
366
}
367
367
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
+ }
370
382
} else if let ItemKind :: Impl ( _) = item. kind
371
- && ! get_item_name ( item) . is_empty ( )
383
+ && get_item_name ( item) . is_some ( )
372
384
{
373
- rustc_span :: Ident :: empty ( ) // FIXME: a bit strange, is there a better way to do it?
385
+ // keep going below
374
386
} else {
375
387
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:?}" ) ;
390
388
}
391
389
392
390
let item_kind = convert_module_item_kind ( & item. kind ) ;
@@ -495,7 +493,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte
495
493
/// further in the [Rust Reference, Paths Chapter][rust_ref].
496
494
///
497
495
/// [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 > {
499
497
match item. kind {
500
498
ItemKind :: Impl ( im) => {
501
499
if let TyKind :: Path ( path) = im. self_ty . kind {
@@ -515,27 +513,19 @@ fn get_item_name(item: &Item<'_>) -> String {
515
513
}
516
514
517
515
segs. push ( String :: new ( ) ) ;
518
- segs. join ( "!!" )
516
+ Some ( segs. join ( "!!" ) )
519
517
} ,
520
518
QPath :: TypeRelative ( _, _path_seg) => {
521
519
// This case doesn't exist in the clippy tests codebase.
522
- String :: new ( )
520
+ None
523
521
} ,
524
- QPath :: LangItem ( _, _) => String :: new ( ) ,
522
+ QPath :: LangItem ( _, _) => None ,
525
523
}
526
524
} else {
527
525
// Impls for anything that isn't a named type can be skipped.
528
- String :: new ( )
526
+ None
529
527
}
530
528
} ,
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 ( ) ) ,
540
530
}
541
531
}
0 commit comments