Skip to content

Commit 822b931

Browse files
committed
Avoid a kw::Empty usage.
`Option<Symbol>` is a much nicer and idiomatic way of representing "no name" using empty symbols. And it works naturally for the item ordering checking because `None < Some(_)` just like the empty string compares less than all non-empty strings. changelog: none
1 parent 529bb5f commit 822b931

File tree

1 file changed

+8
-16
lines changed

1 file changed

+8
-16
lines changed

Diff for: clippy_lints/src/arbitrary_source_item_ordering.rs

+8-16
Original file line numberDiff line numberDiff line change
@@ -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

@@ -368,7 +368,7 @@ impl<'tcx> LateLintPass<'tcx> for ArbitrarySourceItemOrdering {
368368
let ident = if let Some(ident) = item.kind.ident() {
369369
ident
370370
} else if let ItemKind::Impl(_) = item.kind
371-
&& !get_item_name(item).is_empty()
371+
&& get_item_name(item).is_some()
372372
{
373373
rustc_span::Ident::empty() // FIXME: a bit strange, is there a better way to do it?
374374
} else {
@@ -495,7 +495,7 @@ fn convert_module_item_kind(value: &ItemKind<'_>) -> SourceItemOrderingModuleIte
495495
/// further in the [Rust Reference, Paths Chapter][rust_ref].
496496
///
497497
/// [rust_ref]: https://doc.rust-lang.org/reference/paths.html#crate-1
498-
fn get_item_name(item: &Item<'_>) -> String {
498+
fn get_item_name(item: &Item<'_>) -> Option<String> {
499499
match item.kind {
500500
ItemKind::Impl(im) => {
501501
if let TyKind::Path(path) = im.self_ty.kind {
@@ -515,27 +515,19 @@ fn get_item_name(item: &Item<'_>) -> String {
515515
}
516516

517517
segs.push(String::new());
518-
segs.join("!!")
518+
Some(segs.join("!!"))
519519
},
520520
QPath::TypeRelative(_, _path_seg) => {
521521
// This case doesn't exist in the clippy tests codebase.
522-
String::new()
522+
None
523523
},
524-
QPath::LangItem(_, _) => String::new(),
524+
QPath::LangItem(_, _) => None,
525525
}
526526
} else {
527527
// Impls for anything that isn't a named type can be skipped.
528-
String::new()
528+
None
529529
}
530530
},
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(),
531+
_ => item.kind.ident().map(|name| name.as_str().to_owned()),
540532
}
541533
}

0 commit comments

Comments
 (0)