Skip to content

Commit e2348c2

Browse files
committed
Auto merge of #5603 - matklad:publish-nightly-features, r=matklad
Allow publishing crates with nightly features closes #5427. cc @rust-lang/cargo: I remember a vigorous debate over publishing crates with nightly Cargo features, but I can't recollect our exact plan of action. The discussion is logged here: https://paper.dropbox.com/doc/Unstable-Cargo-features-JBYMdsUYcO3FyW8Ubkjoz. I think we just need to allow to publish crates with unstable cargo features, for the same reason we allow unstable rust features: you need explicit opt-in, even for deps. This is covered by Cargo tests: https://github.com/rust-lang/cargo/blob/9f097787b04b06cdde4fc42b26a531b22c1b37a6/tests/testsuite/cargo_features.rs#L115-L215. I am not sure if we have ever implemented crates.io side of validation?
2 parents 946ab00 + 39a3709 commit e2348c2

File tree

2 files changed

+9
-12
lines changed

2 files changed

+9
-12
lines changed

src/cargo/ops/registry.rs

-6
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,6 @@ pub struct PublishOpts<'cfg> {
4343
pub fn publish(ws: &Workspace, opts: &PublishOpts) -> CargoResult<()> {
4444
let pkg = ws.current()?;
4545

46-
// Allow publishing if a registry has been provided, or if there are no nightly
47-
// features enabled.
48-
if opts.registry.is_none() && !pkg.manifest().features().activated().is_empty() {
49-
bail!("cannot publish crates which activate nightly-only cargo features to crates.io")
50-
}
51-
5246
if let Some(ref allowed_registries) = *pkg.publish() {
5347
if !match opts.registry {
5448
Some(ref registry) => allowed_registries.contains(registry),

tests/testsuite/cargo_features.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use cargotest::ChannelChanger;
2-
use cargotest::support::{execs, project};
2+
use cargotest::support::{execs, project, publish};
33
use hamcrest::assert_that;
44

55
#[test]
@@ -303,7 +303,9 @@ fn z_flags_rejected() {
303303
}
304304

305305
#[test]
306-
fn publish_rejected() {
306+
fn publish_allowed() {
307+
publish::setup();
308+
307309
let p = project("foo")
308310
.file(
309311
"Cargo.toml",
@@ -319,9 +321,10 @@ fn publish_rejected() {
319321
.file("src/lib.rs", "")
320322
.build();
321323
assert_that(
322-
p.cargo("publish").masquerade_as_nightly_cargo(),
323-
execs().with_status(101).with_stderr(
324-
"error: cannot publish crates which activate nightly-only cargo features to crates.io",
325-
),
324+
p.cargo("publish")
325+
.arg("--index")
326+
.arg(publish::registry().to_string())
327+
.masquerade_as_nightly_cargo(),
328+
execs().with_status(0),
326329
);
327330
}

0 commit comments

Comments
 (0)