Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/ide/src/doc_links/intra_doc_links.rs')
-rw-r--r--crates/ide/src/doc_links/intra_doc_links.rs52
1 files changed, 24 insertions, 28 deletions
diff --git a/crates/ide/src/doc_links/intra_doc_links.rs b/crates/ide/src/doc_links/intra_doc_links.rs
index 13088bdc3b..ebdd4add17 100644
--- a/crates/ide/src/doc_links/intra_doc_links.rs
+++ b/crates/ide/src/doc_links/intra_doc_links.rs
@@ -1,10 +1,10 @@
//! Helper tools for intra doc links.
-const TYPES: ([&str; 9], [&str; 0]) =
- (["type", "struct", "enum", "mod", "trait", "union", "module", "prim", "primitive"], []);
-const VALUES: ([&str; 8], [&str; 1]) =
- (["value", "function", "fn", "method", "const", "static", "mod", "module"], ["()"]);
-const MACROS: ([&str; 2], [&str; 1]) = (["macro", "derive"], ["!"]);
+const TYPES: (&[&str], &[&str]) =
+ (&["type", "struct", "enum", "mod", "trait", "union", "module", "prim", "primitive"], &[]);
+const VALUES: (&[&str], &[&str]) =
+ (&["value", "function", "fn", "method", "const", "static", "mod", "module"], &["()"]);
+const MACROS: (&[&str], &[&str]) = (&["macro", "derive"], &["!"]);
/// Extract the specified namespace from an intra-doc-link if one exists.
///
@@ -17,42 +17,38 @@ pub(super) fn parse_intra_doc_link(s: &str) -> (&str, Option<hir::Namespace>) {
let s = s.trim_matches('`');
[
- (hir::Namespace::Types, (TYPES.0.iter(), TYPES.1.iter())),
- (hir::Namespace::Values, (VALUES.0.iter(), VALUES.1.iter())),
- (hir::Namespace::Macros, (MACROS.0.iter(), MACROS.1.iter())),
+ (hir::Namespace::Types, TYPES),
+ (hir::Namespace::Values, VALUES),
+ (hir::Namespace::Macros, MACROS),
]
.into_iter()
- .find_map(|(ns, (mut prefixes, mut suffixes))| {
- if let Some(prefix) = prefixes.find(|&&prefix| {
+ .find_map(|(ns, (prefixes, suffixes))| {
+ if let Some(prefix) = prefixes.iter().find(|&&prefix| {
s.starts_with(prefix)
&& s.chars().nth(prefix.len()).map_or(false, |c| c == '@' || c == ' ')
}) {
Some((&s[prefix.len() + 1..], ns))
} else {
- suffixes.find_map(|&suffix| s.strip_suffix(suffix).zip(Some(ns)))
+ suffixes.iter().find_map(|&suffix| s.strip_suffix(suffix).zip(Some(ns)))
}
})
.map_or((s, None), |(s, ns)| (s, Some(ns)))
}
pub(super) fn strip_prefixes_suffixes(s: &str) -> &str {
- [
- (TYPES.0.iter(), TYPES.1.iter()),
- (VALUES.0.iter(), VALUES.1.iter()),
- (MACROS.0.iter(), MACROS.1.iter()),
- ]
- .into_iter()
- .find_map(|(mut prefixes, mut suffixes)| {
- if let Some(prefix) = prefixes.find(|&&prefix| {
- s.starts_with(prefix)
- && s.chars().nth(prefix.len()).map_or(false, |c| c == '@' || c == ' ')
- }) {
- Some(&s[prefix.len() + 1..])
- } else {
- suffixes.find_map(|&suffix| s.strip_suffix(suffix))
- }
- })
- .unwrap_or(s)
+ [TYPES, VALUES, MACROS]
+ .into_iter()
+ .find_map(|(prefixes, suffixes)| {
+ if let Some(prefix) = prefixes.iter().find(|&&prefix| {
+ s.starts_with(prefix)
+ && s.chars().nth(prefix.len()).map_or(false, |c| c == '@' || c == ' ')
+ }) {
+ Some(&s[prefix.len() + 1..])
+ } else {
+ suffixes.iter().find_map(|&suffix| s.strip_suffix(suffix))
+ }
+ })
+ .unwrap_or(s)
}
#[cfg(test)]