diff --git a/src/cargo/core/features.rs b/src/cargo/core/features.rs index 06f9d5741..d18aad6a1 100644 --- a/src/cargo/core/features.rs +++ b/src/cargo/core/features.rs @@ -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 } diff --git a/src/cargo/core/mod.rs b/src/cargo/core/mod.rs index 18b3b7c5a..3312ba345 100644 --- a/src/cargo/core/mod.rs +++ b/src/cargo/core/mod.rs @@ -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}; diff --git a/src/cargo/ops/cargo_run.rs b/src/cargo/ops/cargo_run.rs index aea9a9b19..75267183b 100644 --- a/src/cargo/ops/cargo_run.rs +++ b/src/cargo/ops/cargo_run.rs @@ -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 \ diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index 2ead4d61b..bd99175f9 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -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]