Skip to content

Commit

Permalink
Fix ICE when misplaced visibility cannot be properly parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
rylev committed Jul 7, 2021
1 parent c5e344f commit 04a9c10
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
8 changes: 7 additions & 1 deletion compiler/rustc_parse/src/parser/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1791,7 +1791,13 @@ impl<'a> Parser<'a> {
if self.check_keyword(kw::Pub) {
let sp = sp_start.to(self.prev_token.span);
if let Ok(snippet) = self.span_to_snippet(sp) {
let vis = self.parse_visibility(FollowedByType::No)?;
let vis = match self.parse_visibility(FollowedByType::No) {
Ok(v) => v,
Err(mut d) => {
d.cancel();
return Err(err);
}
};
let vs = pprust::vis_to_string(&vis);
let vs = vs.trim_end();
err.span_suggestion(
Expand Down
3 changes: 3 additions & 0 deletions src/test/ui/parser/issue-86895.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const pub () {}
//~^ ERROR expected one of `async`, `extern`, `fn`, or `unsafe`
pub fn main() {}
8 changes: 8 additions & 0 deletions src/test/ui/parser/issue-86895.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
error: expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub`
--> $DIR/issue-86895.rs:1:7
|
LL | const pub () {}
| ^^^ expected one of `async`, `extern`, `fn`, or `unsafe`

error: aborting due to previous error

0 comments on commit 04a9c10

Please sign in to comment.