Skip to content

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

+1-1
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

+1-1
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

+2
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

+3-3
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

-2
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

-5
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

-10
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

+8-18
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

+3-3
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

-1
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

tests/ui/async-await/in-trait/async-example-desugared-extra.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ check-pass
22
//@ edition: 2021
33

4-
#![feature(lint_reasons)]
5-
64
use std::future::Future;
75
use std::pin::Pin;
86
use std::task::Poll;

tests/ui/cfg/diagnostics-not-a-def.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lint_reasons)]
2-
31
pub mod inner {
42
#[expect(unexpected_cfgs)]
53
pub fn i_am_here() {

tests/ui/cfg/diagnostics-not-a-def.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0425]: cannot find function `i_am_not` in module `inner`
2-
--> $DIR/diagnostics-not-a-def.rs:14:12
2+
--> $DIR/diagnostics-not-a-def.rs:12:12
33
|
44
LL | inner::i_am_not();
55
| ^^^^^^^^ not found in `inner`

tests/ui/empty/empty-attributes.rs

-2
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

tests/ui/empty/empty-attributes.stderr

+9-9
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: attribute `repr` with an empty list has no effect
88
note: the lint level is defined here
9-
--> $DIR/empty-attributes.rs:3:9
9+
--> $DIR/empty-attributes.rs:1:9
1010
|
1111
LL | #![deny(unused_attributes)]
1212
| ^^^^^^^^^^^^^^^^^
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

tests/ui/error-codes/E0602.stderr

+6-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,11 @@ warning[E0602]: unknown lint: `bogus`
1313
= note: requested on the command line with `-D bogus`
1414
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
1515

16-
warning: 3 warnings emitted
16+
warning[E0602]: unknown lint: `bogus`
17+
|
18+
= note: requested on the command line with `-D bogus`
19+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
20+
21+
warning: 4 warnings emitted
1722

1823
For more information about this error, try `rustc --explain E0602`.

tests/ui/feature-gates/feature-gate-lint-reasons.rs

-5
This file was deleted.

tests/ui/feature-gates/feature-gate-lint-reasons.stderr

-24
This file was deleted.

tests/ui/impl-trait/in-trait/auxiliary/rpitit.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![feature(lint_reasons)]
2-
31
use std::ops::Deref;
42

53
pub trait Foo {

tests/ui/impl-trait/in-trait/deep-match-works.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(lint_reasons)]
4-
53
pub struct Wrapper<T>(T);
64

75
pub trait Foo {

tests/ui/impl-trait/in-trait/foreign-dyn-error.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | let _: &dyn rpitit::Foo = todo!();
55
| ^^^^^^^^^^^^^^^^ `Foo` cannot be made into an object
66
|
77
note: for a trait to be "object safe" it needs to allow building a vtable to allow the call to be resolvable dynamically; for more information visit <https://doc.rust-lang.org/reference/items/traits.html#object-safety>
8-
--> $DIR/auxiliary/rpitit.rs:6:21
8+
--> $DIR/auxiliary/rpitit.rs:4:21
99
|
1010
LL | fn bar(self) -> impl Deref<Target = impl Sized>;
1111
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait cannot be made into an object because method `bar` references an `impl Trait` type in its return type

tests/ui/impl-trait/in-trait/foreign.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//@ check-pass
22
//@ aux-build: rpitit.rs
33

4-
#![feature(lint_reasons)]
5-
64
extern crate rpitit;
75

86
use rpitit::{Foo, Foreign};

tests/ui/impl-trait/in-trait/foreign.stderr

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
warning: impl trait in impl method signature does not match trait method signature
2-
--> $DIR/foreign.rs:23:21
2+
--> $DIR/foreign.rs:21:21
33
|
44
LL | fn bar(self) -> Arc<String> {
55
| ^^^^^^^^^^^
66
|
77
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
88
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
99
note: the lint level is defined here
10-
--> $DIR/foreign.rs:22:12
10+
--> $DIR/foreign.rs:20:12
1111
|
1212
LL | #[warn(refining_impl_trait)]
1313
| ^^^^^^^^^^^^^^^^^^^
@@ -18,15 +18,15 @@ LL | fn bar(self) -> impl Deref<Target = impl Sized> {
1818
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1919

2020
warning: impl trait in impl method signature does not match trait method signature
21-
--> $DIR/foreign.rs:33:21
21+
--> $DIR/foreign.rs:31:21
2222
|
2323
LL | fn bar(self) -> Arc<String> {
2424
| ^^^^^^^^^^^
2525
|
2626
= note: add `#[allow(refining_impl_trait)]` if it is intended for this to be part of the public API of this crate
2727
= note: we are soliciting feedback, see issue #121718 <https://github.com/rust-lang/rust/issues/121718> for more information
2828
note: the lint level is defined here
29-
--> $DIR/foreign.rs:31:12
29+
--> $DIR/foreign.rs:29:12
3030
|
3131
LL | #[warn(refining_impl_trait)]
3232
| ^^^^^^^^^^^^^^^^^^^

tests/ui/impl-trait/in-trait/nested-rpitit.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(lint_reasons)]
4-
53
use std::fmt::Display;
64
use std::ops::Deref;
75

tests/ui/impl-trait/in-trait/reveal.rs

-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
//@ check-pass
22

3-
#![feature(lint_reasons)]
4-
53
pub trait Foo {
64
fn f() -> Box<impl Sized>;
75
}

0 commit comments

Comments
 (0)