Skip to content

Commit 2c99f65

Browse files
committed
Update nightly failure notification.
1 parent 3ebb5f1 commit 2c99f65

File tree

13 files changed

+339
-105
lines changed

13 files changed

+339
-105
lines changed

src/cargo/core/compiler/context/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<'a, 'cfg> Context<'a, 'cfg> {
470470
If this looks unexpected, it may be a bug in Cargo. Please file a bug report at\n\
471471
https://github.com/rust-lang/cargo/issues/ with as much information as you\n\
472472
can provide.\n\
473-
{} running on `{}` target `{}`\n\
473+
cargo {} running on `{}` target `{}`\n\
474474
First unit: {:?}\n\
475475
Second unit: {:?}",
476476
describe_collision(unit, other_unit, path),

src/cargo/core/features.rs

Lines changed: 94 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@
7878
//!
7979
//! 1. Update the feature to be stable, based on the kind of feature:
8080
//! 1. `cargo-features`: Change the feature to `stable` in the `features!`
81-
//! macro below.
81+
//! macro below, and include the version and a URL for the documentation.
8282
//! 2. `-Z unstable-options`: Find the call to `fail_if_stable_opt` and
8383
//! remove it. Be sure to update the man pages if necessary.
8484
//! 3. `-Z` flag: Change the parsing code in [`CliUnstable::add`][CliUnstable]
@@ -87,13 +87,13 @@
8787
//! necessary.
8888
//! 2. Remove `masquerade_as_nightly_cargo` from any tests, and remove
8989
//! `cargo-features` from `Cargo.toml` test files if any.
90-
//! 3. Remove the docs from unstable.md and update the redirect at the bottom
91-
//! of that page. Update the rest of the documentation to add the new
92-
//! feature.
90+
//! 3. Update the docs in unstable.md to move the section to the bottom
91+
//! and summarize it similar to the other entries. Update the rest of the
92+
//! documentation to add the new feature.
9393
9494
use std::collections::BTreeSet;
9595
use std::env;
96-
use std::fmt;
96+
use std::fmt::{self, Write};
9797
use std::str::FromStr;
9898

9999
use anyhow::{bail, Error};
@@ -130,13 +130,22 @@ pub enum Edition {
130130
// - Gate on that new feature in TomlManifest::to_real_manifest.
131131
// - Update the shell completion files.
132132
// - Update any failing tests (hopefully there are very few).
133+
// - Update unstable.md to add a new section for this new edition (see
134+
// https://github.com/rust-lang/cargo/blob/3ebb5f15a940810f250b68821149387af583a79e/src/doc/src/reference/unstable.md?plain=1#L1238-L1264
135+
// as an example).
133136
//
134137
// Stabilization instructions:
135138
// - Set LATEST_UNSTABLE to None.
136139
// - Set LATEST_STABLE to the new version.
137140
// - Update `is_stable` to `true`.
138141
// - Set the editionNNNN feature to stable in the features macro below.
139142
// - Update the man page for the --edition flag.
143+
// - Update unstable.md to move the edition section to the bottom.
144+
// - Update the documentation:
145+
// - Update any features impacted by the edition.
146+
// - Update manifest.md#the-edition-field.
147+
// - Update the --edition flag (options-new.md).
148+
// - Rebuild man pages.
140149
impl Edition {
141150
/// The latest edition that is unstable.
142151
///
@@ -279,6 +288,7 @@ macro_rules! features {
279288
$($feature: bool,)*
280289
activated: Vec<String>,
281290
nightly_features_allowed: bool,
291+
is_local: bool,
282292
}
283293

284294
impl Feature {
@@ -362,7 +372,7 @@ features! {
362372
(stable, rename_dependency, "1.31", "reference/specifying-dependencies.html#renaming-dependencies-in-cargotoml"),
363373

364374
// Whether a lock file is published with this crate
365-
(removed, publish_lockfile, "", PUBLISH_LOCKFILE_REMOVED),
375+
(removed, publish_lockfile, "1.37", "reference/unstable.html#publish-lockfile"),
366376

367377
// Overriding profiles for dependencies.
368378
(stable, profile_overrides, "1.41", "reference/profiles.html#overrides"),
@@ -395,14 +405,6 @@ features! {
395405
(unstable, per_package_target, "", "reference/unstable.html#per-package-target"),
396406
}
397407

398-
const PUBLISH_LOCKFILE_REMOVED: &str = "The publish-lockfile key in Cargo.toml \
399-
has been removed. The Cargo.lock file is always included when a package is \
400-
published if the package contains a binary target. `cargo install` requires \
401-
the `--locked` flag to use the Cargo.lock file.\n\
402-
See https://doc.rust-lang.org/cargo/commands/cargo-package.html and \
403-
https://doc.rust-lang.org/cargo/commands/cargo-install.html for more \
404-
information.";
405-
406408
pub struct Feature {
407409
name: &'static str,
408410
stability: Status,
@@ -416,9 +418,11 @@ impl Features {
416418
features: &[String],
417419
config: &Config,
418420
warnings: &mut Vec<String>,
421+
is_local: bool,
419422
) -> CargoResult<Features> {
420423
let mut ret = Features::default();
421424
ret.nightly_features_allowed = config.nightly_features_allowed;
425+
ret.is_local = is_local;
422426
for feature in features {
423427
ret.add(feature, config, warnings)?;
424428
ret.activated.push(feature.to_string());
@@ -433,6 +437,7 @@ impl Features {
433437
warnings: &mut Vec<String>,
434438
) -> CargoResult<()> {
435439
let nightly_features_allowed = self.nightly_features_allowed;
440+
let is_local = self.is_local;
436441
let (slot, feature) = match self.status(feature_name) {
437442
Some(p) => p,
438443
None => bail!("unknown cargo feature `{}`", feature_name),
@@ -460,15 +465,19 @@ impl Features {
460465

461466
match feature.stability {
462467
Status::Stable => {
463-
let warning = format!(
464-
"the cargo feature `{}` has been stabilized in the {} \
465-
release and is no longer necessary to be listed in the \
466-
manifest\n {}",
467-
feature_name,
468-
feature.version,
469-
see_docs()
470-
);
471-
warnings.push(warning);
468+
// The user can't do anything about non-local packages.
469+
// Warnings are usually suppressed, but just being cautious here.
470+
if is_local {
471+
let warning = format!(
472+
"the cargo feature `{}` has been stabilized in the {} \
473+
release and is no longer necessary to be listed in the \
474+
manifest\n {}",
475+
feature_name,
476+
feature.version,
477+
see_docs()
478+
);
479+
warnings.push(warning);
480+
}
472481
}
473482
Status::Unstable if !nightly_features_allowed => bail!(
474483
"the cargo feature `{}` requires a nightly version of \
@@ -490,13 +499,27 @@ impl Features {
490499
}
491500
}
492501
}
493-
Status::Removed => bail!(
494-
"the cargo feature `{}` has been removed\n\
495-
Remove the feature from Cargo.toml to remove this error.\n\
496-
{}",
497-
feature_name,
498-
feature.docs
499-
),
502+
Status::Removed => {
503+
let mut msg = format!(
504+
"the cargo feature `{}` has been removed in the {} release\n\n",
505+
feature_name, feature.version
506+
);
507+
if self.is_local {
508+
drop(writeln!(
509+
msg,
510+
"Remove the feature from Cargo.toml to remove this error."
511+
));
512+
} else {
513+
drop(writeln!(
514+
msg,
515+
"This package cannot be used with this version of Cargo, \
516+
as the unstable feature `{}` is no longer supported.",
517+
feature_name
518+
));
519+
}
520+
drop(writeln!(msg, "{}", see_docs()));
521+
bail!(msg);
522+
}
500523
}
501524

502525
*slot = true;
@@ -510,30 +533,50 @@ impl Features {
510533

511534
pub fn require(&self, feature: &Feature) -> CargoResult<()> {
512535
if feature.is_enabled(self) {
513-
Ok(())
514-
} else {
515-
let feature = feature.name.replace("_", "-");
516-
let mut msg = format!("feature `{}` is required", feature);
517-
518-
if self.nightly_features_allowed {
519-
let s = format!(
520-
"\n\nconsider adding `cargo-features = [\"{0}\"]` \
521-
to the manifest",
522-
feature
523-
);
524-
msg.push_str(&s);
536+
return Ok(());
537+
}
538+
let feature_name = feature.name.replace("_", "-");
539+
let mut msg = format!(
540+
"feature `{}` is required\n\
541+
\n\
542+
The package requires the Cargo feature called `{}`, but \
543+
that feature is not stabilized in this version of Cargo ({}).\n\
544+
",
545+
feature_name,
546+
feature_name,
547+
crate::version(),
548+
);
549+
550+
if self.nightly_features_allowed {
551+
if self.is_local {
552+
drop(writeln!(
553+
msg,
554+
"Consider adding `cargo-features = [\"{}\"]` \
555+
to the top of Cargo.toml (above the [package] table) \
556+
to tell Cargo you are opting in to use this unstable feature.",
557+
feature_name
558+
));
525559
} else {
526-
let s = format!(
527-
"\n\n\
528-
this Cargo does not support nightly features, but if you\n\
529-
switch to nightly channel you can add\n\
530-
`cargo-features = [\"{}\"]` to enable this feature",
531-
feature
532-
);
533-
msg.push_str(&s);
560+
drop(writeln!(
561+
msg,
562+
"Consider trying a more recent nightly release."
563+
));
534564
}
535-
bail!("{}", msg);
565+
} else {
566+
drop(writeln!(
567+
msg,
568+
"Consider trying a newer version of Cargo \
569+
(this may require the nightly release)."
570+
));
536571
}
572+
drop(writeln!(
573+
msg,
574+
"See https://doc.rust-lang.org/nightly/cargo/{} for more information \
575+
about the status of this feature.",
576+
feature.docs
577+
));
578+
579+
bail!("{}", msg);
537580
}
538581

539582
pub fn is_enabled(&self, feature: &Feature) -> bool {

src/cargo/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub struct VersionInfo {
5252

5353
impl fmt::Display for VersionInfo {
5454
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
55-
write!(f, "cargo {}.{}.{}", self.major, self.minor, self.patch)?;
55+
write!(f, "{}.{}.{}", self.major, self.minor, self.patch)?;
5656
if let Some(channel) = self.cfg_info.as_ref().map(|ci| &ci.release_channel) {
5757
if channel != "stable" {
5858
write!(f, "-{}", channel)?;
@@ -106,7 +106,7 @@ pub fn display_error(err: &Error, shell: &mut Shell) {
106106
"we would appreciate a bug report: https://github.com/rust-lang/cargo/issues/",
107107
),
108108
);
109-
drop(shell.note(format!("{}", version())));
109+
drop(shell.note(format!("cargo {}", version())));
110110
// Once backtraces are stabilized, this should print out a backtrace
111111
// if it is available.
112112
}

src/cargo/ops/registry.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,7 @@ pub fn configure_http_handle(config: &Config, handle: &mut Easy) -> CargoResult<
538538
if let Some(user_agent) = &http.user_agent {
539539
handle.useragent(user_agent)?;
540540
} else {
541-
handle.useragent(&version().to_string())?;
541+
handle.useragent(&format!("cargo {}", version()))?;
542542
}
543543

544544
fn to_ssl_version(s: &str) -> CargoResult<SslVersion> {

src/cargo/util/toml/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1042,7 +1042,7 @@ impl TomlManifest {
10421042
// Parse features first so they will be available when parsing other parts of the TOML.
10431043
let empty = Vec::new();
10441044
let cargo_features = me.cargo_features.as_ref().unwrap_or(&empty);
1045-
let features = Features::new(cargo_features, config, &mut warnings)?;
1045+
let features = Features::new(cargo_features, config, &mut warnings, source_id.is_path())?;
10461046

10471047
let project = me.project.as_ref().or_else(|| me.package.as_ref());
10481048
let project = project.ok_or_else(|| anyhow!("no `package` section found"))?;
@@ -1451,7 +1451,7 @@ impl TomlManifest {
14511451
let mut deps = Vec::new();
14521452
let empty = Vec::new();
14531453
let cargo_features = me.cargo_features.as_ref().unwrap_or(&empty);
1454-
let features = Features::new(cargo_features, config, &mut warnings)?;
1454+
let features = Features::new(cargo_features, config, &mut warnings, source_id.is_path())?;
14551455

14561456
let (replace, patch) = {
14571457
let mut cx = Context {

0 commit comments

Comments
 (0)