Skip to content

Commit dadac15

Browse files
committed
Clarify the error message for malformed extern crate statements
Closes #25468.
1 parent 716f920 commit dadac15

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5266,11 +5266,7 @@ impl<'a> Parser<'a> {
52665266
return Ok(Some(try!(self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs))));
52675267
}
52685268

5269-
let span = self.span;
5270-
let token_str = self.this_token_to_string();
5271-
return Err(self.span_fatal(span,
5272-
&format!("expected `{}` or `fn`, found `{}`", "{",
5273-
token_str)))
5269+
try!(self.expect_one_of(&[], &[]));
52745270
}
52755271

52765272
if try!(self.eat_keyword_noexpect(keywords::Virtual) ){
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2015 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+
extern crte foo; //~ ERROR expected one of `crate`, `fn`, or `{`, found `crte`

src/test/parse-fail/extern-expected-fn-or-brace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
// Verifies that the expected token errors for `extern crate` are
1414
// raised
1515

16-
extern "C" mod foo; //~ERROR expected `{` or `fn`, found `mod`
16+
extern "C" mod foo; //~ERROR expected one of `fn` or `{`, found `mod`

0 commit comments

Comments
 (0)