Skip to content

Commit 1a51a21

Browse files
rylevjyn514
authored andcommitted
More specifics on what future-incompatible lints are used for
1 parent c3c110f commit 1a51a21

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

src/diagnostics.md

+19-5
Original file line numberDiff line numberDiff line change
@@ -586,15 +586,21 @@ but warn-by-default in the 2018 edition.
586586

587587
### Future-incompatible lints
588588

589-
Future-incompatible lints are for signalling to the user that code they have
589+
The use of the term `future-incompatible` within the compiler has a slightly
590+
broader meaning than what rustc exposes to users of the compiler.
591+
592+
Inside rustc, future-incompatible lints are for signalling to the user that code they have
590593
written may not compile in the future. In general, future-incompatible code
591594
exists for two reasons:
592595
* the user has written unsound code that the compiler mistakenly accepted. While
593596
it is within Rust's backwards compatibility guarantees to fix the soundness hole
594597
(breaking the user's code), the lint is there to warn the user that this will happen
595-
in some upcoming version *regardless of which edition they are on*.
598+
in some upcoming version of rustc *regardless of which edition the code uses*. This is the
599+
meaning that rustc exclusively exposes to users as "future incompatible".
596600
* the user has written code that will either no longer compiler *or* will change
597-
meaning in an upcoming edition.
601+
meaning in an upcoming *edition*. These are often called "edition lints" and can be
602+
typically seen in the various "edition compatibility" lint groups (e.g., `rust_2021_compatibility`)
603+
that are used to lint against code that will break if the user updates the crate's edition.
598604

599605
A future-incompatible lint should be declared with the `@future_incompatible`
600606
additional "field":
@@ -611,9 +617,17 @@ declare_lint! {
611617
}
612618
```
613619

614-
Notice the `reason` field which describes why the future-incompatible change is happening.
620+
Notice the `reason` field which describes why the future incompatible change is happening.
615621
This will change the diagnostic message the user receives as well as determine which
616-
lint groups the lint is added to.
622+
lint groups the lint is added to. In the example above, the lint is an "edition lint"
623+
(since it's "reason" is `EditionError`) signifying to the user that the use of anonymous
624+
parameters will no longer compile in Rust 2018 and beyond.
625+
626+
Inside [LintStore::register_lints][fi-lint-groupings], lints with `future_incompatible`
627+
fields get placed into either edition-based lint groups (if their `reason` is tied to
628+
an edition) or into the `future_incompatibility` lint group.
629+
630+
[fi-lint-groupings]: https://github.com/rust-lang/rust/blob/51fd129ac12d5bfeca7d216c47b0e337bf13e0c2/compiler/rustc_lint/src/context.rs#L212-L237
617631

618632
If you need a combination of options that's not supported by the
619633
`declare_lint!` macro, you can always change the `declare_lint!` macro

0 commit comments

Comments
 (0)