Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5486,7 +5486,11 @@ impl<'a> Parser<'a> {

if !self.eat(term) {
let token_str = self.this_token_to_string();
return Err(self.fatal(&format!("expected item, found `{}`", token_str)));
let mut err = self.fatal(&format!("expected item, found `{}`", token_str));
if token_str == ";" {
err.note("consider removing the semicolon");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this into a span_suggestion_short(span, msg, "".to_string()), so that the output points at it and tools depending on the RLS can apply the change automatically.

}
return Err(err);
}

let hi = if self.span == syntax_pos::DUMMY_SP {
Expand Down
18 changes: 18 additions & 0 deletions src/test/parse-fail/issue-46186.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// compile-flags: -Z parse-only

struct Struct {
a: usize,
} //~ ERROR expected item, found ';'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is the ;? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lol, good point. Forgot to copy that over

//~| NOTE consider removing the semicolon

fn main() {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you turn this into a ui test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should I go ahead and remove this file from parse-fail then?