Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8b14e23

Browse files
committed
RFC 2383: Stabilize lint_reasons 🎉
1 parent d929a42 commit 8b14e23

File tree

89 files changed

+177
-257
lines changed

Some content is hidden

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

89 files changed

+177
-257
lines changed

compiler/rustc_builtin_macros/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
#![feature(decl_macro)]
1313
#![feature(if_let_guard)]
1414
#![feature(let_chains)]
15-
#![feature(lint_reasons)]
15+
#![cfg_attr(bootstrap, feature(lint_reasons))]
1616
#![feature(proc_macro_internals)]
1717
#![feature(proc_macro_quote)]
1818
#![feature(rustdoc_internals)]

compiler/rustc_data_structures/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#![allow(internal_features)]
1111
#![allow(rustc::default_hash_types)]
1212
#![allow(rustc::potential_query_instability)]
13+
#![cfg_attr(bootstrap, feature(lint_reasons))]
1314
#![cfg_attr(not(parallel_compiler), feature(cell_leak))]
1415
#![deny(unsafe_op_in_unsafe_fn)]
1516
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
@@ -24,7 +25,6 @@
2425
#![feature(extend_one)]
2526
#![feature(hash_raw_entry)]
2627
#![feature(hasher_prefixfree_extras)]
27-
#![feature(lint_reasons)]
2828
#![feature(macro_metavar_expr)]
2929
#![feature(map_try_insert)]
3030
#![feature(min_specialization)]

compiler/rustc_feature/src/accepted.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ declare_features! (
232232
(accepted, label_break_value, "1.65.0", Some(48594)),
233233
/// Allows `let...else` statements.
234234
(accepted, let_else, "1.65.0", Some(87335)),
235+
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
236+
(accepted, lint_reasons, "CURRENT_RUSTC_VERSION", Some(54503)),
235237
/// Allows `break {expr}` with a value inside `loop`s.
236238
(accepted, loop_break_value, "1.19.0", Some(37339)),
237239
/// Allows use of `?` as the Kleene "at most one" operator in macros.

compiler/rustc_feature/src/builtin_attrs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
369369
allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
370370
DuplicatesOk, EncodeCrossCrate::No,
371371
),
372-
gated!(
373-
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk,
374-
EncodeCrossCrate::No, lint_reasons, experimental!(expect)
372+
ungated!(
373+
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
374+
DuplicatesOk, EncodeCrossCrate::No,
375375
),
376376
ungated!(
377377
forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),

compiler/rustc_feature/src/unstable.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -512,8 +512,6 @@ declare_features! (
512512
/// Allows using `#[link(kind = "link-arg", name = "...")]`
513513
/// to pass custom arguments to the linker.
514514
(unstable, link_arg_attribute, "1.76.0", Some(99427)),
515-
/// Allows using `reason` in lint attributes and the `#[expect(lint)]` lint check.
516-
(unstable, lint_reasons, "1.31.0", Some(54503)),
517515
/// Give access to additional metadata about declarative macro meta-variables.
518516
(unstable, macro_metavar_expr, "1.61.0", Some(83527)),
519517
/// Provides a way to concatenate identifiers using metavariable expressions.

compiler/rustc_lint/src/expect.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,18 +3,13 @@ use rustc_middle::query::Providers;
33
use rustc_middle::ty::TyCtxt;
44
use rustc_session::lint::builtin::UNFULFILLED_LINT_EXPECTATIONS;
55
use rustc_session::lint::LintExpectationId;
6-
use rustc_span::symbol::sym;
76
use rustc_span::Symbol;
87

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

1312
fn check_expectations(tcx: TyCtxt<'_>, tool_filter: Option<Symbol>) {
14-
if !tcx.features().active(sym::lint_reasons) {
15-
return;
16-
}
17-
1813
let lint_expectations = tcx.lint_expectations(());
1914
let fulfilled_expectations = tcx.dcx().steal_fulfilled_expectation_ids();
2015

compiler/rustc_lint/src/levels.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ use rustc_session::lint::{
3737
},
3838
Level, Lint, LintExpectationId, LintId,
3939
};
40-
use rustc_session::parse::feature_err;
4140
use rustc_session::Session;
4241
use rustc_span::symbol::{sym, Symbol};
4342
use rustc_span::{Span, DUMMY_SP};
@@ -788,15 +787,6 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
788787
ast::MetaItemKind::NameValue(ref name_value) => {
789788
if item.path == sym::reason {
790789
if let ast::LitKind::Str(rationale, _) = name_value.kind {
791-
if !self.features.lint_reasons {
792-
feature_err(
793-
&self.sess,
794-
sym::lint_reasons,
795-
item.span,
796-
"lint reasons are experimental",
797-
)
798-
.emit();
799-
}
800790
reason = Some(rationale);
801791
} else {
802792
sess.dcx().emit_err(MalformedAttribute {

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -608,13 +608,13 @@ declare_lint! {
608608
}
609609

610610
declare_lint! {
611-
/// The `unfulfilled_lint_expectations` lint detects lint trigger expectations
612-
/// that have not been fulfilled.
611+
/// The `unfulfilled_lint_expectations` lint warns if a lint expectation is
612+
/// unfulfilled.
613613
///
614614
/// ### Example
615615
///
616616
/// ```rust
617-
/// #![feature(lint_reasons)]
617+
/// #![cfg_attr(bootstrap, feature(lint_reasons))]
618618
///
619619
/// #[expect(unused_variables)]
620620
/// let x = 10;
@@ -625,24 +625,14 @@ declare_lint! {
625625
///
626626
/// ### Explanation
627627
///
628-
/// It was expected that the marked code would emit a lint. This expectation
629-
/// has not been fulfilled.
628+
/// The `#[expect]` attribute can be used to create a lint expectation. The
629+
/// expectation is fulfilled, if a `#[warn]` attribute at the same location
630+
/// would result in a lint emission. If the expectation is unfulfilled,
631+
/// because no lint was emitted, this lint will be emitted on the attribute.
630632
///
631-
/// The `expect` attribute can be removed if this is intended behavior otherwise
632-
/// it should be investigated why the expected lint is no longer issued.
633-
///
634-
/// In rare cases, the expectation might be emitted at a different location than
635-
/// shown in the shown code snippet. In most cases, the `#[expect]` attribute
636-
/// works when added to the outer scope. A few lints can only be expected
637-
/// on a crate level.
638-
///
639-
/// Part of RFC 2383. The progress is being tracked in [#54503]
640-
///
641-
/// [#54503]: https://github.com/rust-lang/rust/issues/54503
642633
pub UNFULFILLED_LINT_EXPECTATIONS,
643634
Warn,
644-
"unfulfilled lint expectation",
645-
@feature_gate = rustc_span::sym::lint_reasons;
635+
"unfulfilled lint expectation"
646636
}
647637

648638
declare_lint! {

src/tools/rust-analyzer/crates/hir-expand/src/inert_attr_macro.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,9 @@ pub const INERT_ATTRIBUTES: &[BuiltinAttribute] = &[
142142
allow, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
143143
DuplicatesOk, @only_local: true,
144144
),
145-
gated!(
146-
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#), DuplicatesOk,
147-
lint_reasons, experimental!(expect)
145+
ungated!(
146+
expect, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),
147+
DuplicatesOk, @only_local: true,
148148
),
149149
ungated!(
150150
forbid, Normal, template!(List: r#"lint1, lint2, ..., /*opt*/ reason = "...""#),

tests/rustdoc-ui/lints/expect-tool-lint-rfc-2383.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//@ check-pass
2-
#![feature(lint_reasons)]
32

43
//! This file tests the `#[expect]` attribute implementation for tool lints. The same
54
//! file is used to test clippy and rustdoc. Any changes to this file should be synced

0 commit comments

Comments
 (0)