Dont suggest converting /// to regular comment when it appears after missing , in list

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
xizheyin
2025-06-11 15:06:50 +08:00
parent b6685d748f
commit c63665cd73
3 changed files with 105 additions and 17 deletions

View File

@@ -686,23 +686,34 @@ impl<'a> Parser<'a> {
}
if let token::DocComment(kind, style, _) = self.token.kind {
// We have something like `expr //!val` where the user likely meant `expr // !val`
let pos = self.token.span.lo() + BytePos(2);
let span = self.token.span.with_lo(pos).with_hi(pos);
err.span_suggestion_verbose(
span,
format!(
"add a space before {} to write a regular comment",
match (kind, style) {
(token::CommentKind::Line, ast::AttrStyle::Inner) => "`!`",
(token::CommentKind::Block, ast::AttrStyle::Inner) => "`!`",
(token::CommentKind::Line, ast::AttrStyle::Outer) => "the last `/`",
(token::CommentKind::Block, ast::AttrStyle::Outer) => "the last `*`",
},
),
" ".to_string(),
Applicability::MachineApplicable,
);
// This is to avoid suggesting converting a doc comment to a regular comment
// when missing a comma before the doc comment in lists (#142311):
//
// ```
// enum Foo{
// A /// xxxxxxx
// B,
// }
// ```
if !expected.contains(&TokenType::Comma) {
// We have something like `expr //!val` where the user likely meant `expr // !val`
let pos = self.token.span.lo() + BytePos(2);
let span = self.token.span.with_lo(pos).with_hi(pos);
err.span_suggestion_verbose(
span,
format!(
"add a space before {} to write a regular comment",
match (kind, style) {
(token::CommentKind::Line, ast::AttrStyle::Inner) => "`!`",
(token::CommentKind::Block, ast::AttrStyle::Inner) => "`!`",
(token::CommentKind::Line, ast::AttrStyle::Outer) => "the last `/`",
(token::CommentKind::Block, ast::AttrStyle::Outer) => "the last `*`",
},
),
" ".to_string(),
Applicability::MaybeIncorrect,
);
}
}
let sp = if self.token == token::Eof {