Skip to content

Commit e0d31a8

Browse files
committed
Stabilize lint_reasons in rustc (RFC 2383)
1 parent ed91732 commit e0d31a8

File tree

52 files changed

+96
-202
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+96
-202
lines changed

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,8 @@ declare_features! (
188188
(accepted, item_like_imports, "1.15.0", Some(35120), None),
189189
/// Allows `if/while p && let q = r && ...` chains.
190190
(accepted, let_chains, "1.64.0", Some(53667), None),
191+
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
192+
(accepted, lint_reasons, "1.64.0", Some(54503), None),
191193
/// Allows `break {expr}` with a value inside `loop`s.
192194
(accepted, loop_break_value, "1.19.0", Some(37339), None),
193195
/// Allows use of `?` as the Kleene "at most one" operator in macros.

compiler/rustc_feature/src/active.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -428,8 +428,6 @@ declare_features! (
428428
(active, let_else, "1.56.0", Some(87335), None),
429429
/// Allows `#[link(..., cfg(..))]`.
430430
(active, link_cfg, "1.14.0", Some(37406), None),
431-
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
432-
(active, lint_reasons, "1.31.0", Some(54503), None),
433431
/// Give access to additional metadata about declarative macro meta-variables.
434432
(active, macro_metavar_expr, "1.61.0", Some(83527), None),
435433
/// Allows `#[marker]` on certain traits allowing overlapping implementations.

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,8 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
301301
ungated!(
302302
allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
303303
),
304-
gated!(
305-
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk,
306-
lint_reasons, experimental!(expect)
304+
ungated!(
305+
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk
307306
),
308307
ungated!(
309308
forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk

compiler/rustc_lint/src/expect.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,13 @@ use rustc_hir::HirId;
44
use rustc_middle::ty::query::Providers;
55
use rustc_middle::{lint::LintExpectation, ty::TyCtxt};
66
use rustc_session::lint::LintExpectationId;
7-
use rustc_span::symbol::sym;
87
use rustc_span::Symbol;
98

109
pub(crate) fn provide(providers: &mut Providers) {
1110
*providers = Providers { check_expectations, ..*providers };
1211
}
1312

1413
fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
15-
if !tcx.sess.features_untracked().enabled(sym::lint_reasons) {
16-
return;
17-
}
18-
1914
let fulfilled_expectations = tcx.sess.diagnostic().steal_fulfilled_expectation_ids();
2015
let lint_expectations = &tcx.lint_levels(()).lint_expectations;
2116

compiler/rustc_lint/src/levels.rs

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use rustc_session::lint::{
1717
builtin::{self, FORBIDDEN_LINT_GROUPS, SINGLE_USE_LIFETIMES, UNFULFILLED_LINT_EXPECTATIONS},
1818
Level, Lint, LintExpectationId, LintId,
1919
};
20-
use rustc_session::parse::{add_feature_diagnostics, feature_err};
20+
use rustc_session::parse::add_feature_diagnostics;
2121
use rustc_session::Session;
2222
use rustc_span::symbol::{sym, Symbol};
2323
use rustc_span::{Span, DUMMY_SP};
@@ -306,15 +306,6 @@ impl<'s> LintLevelsBuilder<'s> {
306306
ast::MetaItemKind::NameValue(ref name_value) => {
307307
if item.path == sym::reason {
308308
if let ast::LitKind::Str(rationale, _) = name_value.kind {
309-
if !self.sess.features_untracked().lint_reasons {
310-
feature_err(
311-
&self.sess.parse_sess,
312-
sym::lint_reasons,
313-
item.span,
314-
"lint reasons are experimental",
315-
)
316-
.emit();
317-
}
318309
reason = Some(rationale);
319310
} else {
320311
bad_attr(name_value.span)

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -503,8 +503,6 @@ declare_lint! {
503503
/// ### Example
504504
///
505505
/// ```rust
506-
/// #![feature(lint_reasons)]
507-
///
508506
/// #[expect(unused_variables)]
509507
/// let x = 10;
510508
/// println!("{}", x);
@@ -530,8 +528,7 @@ declare_lint! {
530528
/// [#54503]: https://github.com/rust-lang/rust/issues/54503
531529
pub UNFULFILLED_LINT_EXPECTATIONS,
532530
Warn,
533-
"unfulfilled lint expectation",
534-
@feature_gate = rustc_span::sym::lint_reasons;
531+
"unfulfilled lint expectation"
535532
}
536533

537534
declare_lint! {

src/test/ui/empty/empty-attributes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lint_reasons)]
2-
31
#![deny(unused_attributes)]
42
#![allow()] //~ ERROR unused attribute
53
#![expect()] //~ ERROR unused attribute

src/test/ui/empty/empty-attributes.stderr

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
11
error: unused attribute
2-
--> $DIR/empty-attributes.rs:11:1
2+
--> $DIR/empty-attributes.rs:9:1
33
|
44
LL | #[repr()]
55
| ^^^^^^^^^ help: remove this attribute
66
|
77
note: the lint level is defined here
8-
--> $DIR/empty-attributes.rs:3:9
8+
--> $DIR/empty-attributes.rs:1:9
99
|
1010
LL | #![deny(unused_attributes)]
1111
| ^^^^^^^^^^^^^^^^^
1212
= note: attribute `repr` with an empty list has no effect
1313

1414
error: unused attribute
15-
--> $DIR/empty-attributes.rs:14:1
15+
--> $DIR/empty-attributes.rs:12:1
1616
|
1717
LL | #[target_feature()]
1818
| ^^^^^^^^^^^^^^^^^^^ help: remove this attribute
1919
|
2020
= note: attribute `target_feature` with an empty list has no effect
2121

2222
error: unused attribute
23-
--> $DIR/empty-attributes.rs:4:1
23+
--> $DIR/empty-attributes.rs:2:1
2424
|
2525
LL | #![allow()]
2626
| ^^^^^^^^^^^ help: remove this attribute
2727
|
2828
= note: attribute `allow` with an empty list has no effect
2929

3030
error: unused attribute
31-
--> $DIR/empty-attributes.rs:5:1
31+
--> $DIR/empty-attributes.rs:3:1
3232
|
3333
LL | #![expect()]
3434
| ^^^^^^^^^^^^ help: remove this attribute
3535
|
3636
= note: attribute `expect` with an empty list has no effect
3737

3838
error: unused attribute
39-
--> $DIR/empty-attributes.rs:6:1
39+
--> $DIR/empty-attributes.rs:4:1
4040
|
4141
LL | #![warn()]
4242
| ^^^^^^^^^^ help: remove this attribute
4343
|
4444
= note: attribute `warn` with an empty list has no effect
4545

4646
error: unused attribute
47-
--> $DIR/empty-attributes.rs:7:1
47+
--> $DIR/empty-attributes.rs:5:1
4848
|
4949
LL | #![deny()]
5050
| ^^^^^^^^^^ help: remove this attribute
5151
|
5252
= note: attribute `deny` with an empty list has no effect
5353

5454
error: unused attribute
55-
--> $DIR/empty-attributes.rs:8:1
55+
--> $DIR/empty-attributes.rs:6:1
5656
|
5757
LL | #![forbid()]
5858
| ^^^^^^^^^^^^ help: remove this attribute
5959
|
6060
= note: attribute `forbid` with an empty list has no effect
6161

6262
error: unused attribute
63-
--> $DIR/empty-attributes.rs:9:1
63+
--> $DIR/empty-attributes.rs:7:1
6464
|
6565
LL | #![feature()]
6666
| ^^^^^^^^^^^^^ help: remove this attribute

src/test/ui/feature-gates/feature-gate-lint-reasons.rs

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/test/ui/feature-gates/feature-gate-lint-reasons.stderr

Lines changed: 0 additions & 21 deletions
This file was deleted.

src/test/ui/lint/empty-lint-attributes.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lint_reasons)]
2-
31
// check-pass
42

53
// Empty (and reason-only) lint attributes are legal—although we may want to

src/test/ui/lint/reasons-erroneous.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lint_reasons)]
2-
31
#![warn(absolute_paths_not_starting_with_crate, reason = 0)]
42
//~^ ERROR malformed lint attribute
53
//~| ERROR malformed lint attribute

src/test/ui/lint/reasons-erroneous.stderr

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,125 @@
11
error[E0452]: malformed lint attribute input
2-
--> $DIR/reasons-erroneous.rs:3:58
2+
--> $DIR/reasons-erroneous.rs:1:58
33
|
44
LL | #![warn(absolute_paths_not_starting_with_crate, reason = 0)]
55
| ^ reason must be a string literal
66

77
error[E0452]: malformed lint attribute input
8-
--> $DIR/reasons-erroneous.rs:8:40
8+
--> $DIR/reasons-erroneous.rs:6:40
99
|
1010
LL | #![warn(anonymous_parameters, reason = b"consider these, for we have condemned them")]
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reason must be a string literal
1212

1313
error[E0452]: malformed lint attribute input
14-
--> $DIR/reasons-erroneous.rs:13:29
14+
--> $DIR/reasons-erroneous.rs:11:29
1515
|
1616
LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")]
1717
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
1818

1919
error[E0452]: malformed lint attribute input
20-
--> $DIR/reasons-erroneous.rs:13:29
20+
--> $DIR/reasons-erroneous.rs:11:29
2121
|
2222
LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")]
2323
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
2424

2525
error[E0452]: malformed lint attribute input
26-
--> $DIR/reasons-erroneous.rs:22:23
26+
--> $DIR/reasons-erroneous.rs:20:23
2727
|
2828
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
2929
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
3030

3131
error[E0452]: malformed lint attribute input
32-
--> $DIR/reasons-erroneous.rs:22:23
32+
--> $DIR/reasons-erroneous.rs:20:23
3333
|
3434
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
3535
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
3636

3737
error[E0452]: malformed lint attribute input
38-
--> $DIR/reasons-erroneous.rs:31:36
38+
--> $DIR/reasons-erroneous.rs:29:36
3939
|
4040
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
4141
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
4242

4343
error[E0452]: malformed lint attribute input
44-
--> $DIR/reasons-erroneous.rs:31:36
44+
--> $DIR/reasons-erroneous.rs:29:36
4545
|
4646
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
4747
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
4848

4949
error[E0452]: malformed lint attribute input
50-
--> $DIR/reasons-erroneous.rs:40:44
50+
--> $DIR/reasons-erroneous.rs:38:44
5151
|
5252
LL | #![warn(ellipsis_inclusive_range_patterns, reason = "born barren", reason = "a freak growth")]
5353
| ^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
5454

5555
error[E0452]: malformed lint attribute input
56-
--> $DIR/reasons-erroneous.rs:45:25
56+
--> $DIR/reasons-erroneous.rs:43:25
5757
|
5858
LL | #![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)]
5959
| ^^^^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
6060

6161
error[E0452]: malformed lint attribute input
62-
--> $DIR/reasons-erroneous.rs:3:58
62+
--> $DIR/reasons-erroneous.rs:1:58
6363
|
6464
LL | #![warn(absolute_paths_not_starting_with_crate, reason = 0)]
6565
| ^ reason must be a string literal
6666

6767
error[E0452]: malformed lint attribute input
68-
--> $DIR/reasons-erroneous.rs:8:40
68+
--> $DIR/reasons-erroneous.rs:6:40
6969
|
7070
LL | #![warn(anonymous_parameters, reason = b"consider these, for we have condemned them")]
7171
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ reason must be a string literal
7272

7373
error[E0452]: malformed lint attribute input
74-
--> $DIR/reasons-erroneous.rs:13:29
74+
--> $DIR/reasons-erroneous.rs:11:29
7575
|
7676
LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")]
7777
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
7878

7979
error[E0452]: malformed lint attribute input
80-
--> $DIR/reasons-erroneous.rs:13:29
80+
--> $DIR/reasons-erroneous.rs:11:29
8181
|
8282
LL | #![warn(bare_trait_objects, reasons = "leaders to no sure land, guides their bearings lost")]
8383
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
8484

8585
error[E0452]: malformed lint attribute input
86-
--> $DIR/reasons-erroneous.rs:22:23
86+
--> $DIR/reasons-erroneous.rs:20:23
8787
|
8888
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
8989
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
9090

9191
error[E0452]: malformed lint attribute input
92-
--> $DIR/reasons-erroneous.rs:22:23
92+
--> $DIR/reasons-erroneous.rs:20:23
9393
|
9494
LL | #![warn(box_pointers, blerp = "or in league with robbers have reversed the signposts")]
9595
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
9696

9797
error[E0452]: malformed lint attribute input
98-
--> $DIR/reasons-erroneous.rs:31:36
98+
--> $DIR/reasons-erroneous.rs:29:36
9999
|
100100
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
101101
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
102102

103103
error[E0452]: malformed lint attribute input
104-
--> $DIR/reasons-erroneous.rs:31:36
104+
--> $DIR/reasons-erroneous.rs:29:36
105105
|
106106
LL | #![warn(elided_lifetimes_in_paths, reason("disrespectful to ancestors", "irresponsible to heirs"))]
107107
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ bad attribute argument
108108

109109
error[E0452]: malformed lint attribute input
110-
--> $DIR/reasons-erroneous.rs:40:44
110+
--> $DIR/reasons-erroneous.rs:38:44
111111
|
112112
LL | #![warn(ellipsis_inclusive_range_patterns, reason = "born barren", reason = "a freak growth")]
113113
| ^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
114114

115115
error[E0452]: malformed lint attribute input
116-
--> $DIR/reasons-erroneous.rs:45:25
116+
--> $DIR/reasons-erroneous.rs:43:25
117117
|
118118
LL | #![warn(keyword_idents, reason = "root in rubble", macro_use_extern_crate)]
119119
| ^^^^^^^^^^^^^^^^^^^^^^^^^ reason in lint attribute must come last
120120

121121
warning: unknown lint: `reason`
122-
--> $DIR/reasons-erroneous.rs:50:39
122+
--> $DIR/reasons-erroneous.rs:48:39
123123
|
124124
LL | #![warn(missing_copy_implementations, reason)]
125125
| ^^^^^^

src/test/ui/lint/reasons-forbidden.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lint_reasons)]
2-
31
// If you turn off deduplicate diagnostics (which rustc turns on by default but
42
// compiletest turns off when it runs ui tests), then the errors are
53
// (unfortunately) repeated here because the checking is done as we read in the

src/test/ui/lint/reasons-forbidden.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0453]: allow(unsafe_code) incompatible with previous forbid
2-
--> $DIR/reasons-forbidden.rs:25:13
2+
--> $DIR/reasons-forbidden.rs:23:13
33
|
44
LL | unsafe_code,
55
| ----------- `forbid` level set here
@@ -10,7 +10,7 @@ LL | #[allow(unsafe_code)]
1010
= note: our errors & omissions insurance policy doesn't cover unsafe Rust
1111

1212
error: usage of an `unsafe` block
13-
--> $DIR/reasons-forbidden.rs:29:5
13+
--> $DIR/reasons-forbidden.rs:27:5
1414
|
1515
LL | / unsafe {
1616
LL | |
@@ -21,7 +21,7 @@ LL | | }
2121
|
2222
= note: our errors & omissions insurance policy doesn't cover unsafe Rust
2323
note: the lint level is defined here
24-
--> $DIR/reasons-forbidden.rs:14:5
24+
--> $DIR/reasons-forbidden.rs:12:5
2525
|
2626
LL | unsafe_code,
2727
| ^^^^^^^^^^^

src/test/ui/lint/reasons.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
// check-pass
22

3-
#![feature(lint_reasons)]
43
#![warn(elided_lifetimes_in_paths,
54
//~^ NOTE the lint level is defined here
65
reason = "explicit anonymous lifetimes aid reasoning about ownership")]

0 commit comments

Comments
 (0)