mirror of
https://github.com/rust-lang/rust.git
synced 2026-05-04 01:42:54 +03:00
Rollup merge of #150127 - Bryntet:parse_rustc_lint_untracked_query_information, r=JonathanBrouwer
Port `#[rustc_lint_untracked_query_information]` and `#[rustc_lint_diagnostics]` to using attribute parsers r? ``@JonathanBrouwer``
This commit is contained in:
@@ -117,6 +117,21 @@ fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<Attrib
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct RustcLintDiagnosticsParser;
|
||||
|
||||
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintDiagnosticsParser {
|
||||
const PATH: &[Symbol] = &[sym::rustc_lint_diagnostics];
|
||||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
|
||||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
|
||||
Allow(Target::Fn),
|
||||
Allow(Target::Method(MethodKind::Inherent)),
|
||||
Allow(Target::Method(MethodKind::Trait { body: false })),
|
||||
Allow(Target::Method(MethodKind::Trait { body: true })),
|
||||
Allow(Target::Method(MethodKind::TraitImpl)),
|
||||
]);
|
||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintDiagnostics;
|
||||
}
|
||||
|
||||
pub(crate) struct RustcLintOptDenyFieldAccessParser;
|
||||
|
||||
impl<S: Stage> SingleAttributeParser<S> for RustcLintOptDenyFieldAccessParser {
|
||||
@@ -165,6 +180,22 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcLintQueryInstabilityParser {
|
||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintQueryInstability;
|
||||
}
|
||||
|
||||
pub(crate) struct RustcLintUntrackedQueryInformationParser;
|
||||
|
||||
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintUntrackedQueryInformationParser {
|
||||
const PATH: &[Symbol] = &[sym::rustc_lint_untracked_query_information];
|
||||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
|
||||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
|
||||
Allow(Target::Fn),
|
||||
Allow(Target::Method(MethodKind::Inherent)),
|
||||
Allow(Target::Method(MethodKind::Trait { body: false })),
|
||||
Allow(Target::Method(MethodKind::Trait { body: true })),
|
||||
Allow(Target::Method(MethodKind::TraitImpl)),
|
||||
]);
|
||||
|
||||
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintUntrackedQueryInformation;
|
||||
}
|
||||
|
||||
pub(crate) struct RustcObjectLifetimeDefaultParser;
|
||||
|
||||
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {
|
||||
|
||||
@@ -61,8 +61,9 @@
|
||||
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
|
||||
use crate::attributes::rustc_internal::{
|
||||
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
|
||||
RustcLegacyConstGenericsParser, RustcLintOptDenyFieldAccessParser, RustcLintOptTyParser,
|
||||
RustcLintQueryInstabilityParser, RustcMainParser, RustcNeverReturnsNullPointerParser,
|
||||
RustcLegacyConstGenericsParser, RustcLintDiagnosticsParser, RustcLintOptDenyFieldAccessParser,
|
||||
RustcLintOptTyParser, RustcLintQueryInstabilityParser,
|
||||
RustcLintUntrackedQueryInformationParser, RustcMainParser, RustcNeverReturnsNullPointerParser,
|
||||
RustcNoImplicitAutorefsParser, RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
|
||||
RustcSimdMonomorphizeLaneLimitParser,
|
||||
};
|
||||
@@ -257,8 +258,10 @@ mod late {
|
||||
Single<WithoutArgs<ProcMacroParser>>,
|
||||
Single<WithoutArgs<PubTransparentParser>>,
|
||||
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
|
||||
Single<WithoutArgs<RustcLintDiagnosticsParser>>,
|
||||
Single<WithoutArgs<RustcLintOptTyParser>>,
|
||||
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
|
||||
Single<WithoutArgs<RustcLintUntrackedQueryInformationParser>>,
|
||||
Single<WithoutArgs<RustcMainParser>>,
|
||||
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
|
||||
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,
|
||||
|
||||
@@ -931,6 +931,9 @@ pub enum AttributeKind {
|
||||
/// Represents `#[rustc_legacy_const_generics]`
|
||||
RustcLegacyConstGenerics { fn_indexes: ThinVec<(usize, Span)>, attr_span: Span },
|
||||
|
||||
/// Represents `#[rustc_lint_diagnostics]`
|
||||
RustcLintDiagnostics,
|
||||
|
||||
/// Represents `#[rustc_lint_opt_deny_field_access]`
|
||||
RustcLintOptDenyFieldAccess { lint_message: Symbol },
|
||||
|
||||
@@ -940,6 +943,9 @@ pub enum AttributeKind {
|
||||
/// Represents `#[rustc_lint_query_instability]`
|
||||
RustcLintQueryInstability,
|
||||
|
||||
/// Represents `#[rustc_lint_untracked_query_information]`
|
||||
RustcLintUntrackedQueryInformation,
|
||||
|
||||
/// Represents `#[rustc_main]`.
|
||||
RustcMain,
|
||||
|
||||
|
||||
@@ -94,9 +94,11 @@ pub fn encode_cross_crate(&self) -> EncodeCrossCrate {
|
||||
RustcLayoutScalarValidRangeEnd(..) => Yes,
|
||||
RustcLayoutScalarValidRangeStart(..) => Yes,
|
||||
RustcLegacyConstGenerics { .. } => Yes,
|
||||
RustcLintDiagnostics => Yes,
|
||||
RustcLintOptDenyFieldAccess { .. } => Yes,
|
||||
RustcLintOptTy => Yes,
|
||||
RustcLintQueryInstability => Yes,
|
||||
RustcLintUntrackedQueryInformation => Yes,
|
||||
RustcMain => No,
|
||||
RustcNeverReturnsNullPointer => Yes,
|
||||
RustcNoImplicitAutorefs => Yes,
|
||||
|
||||
@@ -106,7 +106,10 @@ fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'tcx>) {
|
||||
);
|
||||
}
|
||||
|
||||
if cx.tcx.has_attr(def_id, sym::rustc_lint_untracked_query_information) {
|
||||
if find_attr!(
|
||||
cx.tcx.get_all_attrs(def_id),
|
||||
AttributeKind::RustcLintUntrackedQueryInformation
|
||||
) {
|
||||
cx.emit_span_lint(
|
||||
UNTRACKED_QUERY_INFORMATION,
|
||||
span,
|
||||
@@ -606,14 +609,14 @@ fn diagnostic_outside_of_impl<'cx>(
|
||||
else {
|
||||
return;
|
||||
};
|
||||
let has_attr = cx.tcx.has_attr(inst.def_id(), sym::rustc_lint_diagnostics);
|
||||
if !has_attr {
|
||||
|
||||
if !find_attr!(cx.tcx.get_all_attrs(inst.def_id()), AttributeKind::RustcLintDiagnostics) {
|
||||
return;
|
||||
};
|
||||
|
||||
for (hir_id, _parent) in cx.tcx.hir_parent_iter(current_id) {
|
||||
if let Some(owner_did) = hir_id.as_owner()
|
||||
&& cx.tcx.has_attr(owner_did, sym::rustc_lint_diagnostics)
|
||||
&& find_attr!(cx.tcx.get_all_attrs(owner_did), AttributeKind::RustcLintDiagnostics)
|
||||
{
|
||||
// The parent method is marked with `#[rustc_lint_diagnostics]`
|
||||
return;
|
||||
|
||||
@@ -484,13 +484,6 @@ passes_sanitize_attribute_not_allowed =
|
||||
.no_body = function has no body
|
||||
.help = sanitize attribute can be applied to a function (with body), impl block, or module
|
||||
|
||||
passes_should_be_applied_to_fn =
|
||||
attribute should be applied to a function definition
|
||||
.label = {$on_crate ->
|
||||
[true] cannot be applied to crates
|
||||
*[false] not a function definition
|
||||
}
|
||||
|
||||
passes_should_be_applied_to_static =
|
||||
attribute should be applied to a static
|
||||
.label = not a static
|
||||
|
||||
@@ -258,9 +258,11 @@ fn check_attributes(
|
||||
| AttributeKind::RustcNoImplicitAutorefs
|
||||
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
|
||||
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
|
||||
| AttributeKind::RustcLintDiagnostics
|
||||
| AttributeKind::RustcLintOptDenyFieldAccess { .. }
|
||||
| AttributeKind::RustcLintOptTy
|
||||
| AttributeKind::RustcLintQueryInstability
|
||||
| AttributeKind::RustcLintUntrackedQueryInformation
|
||||
| AttributeKind::RustcNeverReturnsNullPointer
|
||||
| AttributeKind::RustcScalableVector { .. }
|
||||
| AttributeKind::RustcSimdMonomorphizeLaneLimit(..)
|
||||
@@ -309,12 +311,6 @@ fn check_attributes(
|
||||
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
|
||||
}
|
||||
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
|
||||
[sym::rustc_lint_untracked_query_information, ..] => {
|
||||
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
|
||||
}
|
||||
[sym::rustc_lint_diagnostics, ..] => {
|
||||
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
|
||||
}
|
||||
[sym::rustc_clean, ..]
|
||||
| [sym::rustc_dirty, ..]
|
||||
| [sym::rustc_if_this_changed, ..]
|
||||
@@ -1230,25 +1226,6 @@ fn check_rustc_legacy_const_generics(
|
||||
}
|
||||
}
|
||||
|
||||
/// Helper function for checking that the provided attribute is only applied to a function or
|
||||
/// method.
|
||||
fn check_applied_to_fn_or_method(
|
||||
&self,
|
||||
hir_id: HirId,
|
||||
attr_span: Span,
|
||||
defn_span: Span,
|
||||
target: Target,
|
||||
) {
|
||||
let is_function = matches!(target, Target::Fn | Target::Method(..));
|
||||
if !is_function {
|
||||
self.dcx().emit_err(errors::AttrShouldBeAppliedToFn {
|
||||
attr_span,
|
||||
defn_span,
|
||||
on_crate: hir_id == CRATE_HIR_ID,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
|
||||
/// option is passed to the compiler.
|
||||
fn check_rustc_dirty_clean(&self, attr: &Attribute) {
|
||||
|
||||
@@ -80,16 +80,6 @@ pub(crate) struct OuterCrateLevelAttrSuggestion {
|
||||
#[diag(passes_inner_crate_level_attr)]
|
||||
pub(crate) struct InnerCrateLevelAttr;
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_should_be_applied_to_fn)]
|
||||
pub(crate) struct AttrShouldBeAppliedToFn {
|
||||
#[primary_span]
|
||||
pub attr_span: Span,
|
||||
#[label]
|
||||
pub defn_span: Span,
|
||||
pub on_crate: bool,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(passes_non_exhaustive_with_default_field_values)]
|
||||
pub(crate) struct NonExhaustiveWithDefaultFieldValues {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
#![feature(rustc_attrs)]
|
||||
|
||||
#[rustc_lint_diagnostics]
|
||||
//~^ ERROR attribute should be applied to a function
|
||||
//~^ ERROR `#[rustc_lint_diagnostics]` attribute cannot be used on structs
|
||||
struct Foo;
|
||||
|
||||
impl Foo {
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
error: malformed `rustc_lint_diagnostics` attribute input
|
||||
--> $DIR/diagnostics_incorrect.rs:10:5
|
||||
|
|
||||
LL | #[rustc_lint_diagnostics(a)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_lint_diagnostics]`
|
||||
|
||||
error: attribute should be applied to a function definition
|
||||
error: `#[rustc_lint_diagnostics]` attribute cannot be used on structs
|
||||
--> $DIR/diagnostics_incorrect.rs:5:1
|
||||
|
|
||||
LL | #[rustc_lint_diagnostics]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
LL |
|
||||
LL | struct Foo;
|
||||
| ----------- not a function definition
|
||||
|
|
||||
= help: `#[rustc_lint_diagnostics]` can only be applied to functions
|
||||
|
||||
error[E0565]: malformed `rustc_lint_diagnostics` attribute input
|
||||
--> $DIR/diagnostics_incorrect.rs:10:5
|
||||
|
|
||||
LL | #[rustc_lint_diagnostics(a)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^---^
|
||||
| | |
|
||||
| | didn't expect any arguments here
|
||||
| help: must be of the form: `#[rustc_lint_diagnostics]`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0565`.
|
||||
|
||||
Reference in New Issue
Block a user