Skip to content

Commit

Permalink
Disallow crate names with leading hyphens
Browse files Browse the repository at this point in the history
Leading hyphens already don't work (#22661), so no code should break
from this change.

Closes #22661.
  • Loading branch information
lambda-fairy committed Feb 22, 2015
1 parent 2b01a37 commit a7594f2
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/librustc/metadata/creader.rs
Expand Up @@ -81,11 +81,13 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
};
if s.len() == 0 {
err("crate name must not be empty");
} else if s.char_at(0) == '-' {
err(&format!("crate name cannot start with a hyphen: {}", s));
}
for c in s.chars() {
if c.is_alphanumeric() { continue }
if c == '_' || c == '-' { continue }
err(&format!("invalid character `{}` in crate name: `{}`", c, s)[]);
err(&format!("invalid character `{}` in crate name: `{}`", c, s));
}
match sess {
Some(sess) => sess.abort_if_errors(),
Expand Down
3 changes: 3 additions & 0 deletions src/test/run-make/weird-output-filenames/Makefile
Expand Up @@ -10,3 +10,6 @@ all:
cp foo.rs $(TMPDIR)/+foo+bar
$(RUSTC) $(TMPDIR)/+foo+bar 2>&1 \
| grep "invalid character.*in crate name:"
cp foo.rs $(TMPDIR)/-foo.rs
$(RUSTC) $(TMPDIR)/-foo.rs 2>&1 \
| grep "crate name cannot start with a hyphen:"

0 comments on commit a7594f2

Please sign in to comment.