diff --git a/src/librustc/metadata/creader.rs b/src/librustc/metadata/creader.rs index 4c123b55e8e5..46155925b3c7 100644 --- a/src/librustc/metadata/creader.rs +++ b/src/librustc/metadata/creader.rs @@ -81,6 +81,8 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option) { }; 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 } diff --git a/src/test/run-make/weird-output-filenames/Makefile b/src/test/run-make/weird-output-filenames/Makefile index 5d6e629ffc1d..3d57a2263e1e 100644 --- a/src/test/run-make/weird-output-filenames/Makefile +++ b/src/test/run-make/weird-output-filenames/Makefile @@ -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:"