use term::color::BLACK;
use core::Workspace;
+use ops::is_bad_artifact_name;
use util::{GitRepo, HgRepo, PijulRepo, CargoResult, human, ChainError, internal};
use util::{Config, paths};
}
}
-fn check_name(name: &str) -> CargoResult<()> {
+fn check_name(name: &str, is_bin: bool) -> CargoResult<()> {
// Ban keywords + test list found at
// https://doc.rust-lang.org/grammar.html#keywords
"super", "test", "trait", "true", "type", "typeof",
"unsafe", "unsized", "use", "virtual", "where",
"while", "yield"];
- if blacklist.contains(&name) {
+ if blacklist.contains(&name) || (is_bin && is_bad_artifact_name(name)) {
bail!("The name `{}` cannot be used as a crate name\n\
use --name to override crate name",
name)
}
let name = get_name(&path, &opts, config)?;
- check_name(name)?;
+ check_name(name, opts.bin)?;
let mkopts = MkOptions {
version_control: opts.version_control,
}
let name = get_name(&path, &opts, config)?;
- check_name(name)?;
+ check_name(name, opts.bin)?;
let mut src_paths_types = vec![];
_lock: FileLock,
}
+pub fn is_bad_artifact_name(name: &str) -> bool {
+ ["deps", "examples", "build", "native", "incremental"]
+ .iter()
+ .find(|&&reserved| reserved == name)
+ .is_some()
+}
+
impl Layout {
pub fn new(ws: &Workspace,
triple: Option<&str>,
pub use self::compilation::Compilation;
pub use self::context::{Context, Unit};
pub use self::custom_build::{BuildOutput, BuildMap, BuildScripts};
+pub use self::layout::is_bad_artifact_name;
mod compilation;
mod context;
pub use self::cargo_compile::{CompileFilter, CompileMode, MessageFormat, Packages};
pub use self::cargo_read_manifest::{read_manifest,read_package,read_packages};
pub use self::cargo_rustc::{compile_targets, Compilation, Kind, Unit};
-pub use self::cargo_rustc::Context;
+pub use self::cargo_rustc::{Context, is_bad_artifact_name};
pub use self::cargo_rustc::{BuildOutput, BuildConfig, TargetConfig};
pub use self::cargo_rustc::{Executor, DefaultExecutor};
pub use self::cargo_run::run;
use core::{EitherManifest, VirtualManifest};
use core::dependency::{Kind, Platform};
use core::manifest::{LibKind, Profile, ManifestMetadata};
+use ops::is_bad_artifact_name;
use sources::CRATES_IO;
use util::{self, CargoResult, human, ToUrl, ToSemver, ChainError, Config};
None => inferred_bin_targets(&project.name, layout)
};
- let blacklist = vec!["build", "deps", "examples", "native"];
-
for bin in bins.iter() {
- if blacklist.iter().find(|&x| *x == bin.name()) != None {
+ if is_bad_artifact_name(&bin.name()) {
bail!("the binary target name `{}` is forbidden",
bin.name())
}
use cargo::util::process;
use cargotest::is_nightly;
use cargotest::support::paths::CargoPathExt;
-use cargotest::support::registry::Package;
use cargotest::support::{project, execs, basic_bin_manifest, basic_lib_manifest};
use hamcrest::{assert_that, existing_file};
use --name to override crate name"));
}
+#[test]
+fn reserved_binary_name() {
+ assert_that(cargo_process("new").arg("--bin").arg("incremental"),
+ execs().with_status(101)
+ .with_stderr("\
+[ERROR] The name `incremental` cannot be used as a crate name\n\
+use --name to override crate name"));
+}
+
#[test]
fn keyword_name() {
assert_that(cargo_process("new").arg("pub"),