fix rust code in comment with a line containing only a hash sign (#3818)

This commit is contained in:
Stéphane Campinas 2019-10-02 16:58:25 +02:00 committed by Seiichi Uchida
parent f4bc494153
commit dbd8936391
3 changed files with 22 additions and 1 deletions

View file

@ -823,7 +823,8 @@ fn rewrite_comment_inner(
const RUSTFMT_CUSTOM_COMMENT_PREFIX: &str = "//#### ";
fn hide_sharp_behind_comment(s: &str) -> Cow<'_, str> {
if s.trim_start().starts_with("# ") {
let s_trimmed = s.trim();
if s_trimmed.starts_with("# ") || s_trimmed == "#" {
Cow::from(format!("{}{}", RUSTFMT_CUSTOM_COMMENT_PREFIX, s))
} else {
Cow::from(s)

View file

@ -0,0 +1,10 @@
// rustfmt-format_code_in_doc_comments: true
//! Empty pound line
//!
//! ```rust
//! #
//! # fn main() {
//! foo ( ) ;
//! # }
//! ```

View file

@ -0,0 +1,10 @@
// rustfmt-format_code_in_doc_comments: true
//! Empty pound line
//!
//! ```rust
//! #
//! # fn main() {
//! foo();
//! # }
//! ```