}
pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
- let say = |s: &str, warn: bool| {
+ let say = |s: &str| {
match (sp, sess) {
(_, None) => panic!("{}", s),
- (Some(sp), Some(sess)) if warn => sess.span_warn(sp, s),
(Some(sp), Some(sess)) => sess.span_err(sp, s),
- (None, Some(sess)) if warn => sess.warn(s),
(None, Some(sess)) => sess.err(s),
}
};
if s.len() == 0 {
- say("crate name must not be empty", false);
- } else if s.contains("-") {
- say(&format!("crate names soon cannot contain hyphens: {}", s), true);
+ say("crate name must not be empty");
}
for c in s.chars() {
if c.is_alphanumeric() { continue }
- if c == '_' || c == '-' { continue }
- say(&format!("invalid character `{}` in crate name: `{}`", c, s), false);
+ if c == '_' { continue }
+ say(&format!("invalid character `{}` in crate name: `{}`", c, s));
}
match sess {
Some(sess) => sess.abort_if_errors(),
-> Option<ast::CrateNum> {
let mut ret = None;
self.sess.cstore.iter_crate_data(|cnum, data| {
- // For now we do a "fuzzy match" on crate names by considering
- // hyphens equal to underscores. This is purely meant to be a
- // transitionary feature while we deprecate the quote syntax of
- // `extern crate` statements.
- if data.name != name.replace("-", "_") {
- return
- }
+ if data.name != name { return }
match hash {
Some(hash) if *hash == data.hash() => { ret = Some(cnum); return }
}
if let Input::File(ref path) = *input {
if let Some(s) = path.file_stem().and_then(|s| s.to_str()) {
- return validate(s.to_string(), None);
+ if s.starts_with("-") {
+ let msg = format!("crate names cannot start with a `-`, but \
+ `{}` has a leading hyphen", s);
+ if let Some(sess) = sess {
+ sess.err(&msg);
+ }
+ } else {
+ return validate(s.replace("-", "_"), None);
+ }
}
}
- "rust-out".to_string()
+ "rust_out".to_string()
}
pub fn build_link_meta(sess: &Session, krate: &ast::Crate,
}
config::CrateTypeExecutable => {
let suffix = &sess.target.target.options.exe_suffix;
- out_filename.with_file_name(&format!("{}{}", libname, suffix))
+ if suffix.len() == 0 {
+ out_filename.to_path_buf()
+ } else {
+ out_filename.with_extension(&suffix[1..])
+ }
}
}
}
// environment to ensure that the target loads the right libraries at
// runtime. It would be a sad day if the *host* libraries were loaded as a
// mistake.
- let mut cmd = Command::new(&outdir.path().join("rust-out"));
+ let mut cmd = Command::new(&outdir.path().join("rust_out"));
let var = DynamicLibrary::envvar();
let newpath = {
let path = env::var_os(var).unwrap_or(OsString::new());
///
/// # Examples
///
- /// extern crate url;
- /// extern crate foo = "bar"; //deprecated
- /// extern crate "bar" as foo;
+ /// extern crate foo;
+ /// extern crate bar as foo;
fn parse_item_extern_crate(&mut self,
- lo: BytePos,
- visibility: Visibility,
- attrs: Vec<Attribute>)
+ lo: BytePos,
+ visibility: Visibility,
+ attrs: Vec<Attribute>)
-> P<Item> {
- let (maybe_path, ident) = match self.token {
- token::Ident(..) => {
- let crate_name = self.parse_ident();
- if self.eat_keyword(keywords::As) {
- (Some(crate_name.name), self.parse_ident())
- } else {
- (None, crate_name)
- }
- },
- token::Literal(token::Str_(..), suf) |
- token::Literal(token::StrRaw(..), suf) => {
- let sp = self.span;
- self.expect_no_suffix(sp, "extern crate name", suf);
- // forgo the internal suffix check of `parse_str` to
- // avoid repeats (this unwrap will always succeed due
- // to the restriction of the `match`)
- let (s, _, _) = self.parse_optional_str().unwrap();
- self.expect_keyword(keywords::As);
- let the_ident = self.parse_ident();
- self.obsolete(sp, ObsoleteSyntax::ExternCrateString);
- let s = token::intern(&s);
- (Some(s), the_ident)
- },
- _ => {
- let span = self.span;
- let token_str = self.this_token_to_string();
- self.span_fatal(span,
- &format!("expected extern crate name but \
- found `{}`",
- token_str));
- }
+ let crate_name = self.parse_ident();
+ let (maybe_path, ident) = if self.eat_keyword(keywords::As) {
+ (Some(crate_name.name), self.parse_ident())
+ } else {
+ (None, crate_name)
};
self.expect(&token::Semi);
+++ /dev/null
-// Copyright 2014 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 crate "" as foo; //~ ERROR: crate name must not be empty
-//~^ WARNING: obsolete syntax
-
-fn main() {}
+++ /dev/null
-// Copyright 2014 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 crate "#a" as bar; //~ ERROR: invalid character `#` in crate name: `#a`
-//~^ WARNING: obsolete syntax
-
-fn main() {}
--- /dev/null
+-include ../tools.mk
+
+all:
+ $(RUSTC) foo-bar.rs
+ [ -f $(TMPDIR)/$(call BIN,foo-bar) ]
+ [ -f $(TMPDIR)/libfoo_bar.rlib ]
--- /dev/null
+// 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.
+
+#![crate_type = "lib"]
+#![crate_type = "bin"]
+
+fn main() {}