rustc: Remove support for hyphens in crate names
This commit removes parser support for `extern crate "foo" as bar` as the renamed crate is now required to be an identifier. Additionally this commit enables hard errors on crate names that contain hyphens in them, they must now solely contain alphanumeric characters or underscores. If the crate name is inferred from the file name, however, the file name `foo-bar.rs` will have the crate name inferred as `foo_bar`. If a binary is being emitted it will have the name `foo-bar` and a library will have the name `libfoo_bar.rlib`. This commit is a breaking change for a number of reasons: * Old syntax is being removed. This was previously only issuing warnings. * The output for the compiler when input is received on stdin is now `rust_out` instead of `rust-out`. * The crate name for a crate in the file `foo-bar.rs` is now `foo_bar` which can affect infrastructure such as logging. [breaking-change]
This commit is contained in:
parent
36ef29abf7
commit
b24a3b8201
7 changed files with 40 additions and 73 deletions
|
@ -4977,46 +4977,19 @@ impl<'a> Parser<'a> {
|
|||
///
|
||||
/// # 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);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue