diff --git a/src/cargo/util/toml/targets.rs b/src/cargo/util/toml/targets.rs index b86300225fe..81afec90926 100644 --- a/src/cargo/util/toml/targets.rs +++ b/src/cargo/util/toml/targets.rs @@ -634,7 +634,12 @@ fn toml_targets_and_inferred( ) -> Vec { let inferred_targets = inferred_to_toml_targets(inferred); match toml_targets { - None => inferred_targets, + None => + if let Some(false) = autodiscover { + vec![] + } else { + inferred_targets + }, Some(targets) => { let mut targets = targets.clone(); diff --git a/tests/testsuite/run.rs b/tests/testsuite/run.rs index d9d15e2790d..ac4bdb46415 100644 --- a/tests/testsuite/run.rs +++ b/tests/testsuite/run.rs @@ -463,6 +463,28 @@ fn run_example_autodiscover_2018() { .run(); } +#[test] +fn autobins_disables() { + let p = project() + .file( + "Cargo.toml", + r#" + [project] + name = "foo" + version = "0.0.1" + autobins = false + "# + ) + .file("src/lib.rs", "pub mod bin;") + .file("src/bin/mod.rs", "// empty") + .build(); + + p.cargo("run") + .with_status(101) + .with_stderr("[ERROR] a bin target must be available for `cargo run`") + .run(); +} + #[test] fn run_bins() { let p = project()