fix rust code in comment with a line containing only a hash sign (#3818)
This commit is contained in:
parent
f4bc494153
commit
dbd8936391
3 changed files with 22 additions and 1 deletions
|
|
@ -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)
|
||||
|
|
|
|||
10
tests/source/issue-3751.rs
Normal file
10
tests/source/issue-3751.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// rustfmt-format_code_in_doc_comments: true
|
||||
|
||||
//! Empty pound line
|
||||
//!
|
||||
//! ```rust
|
||||
//! #
|
||||
//! # fn main() {
|
||||
//! foo ( ) ;
|
||||
//! # }
|
||||
//! ```
|
||||
10
tests/target/issue-3751.rs
Normal file
10
tests/target/issue-3751.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
// rustfmt-format_code_in_doc_comments: true
|
||||
|
||||
//! Empty pound line
|
||||
//!
|
||||
//! ```rust
|
||||
//! #
|
||||
//! # fn main() {
|
||||
//! foo();
|
||||
//! # }
|
||||
//! ```
|
||||
Loading…
Add table
Add a link
Reference in a new issue