Skip to content

Commit fc7caed

Browse files
committed
Rollup merge of rust-lang#48356 - estebank:unsafe-without-braces, r=nikomatsakis
When encountering invalid token after `unsafe`, mention `{` Fix rust-lang#37158.
2 parents 2483d84 + 1aad320 commit fc7caed

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
@@ -6482,6 +6482,8 @@ impl<'a> Parser<'a> {
64826482
&& self.look_ahead(1, |t| *t != token::OpenDelim(token::Brace)) {
64836483
// UNSAFE FUNCTION ITEM
64846484
self.bump(); // `unsafe`
6485+
// `{` is also expected after `unsafe`, in case of error, include it in the diagnostic
6486+
self.check(&token::OpenDelim(token::Brace));
64856487
let abi = if self.eat_keyword(keywords::Extern) {
64866488
self.parse_opt_abi()?.unwrap_or(Abi::C)
64876489
} 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)