Skip to content

Commit e887e66

Browse files
authored
Rollup merge of rust-lang#94633 - TaKO8Ki:suggest-removing-semicolon-after-derive-attribute, r=cjgillot
Suggest removing a semicolon after derive attributes closes rust-lang#93942
2 parents 7143bc3 + 47d91bc commit e887e66

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

compiler/rustc_parse/src/parser/item.rs

+10
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,16 @@ impl<'a> Parser<'a> {
449449
if end.is_doc_comment() {
450450
err.span_label(end.span, "this doc comment doesn't document anything");
451451
}
452+
if end.meta_kind().is_some() {
453+
if self.token.kind == TokenKind::Semi {
454+
err.span_suggestion_verbose(
455+
self.token.span,
456+
"consider removing this semicolon",
457+
String::new(),
458+
Applicability::MaybeIncorrect,
459+
);
460+
}
461+
}
452462
if let [.., penultimate, _] = attrs {
453463
err.span_label(start.span.to(penultimate.span), "other attributes here");
454464
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#[derive(Debug, Clone)]; //~ERROR expected item after attributes
2+
struct Foo;
3+
4+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
error: expected item after attributes
2+
--> $DIR/attr-with-a-semicolon.rs:1:1
3+
|
4+
LL | #[derive(Debug, Clone)];
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
help: consider removing this semicolon
8+
|
9+
LL - #[derive(Debug, Clone)];
10+
LL + #[derive(Debug, Clone)]
11+
|
12+
13+
error: aborting due to previous error
14+

0 commit comments

Comments
 (0)