Skip to content

Commit

Permalink
Inline find_suffix closure that's only used once
Browse files Browse the repository at this point in the history
  • Loading branch information
camelid committed Mar 29, 2021
1 parent 5497f15 commit 141df6f
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions src/librustdoc/passes/collect_intra_doc_links.rs
Expand Up @@ -1549,23 +1549,6 @@ impl Disambiguator {
fn from_str(link: &str) -> Result<Option<(Self, &str)>, (String, Range<usize>)> {
use Disambiguator::{Kind, Namespace as NS, Primitive};

let find_suffix = || {
let suffixes = [
("!()", DefKind::Macro(MacroKind::Bang)),
("()", DefKind::Fn),
("!", DefKind::Macro(MacroKind::Bang)),
];
for &(suffix, kind) in &suffixes {
if let Some(link) = link.strip_suffix(suffix) {
// Avoid turning `!` or `()` into an empty string
if !link.is_empty() {
return Some((Kind(kind), link));
}
}
}
None
};

if let Some(idx) = link.find('@') {
let (prefix, rest) = link.split_at(idx);
let d = match prefix {
Expand All @@ -1586,7 +1569,20 @@ impl Disambiguator {
};
Ok(Some((d, &rest[1..])))
} else {
Ok(find_suffix())
let suffixes = [
("!()", DefKind::Macro(MacroKind::Bang)),
("()", DefKind::Fn),
("!", DefKind::Macro(MacroKind::Bang)),
];
for &(suffix, kind) in &suffixes {
if let Some(link) = link.strip_suffix(suffix) {
// Avoid turning `!` or `()` into an empty string
if !link.is_empty() {
return Ok(Some((Kind(kind), link)));
}
}
}
Ok(None)
}
}

Expand Down

0 comments on commit 141df6f

Please sign in to comment.