Skip to content

Commit f33edd2

Browse files
authored
Rollup merge of rust-lang#46258 - colinmarsh19:master, r=estebank
Remove semicolon note In reference to issue rust-lang#46186 r? @estebank First time doing a pull request, if there are any suggestions on how to improve this please let me know. @jjolly
2 parents a60ffa0 + 096e698 commit f33edd2

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

src/libsyntax/parse/parser.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -5486,7 +5486,12 @@ impl<'a> Parser<'a> {
54865486

54875487
if !self.eat(term) {
54885488
let token_str = self.this_token_to_string();
5489-
return Err(self.fatal(&format!("expected item, found `{}`", token_str)));
5489+
let mut err = self.fatal(&format!("expected item, found `{}`", token_str));
5490+
let msg = "consider removing this semicolon";
5491+
if token_str == ";" {
5492+
err.span_suggestion_short(self.span, msg, "".to_string());
5493+
}
5494+
return Err(err);
54905495
}
54915496

54925497
let hi = if self.span == syntax_pos::DUMMY_SP {

src/test/ui/issue-46186.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
struct Struct {
12+
a: usize,
13+
}; //~ ERROR expected item, found `;`
14+
15+
fn main() {}

src/test/ui/issue-46186.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected item, found `;`
2+
--> $DIR/issue-46186.rs:13:2
3+
|
4+
13 | }; //~ ERROR expected item, found `;`
5+
| ^ help: consider removing this semicolon
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)