Skip to content

Commit fe719f9

Browse files
committed
Unify diagnostic namespace lints as requested in review
Also add the feature gate to the lint
1 parent 6860d84 commit fe719f9

File tree

8 files changed

+19
-41
lines changed

8 files changed

+19
-41
lines changed

compiler/rustc_hir_analysis/src/check/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ use rustc_middle::ty::{
2929
TypeVisitableExt,
3030
};
3131
use rustc_session::lint::builtin::{
32-
MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNINHABITED_STATIC, UNSUPPORTED_CALLING_CONVENTIONS,
32+
UNINHABITED_STATIC, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES, UNSUPPORTED_CALLING_CONVENTIONS,
3333
};
3434
use rustc_span::symbol::sym;
3535
use rustc_span::{self, Span};
@@ -582,7 +582,7 @@ fn check_item_type(tcx: TyCtxt<'_>, id: hir::ItemId) {
582582
.next()
583583
{
584584
tcx.emit_spanned_lint(
585-
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
585+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
586586
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()),
587587
vec![attr.span],
588588
DiagnosticOnUnimplementedOnlyForTraits,

compiler/rustc_lint_defs/src/builtin.rs

+6-28
Original file line numberDiff line numberDiff line change
@@ -3442,8 +3442,8 @@ declare_lint_pass! {
34423442
UNFULFILLED_LINT_EXPECTATIONS,
34433443
UNINHABITED_STATIC,
34443444
UNKNOWN_CRATE_TYPES,
3445-
UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
34463445
UNKNOWN_LINTS,
3446+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
34473447
UNNAMEABLE_TEST_ITEMS,
34483448
UNNAMEABLE_TYPES,
34493449
UNREACHABLE_CODE,
@@ -4463,7 +4463,8 @@ declare_lint! {
44634463
}
44644464

44654465
declare_lint! {
4466-
/// The `unknown_diagnostic_attributes` lint detects unrecognized diagnostic attributes.
4466+
/// The `unknown_or_malformed_diagnostic_attributes` lint detects unrecognized or otherwise malformed
4467+
/// diagnostic attributes.
44674468
///
44684469
/// ### Example
44694470
///
@@ -4482,33 +4483,10 @@ declare_lint! {
44824483
/// the spelling, and check the diagnostic attribute listing for the correct name. Also
44834484
/// consider if you are using an old version of the compiler, and the attribute
44844485
/// is only available in a newer version.
4485-
pub UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
4486+
pub UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
44864487
Warn,
4487-
"unrecognized diagnostic attribute"
4488-
}
4489-
4490-
declare_lint! {
4491-
/// The `malformed_diagnostic_attributes` lint detects malformed diagnostic attributes.
4492-
///
4493-
/// ### Example
4494-
///
4495-
/// ```rust
4496-
/// #![feature(diagnostic_namespace)]
4497-
/// #[diagnostic::on_unimplemented]
4498-
/// struct Foo;
4499-
/// ```
4500-
///
4501-
/// {{produces}}
4502-
///
4503-
/// ### Explanation
4504-
///
4505-
/// It is usually a mistake to specify invalid options to an existing diagnostic attribute.
4506-
/// Check the spelling, and check the diagnostic attribute listing for the correct set of options.
4507-
/// Also consider if you are using an old version of the compiler. Certain options may only
4508-
/// be available on newer compiler versions
4509-
pub MALFORMED_DIAGNOSTIC_ATTRIBUTES,
4510-
Warn,
4511-
"unrecognized diagnostic attribute options"
4488+
"unrecognized or malformed diagnostic attribute",
4489+
@feature_gate = sym::diagnostic_namespace;
45124490
}
45134491

45144492
declare_lint! {

compiler/rustc_resolve/src/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use rustc_middle::middle::stability;
2525
use rustc_middle::ty::RegisteredTools;
2626
use rustc_middle::ty::{TyCtxt, Visibility};
2727
use rustc_session::lint::builtin::{
28-
LEGACY_DERIVE_HELPERS, SOFT_UNSTABLE, UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
28+
LEGACY_DERIVE_HELPERS, SOFT_UNSTABLE, UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
2929
};
3030
use rustc_session::lint::builtin::{UNUSED_MACROS, UNUSED_MACRO_RULES};
3131
use rustc_session::lint::BuiltinLintDiagnostics;
@@ -612,7 +612,7 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
612612
&& path.segments[1].ident.name != sym::on_unimplemented
613613
{
614614
self.tcx.sess.parse_sess.buffer_lint(
615-
UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
615+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
616616
path.segments[1].span(),
617617
node_id,
618618
"unknown diagnostic attribute",

compiler/rustc_trait_selection/src/traits/error_reporting/on_unimplemented.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hir::def_id::DefId;
99
use rustc_middle::ty::GenericArgsRef;
1010
use rustc_middle::ty::{self, GenericParamDefKind, TyCtxt};
1111
use rustc_parse_format::{ParseMode, Parser, Piece, Position};
12-
use rustc_session::lint::builtin::MALFORMED_DIAGNOSTIC_ATTRIBUTES;
12+
use rustc_session::lint::builtin::UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES;
1313
use rustc_span::symbol::{kw, sym, Symbol};
1414
use rustc_span::{Span, DUMMY_SP};
1515
use std::iter;
@@ -445,7 +445,7 @@ impl<'tcx> OnUnimplementedDirective {
445445

446446
if is_diagnostic_namespace_variant {
447447
tcx.emit_spanned_lint(
448-
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
448+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
449449
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()),
450450
vec![item.span()],
451451
NoValueInOnUnimplementedLint,
@@ -508,7 +508,7 @@ impl<'tcx> OnUnimplementedDirective {
508508
}))
509509
} else {
510510
tcx.emit_spanned_lint(
511-
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
511+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
512512
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()),
513513
vec![attr.span],
514514
NoValueInOnUnimplementedLint,
@@ -517,7 +517,7 @@ impl<'tcx> OnUnimplementedDirective {
517517
}
518518
} else if is_diagnostic_namespace_variant {
519519
tcx.emit_spanned_lint(
520-
MALFORMED_DIAGNOSTIC_ATTRIBUTES,
520+
UNKNOWN_OR_MALFORMED_DIAGNOSTIC_ATTRIBUTES,
521521
tcx.hir().local_def_id_to_hir_id(item_def_id.expect_local()),
522522
vec![attr.span],
523523
NoValueInOnUnimplementedLint,

tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#[diagnostic::non_existing_attribute]
22
//~^ERROR `#[diagnostic]` attribute name space is experimental [E0658]
3-
//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes]
3+
//~|WARNING unknown diagnostic attribute [unknown_or_malformed_diagnostic_attributes]
44
pub trait Bar {
55
}
66

77
#[diagnostic::non_existing_attribute(with_option = "foo")]
88
//~^ERROR `#[diagnostic]` attribute name space is experimental [E0658]
9-
//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes]
9+
//~|WARNING unknown diagnostic attribute [unknown_or_malformed_diagnostic_attributes]
1010
struct Foo;
1111

1212
fn main() {

tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ warning: unknown diagnostic attribute
2222
LL | #[diagnostic::non_existing_attribute]
2323
| ^^^^^^^^^^^^^^^^^^^^^^
2424
|
25-
= note: `#[warn(unknown_diagnostic_attributes)]` on by default
25+
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
2626

2727
warning: unknown diagnostic attribute
2828
--> $DIR/feature-gate-diagnostic_namespace.rs:7:15

tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: unknown diagnostic attribute
44
LL | #[diagnostic::non_existing_attribute]
55
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `#[warn(unknown_diagnostic_attributes)]` on by default
7+
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
88

99
warning: unknown diagnostic attribute
1010
--> $DIR/non_existing_attributes_accepted.rs:8:15

tests/ui/diagnostic_namespace/on_unimplemented/do_not_fail_parsing_on_invalid_options_1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ warning: malformed `on_unimplemented` attribute
44
LL | #[diagnostic::on_unimplemented(unsupported = "foo")]
55
| ^^^^^^^^^^^^^^^^^^^
66
|
7-
= note: `#[warn(malformed_diagnostic_attributes)]` on by default
7+
= note: `#[warn(unknown_or_malformed_diagnostic_attributes)]` on by default
88

99
warning: `#[diagnostic::on_unimplemented]` can only be applied to trait definitions
1010
--> $DIR/do_not_fail_parsing_on_invalid_options_1.rs:8:1

0 commit comments

Comments
 (0)