Skip to content

Commit 8ec2ccd

Browse files
committed
relegated use to alternatives, user story, clippy
1 parent c8a726c commit 8ec2ccd

File tree

1 file changed

+58
-38
lines changed

1 file changed

+58
-38
lines changed

text/0000-deprecation.md

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@
66
# Summary
77

88
This RFC proposes to allow library authors to use a `#[deprecated]` attribute,
9-
with optional `since = "`*version*`"`, `reason = "`*free text*`"` and
10-
`use = "`*substitute declaration*`"` fields. The compiler can then
11-
warn on deprecated items, while `rustdoc` can document their deprecation
12-
accordingly.
9+
with optional `since = "`*version*`"` and `reason = "`*free text*`"`fields. The
10+
compiler can then warn on deprecated items, while `rustdoc` can document their
11+
deprecation accordingly.
1312

1413
# Motivation
1514

@@ -30,39 +29,29 @@ fields and enum variants) can be given a `#[deprecated]` attribute. All
3029
possible fields are optional:
3130

3231
* `since` is defined to contain the version of the crate at the time of
33-
deprecating the item, following the semver scheme. It makes no sense to put a
34-
version number higher than the current newest version here, and this is not
35-
checked (but could be by external lints, e.g.
36-
[rust-clippy](https://github.com/Manishearth/rust-clippy).
32+
deprecating the item, following the semver scheme. Rustc does not know about
33+
versions, thus the content of this field is not checked (but will be by external
34+
lints, e.g. [rust-clippy](https://github.com/Manishearth/rust-clippy).
3735
* `reason` should contain a human-readable string outlining the reason for
3836
deprecating the item. While this field is not required, library authors are
3937
strongly advised to make use of it to convey the reason for the deprecation to
4038
users of their library. The string is interpreted as plain unformatted text
4139
(for now) so that rustdoc can include it in the item's documentation without
4240
messing up the formatting.
43-
* `use`, if included, must be the import path (or a semicolon-delimited list of
44-
paths) to a set of API items that will replace the functionality of the
45-
deprecated item. All crates in scope can be reached by this path. E.g. let's
46-
say my `foo()` item was superceded by either the `bar()` or `baz()` functions
47-
in the `bar` crate, in conjunction with the `bruzz(_)` function in the `baz`
48-
crate, I can `#[deprecate(use="bar::{bar,baz};baz::bruzz")] foo()`, as long
49-
as I have the `bar` and `baz` crates in the library path. Rustc checks if the
50-
item is actually available, otherwise returning an error.
5141

5242
On use of a *deprecated* item, `rustc` will `warn` of the deprecation. Note
53-
that during Cargo builds, warnings on dependencies get silenced. Note that
54-
while this has the upside of keeping things tidy, it has a downside when it
55-
comes to deprecation:
43+
that during Cargo builds, warnings on dependencies get silenced. While this has
44+
the upside of keeping things tidy, it has a downside when it comes to
45+
deprecation:
5646

5747
Let's say I have my `llogiq` crate that depends on `foobar` which uses a
5848
deprecated item of `serde`. I will never get the warning about this unless I
5949
try to build `foobar` directly. We may want to create a service like `crater`
6050
to warn on use of deprecated items in library crates, however this is outside
6151
the scope of this RFC.
6252

63-
`rustdoc` will show deprecation on items, with a `[deprecated]`
64-
box that may optionally show the version, reason and/or link to the replacement
65-
if available.
53+
`rustdoc` will show deprecation on items, with a `[deprecated]` box that may
54+
optionally show the version and reason where available.
6655

6756
The language reference will be extended to describe this feature as outlined
6857
in this RFC. Authors shall be advised to leave their users enough time to react
@@ -71,38 +60,69 @@ before *removing* a deprecated item.
7160
The internally used feature can either be subsumed by this or possibly renamed
7261
to avoid a name clash.
7362

63+
# Intended Use
64+
65+
Crate author Anna wants to evolve her crate's API. She has found that one
66+
type, `Foo`, has a better implementation in the `rust-foo` crate. Also she has
67+
written a `frob(Foo)` function to replace the earlier `Foo::frobnicate(self)`
68+
method.
69+
70+
So Anna first bumps the version of her crate (because deprecation is always
71+
done on a version change) from `0.1.1` to `0.2.1`. She also adds the following
72+
prefix to the `Foo` type:
73+
74+
```
75+
extern crate rust_foo;
76+
77+
#[deprecated(since = "0.2.1", use="rust_foo::Foo",
78+
reason="The rust_foo version is more advanced, and this crates' will likely be discontinued")]
79+
struct Foo { .. }
80+
```
81+
82+
Users of her crate will see the following once they `cargo update` and `build`:
83+
84+
```
85+
src/foo_use.rs:27:5: 27:8 warning: Foo is marked deprecated as of version 0.2.1
86+
src/foo_use.rs:27:5: 27:8 note: The rust_foo version is more advanced, and this crates' will likely be discontinued
87+
```
88+
89+
Rust-clippy will likely gain more sophisticated checks for deprecation:
90+
91+
* `future_deprecation` will warn on items marked as deprecated, but with a
92+
version lower than their crates', while `current_deprecation` will warn only on
93+
those items marked as deprecated where the version is equal or lower to the
94+
crates' one.
95+
* `deprecation_syntax` will check that the `since` field really contains a
96+
semver number and not some random string.
97+
98+
Clippy users can then activate the clippy checks and deactivate the standard
99+
deprecation checks.
100+
74101
# Drawbacks
75102

76-
* The required checks for the `since` and `use` fields are potentially
77-
quite complex.
78103
* Once the feature is public, we can no longer change its design
79104

80105
# Alternatives
81106

82107
* Do nothing
83108
* make the `since` field required and check that it's a single version
84-
* Optionally the deprecation lint could check the current version as set by
85-
cargo in the CARGO_CRATE_VERSION environment variable (the rust build process
86-
should set this environment variable, too). This would allow future
87-
deprecations to be shown in the docs early, but not warned against by the
88-
stability lint (there could however be a `future-deprecation` lint that should
89-
be `Allow` by default)
90109
* require either `reason` or `use` be present
91110
* `reason` could include markdown formatting
92-
* The `use` could simply be plain text, which would remove much of the
93-
complexity here
94-
* The `use` field could be left out and added later. However, this would
95-
lead people to describe a replacement in the `reason` field, as is already
96-
happening in the case of rustc-private deprecation
111+
* rename the `reason` field to `note` to clarify it's broader usage.
112+
* add a `note` field and make `reason` a field with specific meaning, perhaps
113+
even predefine a number of valid reason strings, as JEP277 currently does
114+
* Add a `use` field containing a plain text of what to use instead
115+
* Add a `use` field containing a path to some function, type, etc. to replace
116+
the current feature. Currently with the rustc-private feature, people are
117+
describing a replacement in the `reason` field, which is clearly not the
118+
original intention of the field
97119
* Optionally, `cargo` could offer a new dependency category: "doc-dependencies"
98120
which are used to pull in other crates' documentations to link them (this is
99-
obviously not only relevant to deprecation).
121+
obviously not only relevant to deprecation)
100122

101123
# Unresolved questions
102124

103125
* What other restrictions should we introduce now to avoid being bound to a
104126
possibly flawed design?
105-
* How should the multiple values in the `use` field work? Just split by
106-
comma or some other delimiter?
107127
* Can / Should the `std` library make use of the `#[deprecated]` extensions?
108128
* Bikeshedding: Are the names good enough?

0 commit comments

Comments
 (0)