diff options
author | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-04-07 14:00:30 +0200 |
---|---|---|
committer | Emilio Cobos Álvarez <emilio@crisal.io> | 2018-04-07 14:04:12 +0200 |
commit | 3258c5a949d2ef9290189b4b8fb2af635f1ba86a (patch) | |
tree | be4b63a9a1d04f3bef83427974e82adc54942dab /src | |
parent | b678c8a891087869523f7d95f65b463f78ed4559 (diff) |
Make doc comments nice again.
Diffstat (limited to 'src')
-rw-r--r-- | src/codegen/helpers.rs | 9 | ||||
-rw-r--r-- | src/ir/comment.rs | 12 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs index a73f02ae..f1007c51 100644 --- a/src/codegen/helpers.rs +++ b/src/codegen/helpers.rs @@ -38,7 +38,14 @@ pub mod attributes { } pub fn doc(comment: String) -> quote::Tokens { - quote!(#[doc=#comment]) + // Doc comments are already preprocessed into nice `///` formats by the + // time they get here. Just make sure that we have newlines around it so + // that nothing else gets wrapped into the comment. + let mut tokens = quote! {}; + tokens.append(Term::new("\n", Span::call_site())); + tokens.append(Term::new(&comment, Span::call_site())); + tokens.append(Term::new("\n", Span::call_site())); + tokens } pub fn link_name(name: &str) -> quote::Tokens { diff --git a/src/ir/comment.rs b/src/ir/comment.rs index b3140ffb..afa2a385 100644 --- a/src/ir/comment.rs +++ b/src/ir/comment.rs @@ -54,7 +54,7 @@ fn preprocess_single_lines(comment: &str, indent: usize) -> String { let indent = if is_first { "" } else { &*indent }; is_first = false; let maybe_space = if l.is_empty() { "" } else { " " }; - format!("{}{}{}", indent, maybe_space, l) + format!("{}///{}{}", indent, maybe_space, l) }) .collect(); lines.join("\n") @@ -79,7 +79,7 @@ fn preprocess_multi_line(comment: &str, indent: usize) -> String { let indent = if is_first { "" } else { &*indent }; is_first = false; let maybe_space = if line.is_empty() { "" } else { " " }; - format!("{}{}{}", indent, maybe_space, line) + format!("{}///{}{}", indent, maybe_space, line) }) .collect(); @@ -105,20 +105,20 @@ mod test { #[test] fn processes_single_lines_correctly() { - assert_eq!(preprocess("/// hello", 0), " hello"); - assert_eq!(preprocess("// hello", 0), " hello"); + assert_eq!(preprocess("/// hello", 0), "/// hello"); + assert_eq!(preprocess("// hello", 0), "/// hello"); } #[test] fn processes_multi_lines_correctly() { assert_eq!( preprocess("/** hello \n * world \n * foo \n */", 0), - " hello\n world\n foo" + "/// hello\n/// world\n/// foo" ); assert_eq!( preprocess("/**\nhello\n*world\n*foo\n*/", 0), - " hello\n world\n foo" + "/// hello\n/// world\n/// foo" ); } } |