Skip to content

Commit d9347c3

Browse files
committed
Auto merge of #6380 - fbunt:issue-6370, r=alexcrichton
Warn if feature is called "default-features" Fixes #6370. I'm new to Rust and Cargo so any tips or critiques are welcome!
2 parents c2829b3 + d522344 commit d9347c3

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/cargo/util/toml/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -1021,6 +1021,13 @@ impl TomlManifest {
10211021
None => false,
10221022
};
10231023

1024+
if summary.features().contains_key("default-features") {
1025+
warnings.push(
1026+
"`default-features = [\"..\"]` was found in [features]. \
1027+
Did you mean to use `default = [\"..\"]`?".to_string()
1028+
)
1029+
}
1030+
10241031
let custom_metadata = project.metadata.clone();
10251032
let mut manifest = Manifest::new(
10261033
summary,

tests/testsuite/features.rs

+33
Original file line numberDiff line numberDiff line change
@@ -1730,3 +1730,36 @@ fn feature_off_dylib() {
17301730
// Check that building without `f1` uses a dylib without `f1`.
17311731
p.cargo("run -p bar").run();
17321732
}
1733+
1734+
#[test]
1735+
fn warn_if_default_features() {
1736+
let p = project()
1737+
.file(
1738+
"Cargo.toml",
1739+
r#"
1740+
[project]
1741+
name = "foo"
1742+
version = "0.0.1"
1743+
authors = []
1744+
1745+
[dependencies.bar]
1746+
path = "bar"
1747+
optional = true
1748+
1749+
[features]
1750+
default-features = ["bar"]
1751+
"#
1752+
).file("src/main.rs", "fn main() {}")
1753+
.file("bar/Cargo.toml",&basic_manifest("bar", "0.0.1"))
1754+
.file("bar/src/lib.rs", "pub fn bar() {}")
1755+
.build();
1756+
1757+
p.cargo("build")
1758+
.with_stderr(
1759+
r#"
1760+
[WARNING] `default-features = [".."]` was found in [features]. Did you mean to use `default = [".."]`?
1761+
[COMPILING] foo v0.0.1 ([CWD])
1762+
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
1763+
"#.trim(),
1764+
).run();
1765+
}

0 commit comments

Comments
 (0)