]> git.lizzy.rs Git - rust.git/commitdiff
Clarify the error message for malformed `extern crate` statements
authorP1start <rewi-github@whanau.org>
Sat, 16 May 2015 10:35:59 +0000 (22:35 +1200)
committerP1start <rewi-github@whanau.org>
Sat, 16 May 2015 10:35:59 +0000 (22:35 +1200)
Closes #25468.

src/libsyntax/parse/parser.rs
src/test/parse-fail/extern-crate-unexpected-token.rs [new file with mode: 0644]
src/test/parse-fail/extern-expected-fn-or-brace.rs

index 9bf6fa88ba5531d48e61fce29a2fb34548a9f8c9..05d6cbf0a7e5899e15d47aa9f0d7048ef59ada1e 100644 (file)
@@ -5266,11 +5266,7 @@ fn parse_item_(&mut self, attrs: Vec<Attribute>,
                 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) ){
diff --git a/src/test/parse-fail/extern-crate-unexpected-token.rs b/src/test/parse-fail/extern-crate-unexpected-token.rs
new file mode 100644 (file)
index 0000000..2518686
--- /dev/null
@@ -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`
index 7fb7233dc698269ff6f5adcae23a2010a6316678..21cca129658c526b6c1997a62353a5e6f8124814 100644 (file)
@@ -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`