mirror of
https://github.com/rust-lang/rust.git
synced 2024-10-31 22:41:50 +00:00
Fix ICE when misplaced visibility cannot be properly parsed
This commit is contained in:
parent
c5e344f774
commit
04a9c10fc2
@ -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(
|
||||
|
3
src/test/ui/parser/issue-86895.rs
Normal file
3
src/test/ui/parser/issue-86895.rs
Normal file
@ -0,0 +1,3 @@
|
||||
const pub () {}
|
||||
//~^ ERROR expected one of `async`, `extern`, `fn`, or `unsafe`
|
||||
pub fn main() {}
|
8
src/test/ui/parser/issue-86895.stderr
Normal file
8
src/test/ui/parser/issue-86895.stderr
Normal file
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user