Skip to content

four_forward_slashes does not know that doc comments cannot contain "bare CR" #15174

Open
@matthiaskrgr

Description

@matthiaskrgr

Using the following flags

--force-warn clippy::four_forward_slashes

this code:

//@ run-pass
//// nondoc comment with bare CR: '
'

//@ run-pass
// ignore-tidy-cr
// nondoc comment with bare CR: '
'

fn main() {
}

caused the following diagnostics:

    Checking _D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9 v0.1.0 (/tmp/icemaker_global_tempdir.EuHmIYit9wj1/icemaker_clippyfix_tempdir.qMWSJuzry655/_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9)
warning: this item has comments with 4 forward slashes (`////`). These look like doc comments, but they aren't
 --> src/main.rs:2:1
  |
2 | / //// nondoc comment with bare CR: '␍'
... |
8 | | fn main() {
  | |_^
  |
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#four_forward_slashes
  = note: requested on the command line with `--force-warn clippy::four-forward-slashes`
help: make this a doc comment by removing one `/`
  |
2 - //// nondoc comment with bare CR: '␍'
3 - 
2 + /// nondoc comment with bare CR: '␍'
  |

warning: `_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9` (bin "_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9") generated 1 warning (run `cargo clippy --fix --bin "_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9"` to apply 1 suggestion)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.11s

However after applying these diagnostics, the resulting code:

//@ run-pass
/// nondoc comment with bare CR: '
'

//@ run-pass
// ignore-tidy-cr
// nondoc comment with bare CR: '
'

fn main() {
}

no longer compiled:

    Checking _D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9 v0.1.0 (/tmp/icemaker_global_tempdir.EuHmIYit9wj1/icemaker_clippyfix_tempdir.qMWSJuzry655/_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9)
error: bare CR not allowed in doc-comment
 --> src/main.rs:2:35
  |
2 | /// nondoc comment with bare CR: '␍'
  |                                   ^

error: could not compile `_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9` (bin "_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9") due to 1 previous error
warning: build failed, waiting for other jobs to finish...
error: could not compile `_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9` (bin "_D6FF14B02D28EA9D365F35DE306FF69BA4F6AE8E8B6823C41A36C655587E9BC9" test) due to 1 previous error

Version:

rustc 1.90.0-nightly (5e749eb66 2025-06-29)
binary: rustc
commit-hash: 5e749eb66f93ee998145399fbdde337e57cd72ef
commit-date: 2025-06-29
host: x86_64-unknown-linux-gnu
release: 1.90.0-nightly
LLVM version: 20.1.7

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions