Skip to content

Commit de403ef

Browse files
authored
Rollup merge of rust-lang#86932 - rylev:fix-ice-86895, r=estebank
Fix ICE when misplaced visibility cannot be properly parsed Fixes rust-lang#86895 The issue was that a failure to parse the visibility was causing the original error to be dropped before being emitted. The resulting error isn't quite as nice as when the visibility is parsed properly, but I'm not sure which error to prioritize here. Displaying both errors might be too confusing. r? ``@estebank``
2 parents 8445192 + 04a9c10 commit de403ef

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

compiler/rustc_parse/src/parser/item.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1791,7 +1791,13 @@ impl<'a> Parser<'a> {
17911791
if self.check_keyword(kw::Pub) {
17921792
let sp = sp_start.to(self.prev_token.span);
17931793
if let Ok(snippet) = self.span_to_snippet(sp) {
1794-
let vis = self.parse_visibility(FollowedByType::No)?;
1794+
let vis = match self.parse_visibility(FollowedByType::No) {
1795+
Ok(v) => v,
1796+
Err(mut d) => {
1797+
d.cancel();
1798+
return Err(err);
1799+
}
1800+
};
17951801
let vs = pprust::vis_to_string(&vis);
17961802
let vs = vs.trim_end();
17971803
err.span_suggestion(

src/test/ui/parser/issue-86895.rs

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const pub () {}
2+
//~^ ERROR expected one of `async`, `extern`, `fn`, or `unsafe`
3+
pub fn main() {}

src/test/ui/parser/issue-86895.stderr

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: expected one of `async`, `extern`, `fn`, or `unsafe`, found keyword `pub`
2+
--> $DIR/issue-86895.rs:1:7
3+
|
4+
LL | const pub () {}
5+
| ^^^ expected one of `async`, `extern`, `fn`, or `unsafe`
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)