6
6
# Summary
7
7
8
8
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.
13
12
14
13
# Motivation
15
14
@@ -30,39 +29,29 @@ fields and enum variants) can be given a `#[deprecated]` attribute. All
30
29
possible fields are optional:
31
30
32
31
* ` 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 ) .
37
35
* ` reason ` should contain a human-readable string outlining the reason for
38
36
deprecating the item. While this field is not required, library authors are
39
37
strongly advised to make use of it to convey the reason for the deprecation to
40
38
users of their library. The string is interpreted as plain unformatted text
41
39
(for now) so that rustdoc can include it in the item's documentation without
42
40
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.
51
41
52
42
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:
56
46
57
47
Let's say I have my ` llogiq ` crate that depends on ` foobar ` which uses a
58
48
deprecated item of ` serde ` . I will never get the warning about this unless I
59
49
try to build ` foobar ` directly. We may want to create a service like ` crater `
60
50
to warn on use of deprecated items in library crates, however this is outside
61
51
the scope of this RFC.
62
52
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.
66
55
67
56
The language reference will be extended to describe this feature as outlined
68
57
in this RFC. Authors shall be advised to leave their users enough time to react
@@ -71,38 +60,69 @@ before *removing* a deprecated item.
71
60
The internally used feature can either be subsumed by this or possibly renamed
72
61
to avoid a name clash.
73
62
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
+
74
101
# Drawbacks
75
102
76
- * The required checks for the ` since ` and ` use ` fields are potentially
77
- quite complex.
78
103
* Once the feature is public, we can no longer change its design
79
104
80
105
# Alternatives
81
106
82
107
* Do nothing
83
108
* 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)
90
109
* require either ` reason ` or ` use ` be present
91
110
* ` 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
97
119
* Optionally, ` cargo ` could offer a new dependency category: "doc-dependencies"
98
120
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)
100
122
101
123
# Unresolved questions
102
124
103
125
* What other restrictions should we introduce now to avoid being bound to a
104
126
possibly flawed design?
105
- * How should the multiple values in the ` use ` field work? Just split by
106
- comma or some other delimiter?
107
127
* Can / Should the ` std ` library make use of the ` #[deprecated] ` extensions?
108
128
* Bikeshedding: Are the names good enough?
0 commit comments