]> git.lizzy.rs Git - rust.git/blob - src/tools/rust-analyzer/crates/ide-db/src/rust_doc.rs
Auto merge of #102692 - nnethercote:TokenStreamBuilder, r=Aaron1011
[rust.git] / src / tools / rust-analyzer / crates / ide-db / src / rust_doc.rs
1 //! Rustdoc specific doc comment handling
2
3 // stripped down version of https://github.com/rust-lang/rust/blob/392ba2ba1a7d6c542d2459fb8133bebf62a4a423/src/librustdoc/html/markdown.rs#L810-L933
4 pub fn is_rust_fence(s: &str) -> bool {
5     let mut seen_rust_tags = false;
6     let mut seen_other_tags = false;
7
8     let tokens = s
9         .trim()
10         .split(|c| c == ',' || c == ' ' || c == '\t')
11         .map(str::trim)
12         .filter(|t| !t.is_empty());
13
14     for token in tokens {
15         match token {
16             "should_panic" | "no_run" | "ignore" | "allow_fail" => {
17                 seen_rust_tags = !seen_other_tags
18             }
19             "rust" => seen_rust_tags = true,
20             "test_harness" | "compile_fail" => seen_rust_tags = !seen_other_tags || seen_rust_tags,
21             x if x.starts_with("edition") => {}
22             x if x.starts_with('E') && x.len() == 5 => {
23                 if x[1..].parse::<u32>().is_ok() {
24                     seen_rust_tags = !seen_other_tags || seen_rust_tags;
25                 } else {
26                     seen_other_tags = true;
27                 }
28             }
29             _ => seen_other_tags = true,
30         }
31     }
32
33     !seen_other_tags || seen_rust_tags
34 }