Skip to content

Commit 1aad320

Browse files
committed
When encountering invalid token after unsafe, mention {
1 parent 1670a53 commit 1aad320

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/libsyntax/parse/parser.rs

+2
Original file line numberDiff line numberDiff line change
@@ -6469,6 +6469,8 @@ impl<'a> Parser<'a> {
64696469
&& self.look_ahead(1, |t| *t != token::OpenDelim(token::Brace)) {
64706470
// UNSAFE FUNCTION ITEM
64716471
self.bump(); // `unsafe`
6472+
// `{` is also expected after `unsafe`, in case of error, include it in the diagnostic
6473+
self.check(&token::OpenDelim(token::Brace));
64726474
let abi = if self.eat_keyword(keywords::Extern) {
64736475
self.parse_opt_abi()?.unwrap_or(Abi::C)
64746476
} else {
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2018 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+
fn main() {
12+
unsafe //{
13+
std::mem::transmute::<f32, u32>(1.0);
14+
//}
15+
}
16+
//~^^^ ERROR expected one of `extern`, `fn`, or `{`, found `std`
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: expected one of `extern`, `fn`, or `{`, found `std`
2+
--> $DIR/unsafe-block-without-braces.rs:13:9
3+
|
4+
12 | unsafe //{
5+
| - expected one of `extern`, `fn`, or `{` here
6+
13 | std::mem::transmute::<f32, u32>(1.0);
7+
| ^^^ unexpected token
8+
9+
error: aborting due to previous error
10+

0 commit comments

Comments
 (0)