Skip to content

Commit 00852e6

Browse files
authored
Merge pull request rust-lang#208 from mrhota/more-deprecated
Enhance discussion of deprecated attribute
2 parents a4af6ac + 196b071 commit 00852e6

File tree

1 file changed

+32
-4
lines changed

1 file changed

+32
-4
lines changed

src/attributes.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ type int8_t = i8;
8484

8585
[subsystem]: https://msdn.microsoft.com/en-us/library/fcc1zstk.aspx
8686

87-
### Module-only attributes
87+
## Module-only attributes
8888

8989
- `no_implicit_prelude` - disable injecting `use std::prelude::*` in this
9090
module.
@@ -175,9 +175,6 @@ macro scope.
175175

176176
## Miscellaneous attributes
177177

178-
- `deprecated` - mark the item as deprecated; the full attribute is
179-
`#[deprecated(since = "crate version", note = "...")`, where both arguments
180-
are optional.
181178
- `export_name` - on statics and functions, this determines the name of the
182179
exported symbol.
183180
- `link_section` - on statics and functions, this specifies the section of the
@@ -188,6 +185,37 @@ macro scope.
188185
assigned to a variable. You may also include an optional message by using
189186
`#[must_use = "message"]` which will be given alongside the warning.
190187

188+
### Deprecation
189+
190+
The `deprecated` attribute marks an item as deprecated. It has two optional
191+
fields, `since` and `note`.
192+
193+
- `since` expects a version number, as in `#[deprecated(since = "1.4.1")]`
194+
- `rustc` doesn't know anything about versions, but external tools like
195+
`clippy` may check the validity of this field.
196+
- `note` is a free text field, allowing you to provide an explanation about
197+
the deprecation and preferred alternatives.
198+
199+
Only [public items](visibility-and-privacy.html) can be given the
200+
`#[deprecated]` attribute. `#[deprecated]` on a module is inherited by all
201+
child items of that module.
202+
203+
`rustc` will issue warnings on usage of `#[deprecated]` items. `rustdoc` will
204+
show item deprecation, including the `since` version and `note`, if available.
205+
206+
Here's an example.
207+
208+
```rust
209+
#[deprecated(since = "5.2", note = "foo was rarely used. Users should instead use bar")]
210+
pub fn foo() {}
211+
212+
pub fn bar() {}
213+
```
214+
215+
The [RFC][1270-deprecation.md] contains motivations and more details.
216+
217+
[1270-deprecation.md]: https://github.com/rust-lang/rfcs/blob/master/text/1270-deprecation.md
218+
191219
### Documentation
192220

193221
The `doc` attribute is used to document items and fields. [Doc comments]

0 commit comments

Comments
 (0)