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:
@@ -686,6 +686,16 @@ impl<'a> Parser<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let token::DocComment(kind, style, _) = self.token.kind {
|
if let token::DocComment(kind, style, _) = self.token.kind {
|
||||||
|
// 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`
|
// We have something like `expr //!val` where the user likely meant `expr // !val`
|
||||||
let pos = self.token.span.lo() + BytePos(2);
|
let pos = self.token.span.lo() + BytePos(2);
|
||||||
let span = self.token.span.with_lo(pos).with_hi(pos);
|
let span = self.token.span.with_lo(pos).with_hi(pos);
|
||||||
@@ -701,9 +711,10 @@ impl<'a> Parser<'a> {
|
|||||||
},
|
},
|
||||||
),
|
),
|
||||||
" ".to_string(),
|
" ".to_string(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let sp = if self.token == token::Eof {
|
let sp = if self.token == token::Eof {
|
||||||
// This is EOF; don't want to point at the following char, but rather the last token.
|
// This is EOF; don't want to point at the following char, but rather the last token.
|
||||||
|
|||||||
@@ -0,0 +1,34 @@
|
|||||||
|
//! Check that if the parser suggests converting `///` to a regular comment
|
||||||
|
//! when it appears after a missing comma in an list (e.g. `enum` variants).
|
||||||
|
//!
|
||||||
|
//! Related issue
|
||||||
|
//! - https://github.com/rust-lang/rust/issues/142311
|
||||||
|
|
||||||
|
enum Foo {
|
||||||
|
/// Like the noise a sheep makes
|
||||||
|
Bar
|
||||||
|
/// Like where people drink
|
||||||
|
//~^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `/// Like where people drink`
|
||||||
|
Baa///xxxxxx
|
||||||
|
//~^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx`
|
||||||
|
Baz///xxxxxx
|
||||||
|
//~^ ERROR expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx`
|
||||||
|
}
|
||||||
|
|
||||||
|
fn foo() {
|
||||||
|
let a = [
|
||||||
|
1///xxxxxx
|
||||||
|
//~^ ERROR expected one of `,`, `.`, `;`, `?`, `]`, or an operator, found doc comment `///xxxxxx`
|
||||||
|
2
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
fn bar() {
|
||||||
|
let a = [
|
||||||
|
1,
|
||||||
|
2///xxxxxx
|
||||||
|
//~^ ERROR expected one of `,`, `.`, `?`, `]`, or an operator, found doc comment `///xxxxxx`
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
error: expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `/// Like where people drink`
|
||||||
|
--> $DIR/doc-comment-after-missing-comma-issue-142311.rs:10:5
|
||||||
|
|
|
||||||
|
LL | Bar
|
||||||
|
| -
|
||||||
|
| |
|
||||||
|
| expected one of `(`, `,`, `=`, `{`, or `}`
|
||||||
|
| help: missing `,`
|
||||||
|
LL | /// Like where people drink
|
||||||
|
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ unexpected token
|
||||||
|
|
||||||
|
error: expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx`
|
||||||
|
--> $DIR/doc-comment-after-missing-comma-issue-142311.rs:12:8
|
||||||
|
|
|
||||||
|
LL | Baa///xxxxxx
|
||||||
|
| -^^^^^^^^
|
||||||
|
| |
|
||||||
|
| expected one of `(`, `,`, `=`, `{`, or `}`
|
||||||
|
| help: missing `,`
|
||||||
|
|
||||||
|
error: expected one of `(`, `,`, `=`, `{`, or `}`, found doc comment `///xxxxxx`
|
||||||
|
--> $DIR/doc-comment-after-missing-comma-issue-142311.rs:14:8
|
||||||
|
|
|
||||||
|
LL | Baz///xxxxxx
|
||||||
|
| ^^^^^^^^^ expected one of `(`, `,`, `=`, `{`, or `}`
|
||||||
|
|
|
||||||
|
= help: doc comments must come before what they document, if a comment was intended use `//`
|
||||||
|
= help: enum variants can be `Variant`, `Variant = <integer>`, `Variant(Type, ..., TypeN)` or `Variant { fields: Types }`
|
||||||
|
|
||||||
|
error: expected one of `,`, `.`, `;`, `?`, `]`, or an operator, found doc comment `///xxxxxx`
|
||||||
|
--> $DIR/doc-comment-after-missing-comma-issue-142311.rs:20:10
|
||||||
|
|
|
||||||
|
LL | 1///xxxxxx
|
||||||
|
| ^^^^^^^^^ expected one of `,`, `.`, `;`, `?`, `]`, or an operator
|
||||||
|
|
||||||
|
error: expected one of `,`, `.`, `?`, `]`, or an operator, found doc comment `///xxxxxx`
|
||||||
|
--> $DIR/doc-comment-after-missing-comma-issue-142311.rs:29:10
|
||||||
|
|
|
||||||
|
LL | 2///xxxxxx
|
||||||
|
| ^^^^^^^^^ expected one of `,`, `.`, `?`, `]`, or an operator
|
||||||
|
|
||||||
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
Reference in New Issue
Block a user