Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 43 additions & 20 deletions src/bin/cargo/cli.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use annotate_snippets::Level;
use anyhow::{Context as _, anyhow};
use cargo::core::{CliUnstable, features};
use cargo::util::context::TermConfig;
Expand Down Expand Up @@ -318,26 +319,40 @@ To pass the arguments to the subcommand, remove `--`",
// a hard error.
if super::builtin_aliases_execs(cmd).is_none() {
if let Some(path) = super::find_external_subcommand(gctx, cmd) {
gctx.shell().warn(format!(
"\
user-defined alias `{}` is shadowing an external subcommand found at: `{}`
This was previously accepted but is being phased out; it will become a hard error in a future release.
For more information, see issue #10049 <https://github.com/rust-lang/cargo/issues/10049>.",
cmd,
path.display(),
))?;
gctx.shell().print_report(
&[
Level::WARNING.secondary_title(format!(
"user-defined alias `{}` is shadowing an external subcommand found at `{}`",
cmd,
path.display()
)).element(
Level::NOTE.message(
"this was previously accepted but will become a hard error in the future; \
see <https://github.com/rust-lang/cargo/issues/10049>"
)
)
],
false,
)?;
}
}
if commands::run::is_manifest_command(cmd) {
if gctx.cli_unstable().script {
return Ok((args, GlobalArgs::default()));
} else {
gctx.shell().warn(format_args!(
"\
user-defined alias `{cmd}` has the appearance of a manifest-command
This was previously accepted but will be phased out when `-Zscript` is stabilized.
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>."
))?;
gctx.shell().print_report(
&[
Level::WARNING.secondary_title(
format!("user-defined alias `{cmd}` has the appearance of a manifest-command")
).element(
Level::NOTE.message(
"this was previously accepted but will be phased out when `-Zscript` is stabilized; \
see <https://github.com/rust-lang/cargo/issues/12207>"
)
)
],
false
)?;
}
}

Expand Down Expand Up @@ -477,12 +492,20 @@ impl Exec {
Self::Manifest(cmd) => {
let ext_path = super::find_external_subcommand(gctx, &cmd);
if !gctx.cli_unstable().script && ext_path.is_some() {
gctx.shell().warn(format_args!(
"\
external subcommand `{cmd}` has the appearance of a manifest-command
This was previously accepted but will be phased out when `-Zscript` is stabilized.
For more information, see issue #12207 <https://github.com/rust-lang/cargo/issues/12207>.",
))?;
gctx.shell().print_report(
&[
Level::WARNING.secondary_title(
format!("external subcommand `{cmd}` has the appearance of a manifest-command")
).element(
Level::NOTE.message(
"this was previously accepted but will be phased out when `-Zscript` is stabilized; \
see <https://github.com/rust-lang/cargo/issues/12207>"
)
)
],
false
)?;

Self::External(cmd).exec(gctx, subcommand_args)
} else {
let ext_args: Vec<OsString> = subcommand_args
Expand Down
100 changes: 52 additions & 48 deletions src/cargo/core/compiler/build_runner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::core::compiler::compilation::{self, UnitOutput};
use crate::core::compiler::{self, Unit, artifact};
use crate::util::cache_lock::CacheLockMode;
use crate::util::errors::CargoResult;
use annotate_snippets::{Level, Message};
use anyhow::{Context as _, bail};
use cargo_util::paths;
use filetime::FileTime;
Expand Down Expand Up @@ -515,58 +516,56 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
#[tracing::instrument(skip_all)]
fn check_collisions(&self) -> CargoResult<()> {
let mut output_collisions = HashMap::new();
let describe_collision = |unit: &Unit, other_unit: &Unit, path: &PathBuf| -> String {
let describe_collision = |unit: &Unit, other_unit: &Unit| -> String {
format!(
"The {} target `{}` in package `{}` has the same output \
filename as the {} target `{}` in package `{}`.\n\
Colliding filename is: {}\n",
"the {} target `{}` in package `{}` has the same output filename as the {} target `{}` in package `{}`",
unit.target.kind().description(),
unit.target.name(),
unit.pkg.package_id(),
other_unit.target.kind().description(),
other_unit.target.name(),
other_unit.pkg.package_id(),
path.display()
)
};
let suggestion = "Consider changing their names to be unique or compiling them separately.\n\
This may become a hard error in the future; see \
<https://github.com/rust-lang/cargo/issues/6313>.";
let rustdoc_suggestion = "This is a known bug where multiple crates with the same name use\n\
the same path; see <https://github.com/rust-lang/cargo/issues/6313>.";
let suggestion = [
Level::NOTE.message("this may become a hard error in the future; see <https://github.com/rust-lang/cargo/issues/6313>"),
Level::HELP.message("consider changing their names to be unique or compiling them separately")
];
let rustdoc_suggestion = [
Level::NOTE.message("this is a known bug where multiple crates with the same name use the same path; see <https://github.com/rust-lang/cargo/issues/6313>")
];
let report_collision = |unit: &Unit,
other_unit: &Unit,
path: &PathBuf,
suggestion: &str|
messages: &[Message<'_>]|
-> CargoResult<()> {
if unit.target.name() == other_unit.target.name() {
self.bcx.gctx.shell().warn(format!(
"output filename collision.\n\
{}\
The targets should have unique names.\n\
{}",
describe_collision(unit, other_unit, path),
suggestion
))
self.bcx.gctx.shell().print_report(
&[Level::WARNING
.secondary_title(format!("output filename collision at {}", path.display()))
.elements(
[Level::NOTE.message(describe_collision(unit, other_unit))]
.into_iter()
.chain(messages.iter().cloned()),
)],
false,
)
} else {
self.bcx.gctx.shell().warn(format!(
"output filename collision.\n\
{}\
The output filenames should be unique.\n\
{}\n\
If this looks unexpected, it may be a bug in Cargo. Please file a bug report at\n\
https://github.com/rust-lang/cargo/issues/ with as much information as you\n\
can provide.\n\
cargo {} running on `{}` target `{}`\n\
First unit: {:?}\n\
Second unit: {:?}",
describe_collision(unit, other_unit, path),
suggestion,
crate::version(),
self.bcx.host_triple(),
self.bcx.target_data.short_name(&unit.kind),
unit,
other_unit))
self.bcx.gctx.shell().print_report(
&[Level::WARNING
.secondary_title(format!("output filename collision at {}", path.display()))
.elements([
Level::NOTE.message(describe_collision(unit, other_unit)),
Level::NOTE.message("if this looks unexpected, it may be a bug in Cargo. Please file a bug \
report at https://github.com/rust-lang/cargo/issues/ with as much information as you \
can provide."),
Level::NOTE.message(format!("cargo {} running on `{}` target `{}`",
crate::version(), self.bcx.host_triple(), self.bcx.target_data.short_name(&unit.kind))),
Level::NOTE.message(format!("first unit: {unit:?}")),
Level::NOTE.message(format!("second unit: {other_unit:?}")),
])],
false,
)
}
};

Expand Down Expand Up @@ -623,26 +622,31 @@ impl<'a, 'gctx> BuildRunner<'a, 'gctx> {
if unit.mode.is_doc() {
// See https://github.com/rust-lang/rust/issues/56169
// and https://github.com/rust-lang/rust/issues/61378
report_collision(unit, other_unit, &output.path, rustdoc_suggestion)?;
report_collision(unit, other_unit, &output.path, &rustdoc_suggestion)?;
} else {
report_collision(unit, other_unit, &output.path, suggestion)?;
report_collision(unit, other_unit, &output.path, &suggestion)?;
}
}
if let Some(hardlink) = output.hardlink.as_ref() {
if let Some(other_unit) = output_collisions.insert(hardlink.clone(), unit) {
report_collision(unit, other_unit, hardlink, suggestion)?;
report_collision(unit, other_unit, hardlink, &suggestion)?;
}
}
if let Some(ref export_path) = output.export_path {
if let Some(other_unit) = output_collisions.insert(export_path.clone(), unit) {
self.bcx.gctx.shell().warn(format!(
"`--artifact-dir` filename collision.\n\
{}\
The exported filenames should be unique.\n\
{}",
describe_collision(unit, other_unit, export_path),
suggestion
))?;
self.bcx.gctx.shell().print_report(
&[Level::WARNING
.secondary_title(format!(
"`--artifact-dir` filename collision at {}",
export_path.display()
))
.elements(
[Level::NOTE.message(describe_collision(unit, other_unit))]
.into_iter()
.chain(suggestion.iter().cloned()),
)],
false,
)?;
}
}
}
Expand Down
19 changes: 10 additions & 9 deletions src/cargo/core/compiler/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,15 +1717,16 @@ fn build_deps_args(
if let Some(dep) = deps.iter().find(|dep| {
!dep.unit.mode.is_doc() && dep.unit.target.is_lib() && !dep.unit.artifact.is_true()
}) {
bcx.gctx.shell().warn(format!(
"The package `{}` \
provides no linkable target. The compiler might raise an error while compiling \
`{}`. Consider adding 'dylib' or 'rlib' to key `crate-type` in `{}`'s \
Cargo.toml. This warning might turn into a hard error in the future.",
dep.unit.target.crate_name(),
unit.target.crate_name(),
dep.unit.target.crate_name()
))?;
let dep_name = dep.unit.target.crate_name();
let name = unit.target.crate_name();
bcx.gctx.shell().print_report(&[
Level::WARNING.secondary_title(format!("the package `{dep_name}` provides no linkable target"))
.elements([
Level::NOTE.message(format!("this might cause `{name}` to fail compilation")),
Level::NOTE.message("this warning might turn into a hard error in the future"),
Level::HELP.message(format!("consider adding 'dylib' or 'rlib' to key 'crate-type' in `{dep_name}`'s Cargo.toml"))
])
], false)?;
}
}

Expand Down
81 changes: 52 additions & 29 deletions src/cargo/ops/registry/publish.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use std::io::Seek;
use std::io::SeekFrom;
use std::time::Duration;

use annotate_snippets::Level;
use anyhow::Context as _;
use anyhow::bail;
use cargo_credential::Operation;
Expand Down Expand Up @@ -108,12 +109,16 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
if allow_unpublishable {
let n = unpublishable.len();
let plural = if n == 1 { "" } else { "s" };
ws.gctx().shell().warn(format_args!(
"nothing to publish, but found {n} unpublishable package{plural}"
))?;
ws.gctx().shell().note(format_args!(
"to publish packages, set `package.publish` to `true` or a non-empty list"
))?;
ws.gctx().shell().print_report(
&[Level::WARNING
.secondary_title(format!(
"nothing to publish, but found {n} unpublishable package{plural}"
))
.element(Level::HELP.message(
"to publish packages, set `package.publish` to `true` or a non-empty list",
))],
false,
)?;
return Ok(());
} else {
unreachable!("must have at least one publishable package");
Expand Down Expand Up @@ -323,18 +328,23 @@ pub fn publish(ws: &Workspace<'_>, opts: &PublishOpts<'_>) -> CargoResult<()> {
)?;
} else {
let short_pkg_descriptions = package_list(to_confirm.iter().copied(), "or");
opts.gctx.shell().warn(format!(
"timed out waiting for {short_pkg_descriptions} to be available in {source_description}",
))?;
opts.gctx.shell().note(format!(
"the registry may have a backlog that is delaying making the \
{crate} available. The {crate} should be available soon.",
crate = if to_confirm.len() == 1 {
"crate"
} else {
"crates"
}
))?;
let krate = if to_confirm.len() == 1 {
"crate"
} else {
"crates"
};
opts.gctx.shell().print_report(
&[Level::WARNING
.secondary_title(format!(
"timed out waiting for {short_pkg_descriptions} \
to be available in {source_description}",
))
.element(Level::NOTE.message(format!(
"the registry may have a backlog that is delaying making the \
{krate} available. The {krate} should be available soon.",
)))],
false,
)?;
}
confirmed
} else {
Expand Down Expand Up @@ -676,25 +686,38 @@ fn transmit(

if !warnings.invalid_categories.is_empty() {
let msg = format!(
"the following are not valid category slugs and were \
ignored: {}. Please see https://crates.io/category_slugs \
for the list of all category slugs. \
",
"the following are not valid category slugs and were ignored: {}",
warnings.invalid_categories.join(", ")
);
gctx.shell().warn(&msg)?;
gctx.shell().print_report(
&[Level::WARNING
.secondary_title(msg)
.element(Level::HELP.message(
"please see <https://crates.io/category_slugs> for the list of all category slugs",
))],
false,
)?;
}

if !warnings.invalid_badges.is_empty() {
let msg = format!(
"the following are not valid badges and were ignored: {}. \
Either the badge type specified is unknown or a required \
attribute is missing. Please see \
https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata \
for valid badge types and their required attributes.",
"the following are not valid badges and were ignored: {}",
warnings.invalid_badges.join(", ")
);
gctx.shell().warn(&msg)?;
gctx.shell().print_report(
&[Level::WARNING.secondary_title(msg).elements([
Level::NOTE.message(
"either the badge type specified is unknown or a required \
attribute is missing",
),
Level::HELP.message(
"please see \
<https://doc.rust-lang.org/cargo/reference/manifest.html#package-metadata> \
for valid badge types and their required attributes",
),
])],
false,
)?;
}

if !warnings.other.is_empty() {
Expand Down
Loading