Skip to content

Commit 64dda42

Browse files
committed
Merge PR #301
2 parents 0c68e90 + eb04050 commit 64dda42

4 files changed

+135
-3
lines changed

src/SUMMARY.md

+2
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,6 @@
4444
- [Disallow references to `static mut`](rust-2024/static-mut-reference.md)
4545
- [Public/private dependencies](rust-2024/public-private-dependencies.md)
4646
- [Cargo: Remove implicit features](rust-2024/cargo-remove-implicit-features.md)
47+
- [Cargo: Table and key name consistency](rust-2024/cargo-table-key-names.md)
48+
- [Cargo: Reject unused inherited default-features](rust-2024/cargo-inherited-default-features.md)
4749
- [Rustfmt: Combine all delimited exprs as last argument](rust-2024/rustfmt-overflow-delimited-expr.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# Cargo: Reject unused inherited default-features
2+
3+
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
4+
5+
## Summary
6+
7+
- `default-features = false` is no longer allowed in an inherited workspace dependency if the workspace dependency specifies `default-features = true` (or does not specify `default-features`).
8+
9+
## Details
10+
11+
[Workspace inheritance] allows you to specify dependencies in one place (the workspace), and then to refer to those workspace dependencies from within a package.
12+
There was an inadvertent interaction with how `default-features` is specified that is no longer allowed in the 2024 Edition.
13+
14+
Unless the workspace specifies `default-features = false`, it is no longer allowed to specify `default-features = false` in an inherited package dependency.
15+
For example, with a workspace that specifies:
16+
17+
```toml
18+
[workspace.dependencies]
19+
regex = "1.10.4"
20+
```
21+
22+
The following is now an error:
23+
24+
```toml
25+
[package]
26+
name = "foo"
27+
version = "1.0.0"
28+
edition = "2024"
29+
30+
[dependencies]
31+
regex = { workspace = true, default-features = false } # ERROR
32+
```
33+
34+
The reason for this change is to avoid confusion when specifying `default-features = false` when the default feature is already enabled, since it has no effect.
35+
36+
If you want the flexibility of deciding whether or not a dependency enables the default-features of a dependency, be sure to set `default-features = false` in the workspace definition.
37+
Just beware that if you build multiple workspace members at the same time, the features will be unified so that if one member sets `default-features = true` (which is the default if not explicitly set), the default-features will be enabled for all members using that dependency.
38+
39+
## Migration
40+
41+
When using `cargo fix --edition`, Cargo will automatically update your `Cargo.toml` file to remove `default-features = false` in this situation.
42+
43+
If you would prefer to update your `Cargo.toml` manually, check for any warnings when running a build and remove the corresponding entries.
44+
Previous editions should display something like:
45+
46+
```text
47+
warning: /home/project/Cargo.toml: `default-features` is ignored for regex,
48+
since `default-features` was not specified for `workspace.dependencies.regex`,
49+
this could become a hard error in the future
50+
```
51+
52+
[workspace inheritance]: ../../cargo/reference/specifying-dependencies.html#inheriting-a-dependency-from-a-workspace

src/rust-2024/cargo-remove-implicit-features.md

+38-3
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,46 @@
22

33
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
44

5-
This feature has not yet been implemented.
6-
More information may be found in the tracking issue at <https://github.com/rust-lang/cargo/issues/12826>.
7-
85
## Summary
96

7+
- Optional dependencies must now be explicitly specified in the `[features]` table.
8+
109
## Details
1110

11+
In previous editions, when an [optional dependency] is specified, Cargo would automatically add an implicit [feature] of the same name as the dependency. For example:
12+
13+
```toml
14+
[dependencies]
15+
jpeg-decoder = { version = "0.3.1", optional = true }
16+
```
17+
18+
This would automatically add a feature `jpeg-decoder = ["dep:jpeg-decoder"]` to provide a way to enable the dependency.
19+
The `dep:` entries are specific syntax for referring to optional dependencies.
20+
This implicit feature is only added if `"dep:jpeg-decoder"` is not specified in any other feature.
21+
22+
In the 2024 Edition, this implicit feature is no longer added, and you are required to explicitly specify the dependency in the `[features]` table.
23+
For example, instead of exposing the particular internal name of some dependency, you may consider using a more general term for the feature name:
24+
25+
```toml
26+
[features]
27+
graphics = ["dep:jpeg-decoder"]
28+
```
29+
30+
`cargo add --optional <NAME>` automatically adds a feature for the dependency to the `[features]` table if it isn't already there.
31+
32+
### Motivation
33+
34+
One reason for requiring this to be explicit is that it encourages a conscious decision about the public exposure of the feature name, and makes it clearer when reading the `[features]` table which features exist.
35+
This can help avoid tying the implementation details (the dependency names) to the public set of feature names.
36+
37+
Also, removing features is a [SemVer incompatible change][semver], which may not be obvious when removing an optional dependency that you thought was private.
38+
1239
## Migration
40+
41+
When using `cargo fix --edition`, Cargo will automatically update your `Cargo.toml` file to include the implicit features if necessary.
42+
43+
If you would prefer to update your `Cargo.toml` manually, add a `foo = ["dep:foo"]` entry for each optional dependency named *foo* if `dep:foo` is not already specified anywhere in the `[features]` table.
44+
45+
[optional dependency]: ../../cargo/reference/features.html#optional-dependencies
46+
[feature]: ../../cargo/reference/features.html
47+
[semver]: ../../cargo/reference/semver.html#cargo-feature-remove
+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Cargo: Table and key name consistency
2+
3+
🚧 The 2024 Edition has not yet been released and hence this section is still "under construction".
4+
5+
## Summary
6+
7+
- Several table and key names in `Cargo.toml` have been removed where there were previously two ways to specify the same thing.
8+
- Removed `[project]`; use `[package]` instead.
9+
- Removed `default_features`; use `default-features` instead.
10+
- Removed `crate_type`; use `crate-type` instead.
11+
- Removed `proc_macro`; use `proc-macro` instead.
12+
- Removed `dev_dependencies`; use `dev-dependencies` instead.
13+
- Removed `build_dependencies`; use `build-dependencies` instead.
14+
15+
## Details
16+
17+
Several table and keys names are no longer allowed in the 2024 Edition.
18+
There were two ways to specify these tables or keys, and this helps ensure there is only one way to specify them.
19+
20+
Some were due to a change in decisions over time, and some were inadvertent implementation artifacts.
21+
In order to avoid confusion, and to enforce a single style for specifying these tables and keys, only one variant is now allowed.
22+
23+
For example:
24+
25+
```toml
26+
[dev_dependencies]
27+
rand = { version = "0.8.5", default_features = false }
28+
```
29+
30+
Should be changed to:
31+
32+
```toml
33+
[dev-dependencies]
34+
rand = { version = "0.8.5", default-features = false }
35+
```
36+
37+
Notice that the underscores were changed to dashes for `dev_dependencies` and `default_features`.
38+
39+
## Migration
40+
41+
When using `cargo fix --edition`, Cargo will automatically update your `Cargo.toml` file to use the preferred table and key names.
42+
43+
If you would prefer to update your `Cargo.toml` manually, be sure to go through the list above and make sure only the new forms are used.

0 commit comments

Comments
 (0)