Skip to content

Commit 707abe3

Browse files
committed
Move the container behavior to a separate rule
This is somewhat separate behavior, and I think it helps to discuss it separately.
1 parent 5f62ab8 commit 707abe3

File tree

1 file changed

+26
-3
lines changed

1 file changed

+26
-3
lines changed

src/attributes/diagnostics.md

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -323,13 +323,34 @@ The `deprecated` attribute has several forms:
323323
- `note` --- Specifies a string that should be included in the deprecation message. This is typically used to provide an explanation about the deprecation and preferred alternatives.
324324
325325
r[attributes.diagnostic.deprecated.allowed-positions]
326-
The `deprecated` attribute may be applied to any [item], [trait item], [enum variant], [struct field], [external block item], or [macro definition]. It cannot be applied to [trait implementation items][trait-impl]. When applied to an item containing other items, such as a [module] or [implementation], all child items inherit the deprecation attribute.
326+
The `deprecated` attribute may be applied to any [item], [trait item], [enum variant], [struct field], [external block item], or [macro definition]. It cannot be applied to [trait implementation items][trait-impl].
327327
328328
<!-- NOTE: It is only rejected for trait impl items
329329
(AnnotationKind::Prohibited). In all other locations, it is silently ignored.
330330
Tuple struct fields are ignored.
331331
-->
332332
333+
r[attributes.diagnostics.deprecated.containers]
334+
When `deprecated` is applied to an item containing other items, all child items inherit the deprecation attribute. This includes:
335+
336+
- [crate root]
337+
- [modules]
338+
- [implementations]
339+
- [external blocks]
340+
341+
> [!EXAMPLE]
342+
> ```rust
343+
> #[deprecated = "utility functions are no longer supported and will be removed in the future"]
344+
> pub mod utils {
345+
> pub fn trim() {}
346+
> pub fn flush() {}
347+
> }
348+
>
349+
> fn main() {
350+
> utils::trim(); // WARNING: deprecated
351+
> }
352+
> ```
353+
333354
r[attributes.diagnostics.must_use]
334355
## The `must_use` attribute
335356
@@ -652,19 +673,21 @@ The first error message includes a somewhat confusing error message about the re
652673
[attributes]: ../attributes.md
653674
[block expression]: ../expressions/block-expr.md
654675
[call expression]: ../expressions/call-expr.md
676+
[crate root]: ../crates-and-source-files.md
655677
[dyn trait]: ../types/trait-object.md
656678
[enum variant]: ../items/enumerations.md
657679
[enum]: ../items/enumerations.md
658680
[expression statement]: ../statements.md#expression-statements
659681
[expression]: ../expressions.md
660682
[external block item]: ../items/external-blocks.md
683+
[external blocks]: ../items/external-blocks.md
661684
[functions]: ../items/functions.md
662685
[impl trait]: ../types/impl-trait.md
663-
[implementation]: ../items/implementations.md
686+
[implementations]: ../items/implementations.md
664687
[item]: ../items.md
665688
[let statement]: ../statements.md#let-statements
666689
[macro definition]: ../macros-by-example.md
667-
[module]: ../items/modules.md
690+
[modules]: ../items/modules.md
668691
[rustc book]: ../../rustc/lints/index.html
669692
[rustc-lint-caps]: ../../rustc/lints/levels.html#capping-lints
670693
[rustc-lint-cli]: ../../rustc/lints/levels.html#via-compiler-flag

0 commit comments

Comments
 (0)