1
Fork 0

Auto merge of #111780 - weiznich:diagnostic_namespace, r=petrochenkov

Diagnostic namespace

This PR implements the basic infrastructure for accepting the `#[diagnostic]` attribute tool namespace as specified in https://github.com/rust-lang/rfcs/pull/3368. Note: This RFC is not merged yet, but it seems like it will be accepted soon. I open this PR early on to get feedback on the actual implementation as soon as possible. This hopefully enables getting at least the diagnostic namespace to stable rust "soon", so that crates do not need to bump their MSRV if we stabilize actual attributes in this namespace.

 This PR only adds infrastructure accept attributes from this namespace, it does not add any specific attribute. Therefore the compiler will emit a lint warning for each attribute that's actually used. This namespace is added behind a feature flag, so it will be only available on a nightly compiler for now.

cc `@estebank` as they've supported me in planing, specifying and implementing this feature.
This commit is contained in:
bors 2023-07-28 14:18:29 +00:00
commit 317ec04d18
15 changed files with 202 additions and 4 deletions

View file

@ -3400,6 +3400,7 @@ declare_lint_pass! {
UNFULFILLED_LINT_EXPECTATIONS,
UNINHABITED_STATIC,
UNKNOWN_CRATE_TYPES,
UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
UNKNOWN_LINTS,
UNNAMEABLE_TYPES,
UNREACHABLE_CODE,
@ -4380,3 +4381,27 @@ declare_lint! {
"effective visibility of a type is larger than the area in which it can be named",
@feature_gate = sym::type_privacy_lints;
}
declare_lint! {
/// The `unknown_diagnostic_attributes` lint detects unrecognized diagnostic attributes.
///
/// ### Example
///
/// ```rust
/// #![feature(diagnostic_namespace)]
/// #[diagnostic::does_not_exist]
/// struct Foo;
/// ```
///
/// {{produces}}
///
/// ### Explanation
///
/// It is usually a mistake to specify a diagnostic attribute that does not exist. Check
/// the spelling, and check the diagnostic attribute listing for the correct name. Also
/// consider if you are using an old version of the compiler, and the attribute
/// is only available in a newer version.
pub UNKNOWN_DIAGNOSTIC_ATTRIBUTES,
Warn,
"unrecognized diagnostic attribute"
}