Skip to content

Clarify the error message for malformed extern crate statements #25487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5266,11 +5266,7 @@ impl<'a> Parser<'a> {
return Ok(Some(try!(self.parse_item_foreign_mod(lo, opt_abi, visibility, attrs))));
}

let span = self.span;
let token_str = self.this_token_to_string();
return Err(self.span_fatal(span,
&format!("expected `{}` or `fn`, found `{}`", "{",
token_str)))
try!(self.expect_one_of(&[], &[]));
}

if try!(self.eat_keyword_noexpect(keywords::Virtual) ){
Expand Down
11 changes: 11 additions & 0 deletions src/test/parse-fail/extern-crate-unexpected-token.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

extern crte foo; //~ ERROR expected one of `crate`, `fn`, or `{`, found `crte`
2 changes: 1 addition & 1 deletion src/test/parse-fail/extern-expected-fn-or-brace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@
// Verifies that the expected token errors for `extern crate` are
// raised

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