Skip to content

Commit 99e714c

Browse files
committed
Auto merge of #9230 - kornelski:nobinaries, r=alexcrichton
Explain `cargo install` is not for libraries On a few occasions I've seen novice users assume that `cargo install` works like `npm install` or `apt install`, and they're confused that they can't use library dependencies this way. I've expanded the error message to hopefully clarify the misconception.
2 parents 61a31bc + 6977dee commit 99e714c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/cargo/ops/cargo_install.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,12 @@ fn install_one(
305305
// *something* to install. Explicit `--bin` or `--example` flags will be
306306
// checked at the start of `compile_ws`.
307307
if !opts.filter.is_specific() && !pkg.targets().iter().any(|t| t.is_bin()) {
308-
bail!("specified package `{}` has no binaries", pkg);
308+
bail!(
309+
"there is nothing to install in `{}`, because it has no binaries\n\
310+
`cargo install` is only for installing programs, and can't be used with libraries.\n\
311+
To use a library crate, add it as a dependency in a Cargo project instead.",
312+
pkg
313+
);
309314
}
310315

311316
// Helper for --no-track flag to make sure it doesn't overwrite anything.

tests/testsuite/install.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -567,8 +567,9 @@ fn no_binaries() {
567567
.with_status(101)
568568
.with_stderr(
569569
"\
570-
[ERROR] specified package `foo v0.0.1 ([..])` has no binaries
571-
",
570+
[ERROR] there is nothing to install in `foo v0.0.1 ([..])`, because it has no binaries[..]
571+
[..]
572+
[..]",
572573
)
573574
.run();
574575
}

0 commit comments

Comments
 (0)