+ fn guess_macro_braces(&self, macro_name: &str, docs: &str) -> &'static str {
+ let mut votes = [0, 0, 0];
+ for (idx, s) in docs.match_indices(¯o_name) {
+ let (before, after) = (&docs[..idx], &docs[idx + s.len()..]);
+ // Ensure to match the full word
+ if after.starts_with("!")
+ && before
+ .chars()
+ .rev()
+ .next()
+ .map_or(true, |c| c != '_' && !c.is_ascii_alphanumeric())
+ {
+ // It may have spaces before the braces like `foo! {}`
+ match after[1..].chars().find(|&c| !c.is_whitespace()) {
+ Some('{') => votes[0] += 1,
+ Some('[') => votes[1] += 1,
+ Some('(') => votes[2] += 1,
+ _ => {}
+ }
+ }
+ }
+
+ // Insert a space before `{}`.
+ // We prefer the last one when some votes equal.
+ *votes.iter().zip(&[" {$0}", "[$0]", "($0)"]).max_by_key(|&(&vote, _)| vote).unwrap().1
+ }
+