Auto merge of #5751 - RalfJung:default-run, r=alexcrichton

cargo run: on nightly, advertise the default-run feature
This commit is contained in:
bors 2018-07-21 23:03:13 +00:00
commit b4a245e6f4
4 changed files with 34 additions and 9 deletions

View File

@ -392,7 +392,7 @@ thread_local!(
/// - this is an `#[test]` that called `enable_nightly_features`
/// - this is a integration test that uses `ProcessBuilder`
/// that called `masquerade_as_nightly_cargo`
fn nightly_features_allowed() -> bool {
pub fn nightly_features_allowed() -> bool {
if ENABLE_NIGHTLY_FEATURES.with(|c| c.get()) {
return true
}

View File

@ -1,6 +1,10 @@
pub use self::dependency::Dependency;
pub use self::features::{CliUnstable, Edition, Feature, Features};
pub use self::features::{maybe_allow_nightly_features, enable_nightly_features};
pub use self::features::{
maybe_allow_nightly_features,
enable_nightly_features,
nightly_features_allowed
};
pub use self::manifest::{EitherManifest, VirtualManifest};
pub use self::manifest::{LibKind, Manifest, Target, TargetKind};
pub use self::package::{Package, PackageSet};

View File

@ -2,7 +2,7 @@ use std::path::Path;
use ops;
use util::{self, CargoResult, ProcessError};
use core::{TargetKind, Workspace};
use core::{TargetKind, Workspace, nightly_features_allowed};
pub fn run(
ws: &Workspace,
@ -53,12 +53,22 @@ pub fn run(
if bins.len() > 1 {
if !options.filter.is_specific() {
let names: Vec<&str> = bins.into_iter().map(|bin| bin.0).collect();
bail!(
"`cargo run` requires that a project only have one \
executable; use the `--bin` option to specify which one \
to run\navailable binaries: {}",
names.join(", ")
)
if nightly_features_allowed() {
bail!(
"`cargo run` could not determine which binary to run. \
Use the `--bin` option to specify a binary, \
or (on nightly) the `default-run` manifest key.\n\
available binaries: {}",
names.join(", ")
)
} else {
bail!(
"`cargo run` requires that a project only have one \
executable; use the `--bin` option to specify which one \
to run\navailable binaries: {}",
names.join(", ")
)
}
} else {
bail!(
"`cargo run` can run at most one executable, but \

View File

@ -282,6 +282,17 @@ fn too_many_bins() {
to specify which one to run\navailable binaries: [..]\n",
),
);
assert_that(
p.cargo("run").masquerade_as_nightly_cargo(),
// Using [..] here because the order is not stable
execs().with_status(101).with_stderr(
"[ERROR] `cargo run` could not determine which binary to run. \
Use the `--bin` option to specify a binary, or (on \
nightly) the `default-run` manifest key.\
\navailable binaries: [..]\n",
),
);
}
#[test]