Skip to content

Commit 96e453d

Browse files
committed
Port #[rustc_lint_query_instability] to parsed attribute
1 parent 81d2036 commit 96e453d

File tree

8 files changed

+42
-18
lines changed

8 files changed

+42
-18
lines changed

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,21 @@ impl<S: Stage> NoArgsAttributeParser<S> for RustcLintOptTyParser {
126126
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintOptTy;
127127
}
128128

129+
pub(crate) struct RustcLintQueryInstabilityParser;
130+
131+
impl<S: Stage> NoArgsAttributeParser<S> for RustcLintQueryInstabilityParser {
132+
const PATH: &[Symbol] = &[sym::rustc_lint_query_instability];
133+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Warn;
134+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[
135+
Allow(Target::Fn),
136+
Allow(Target::Method(MethodKind::Inherent)),
137+
Allow(Target::Method(MethodKind::Trait { body: false })),
138+
Allow(Target::Method(MethodKind::Trait { body: true })),
139+
Allow(Target::Method(MethodKind::TraitImpl)),
140+
]);
141+
const CREATE: fn(Span) -> AttributeKind = |_| AttributeKind::RustcLintQueryInstability;
142+
}
143+
129144
pub(crate) struct RustcObjectLifetimeDefaultParser;
130145

131146
impl<S: Stage> SingleAttributeParser<S> for RustcObjectLifetimeDefaultParser {

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,8 @@ use crate::attributes::prototype::CustomMirParser;
6161
use crate::attributes::repr::{AlignParser, AlignStaticParser, ReprParser};
6262
use crate::attributes::rustc_internal::{
6363
RustcLayoutScalarValidRangeEndParser, RustcLayoutScalarValidRangeStartParser,
64-
RustcLegacyConstGenericsParser, RustcLintOptTyParser, RustcMainParser,
65-
RustcNeverReturnsNullPointerParser, RustcNoImplicitAutorefsParser,
64+
RustcLegacyConstGenericsParser, RustcLintOptTyParser, RustcLintQueryInstabilityParser,
65+
RustcMainParser, RustcNeverReturnsNullPointerParser, RustcNoImplicitAutorefsParser,
6666
RustcObjectLifetimeDefaultParser, RustcScalableVectorParser,
6767
RustcSimdMonomorphizeLaneLimitParser,
6868
};
@@ -257,6 +257,7 @@ attribute_parsers!(
257257
Single<WithoutArgs<PubTransparentParser>>,
258258
Single<WithoutArgs<RustcCoherenceIsCoreParser>>,
259259
Single<WithoutArgs<RustcLintOptTyParser>>,
260+
Single<WithoutArgs<RustcLintQueryInstabilityParser>>,
260261
Single<WithoutArgs<RustcMainParser>>,
261262
Single<WithoutArgs<RustcNeverReturnsNullPointerParser>>,
262263
Single<WithoutArgs<RustcNoImplicitAutorefsParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,6 +878,9 @@ pub enum AttributeKind {
878878
/// Represents `#[rustc_lint_opt_ty]`
879879
RustcLintOptTy,
880880

881+
/// Represents `#[rustc_lint_query_instability]`
882+
RustcLintQueryInstability,
883+
881884
/// Represents `#[rustc_main]`.
882885
RustcMain,
883886

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ impl AttributeKind {
9595
RustcLayoutScalarValidRangeStart(..) => Yes,
9696
RustcLegacyConstGenerics { .. } => Yes,
9797
RustcLintOptTy => Yes,
98+
RustcLintQueryInstability => Yes,
9899
RustcMain => No,
99100
RustcNeverReturnsNullPointer => Yes,
100101
RustcNoImplicitAutorefs => Yes,

compiler/rustc_lint/src/internal.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ impl<'tcx> LateLintPass<'tcx> for QueryStability {
9191
ty::Instance::try_resolve(cx.tcx, cx.typing_env(), callee_def_id, generic_args)
9292
{
9393
let def_id = instance.def_id();
94-
if cx.tcx.has_attr(def_id, sym::rustc_lint_query_instability) {
94+
if find_attr!(cx.tcx.get_all_attrs(def_id), AttributeKind::RustcLintQueryInstability) {
9595
cx.emit_span_lint(
9696
POTENTIAL_QUERY_INSTABILITY,
9797
span,
@@ -151,7 +151,10 @@ fn has_unstable_into_iter_predicate<'tcx>(
151151
};
152152
// Does the input type's `IntoIterator` implementation have the
153153
// `rustc_lint_query_instability` attribute on its `into_iter` method?
154-
if cx.tcx.has_attr(instance.def_id(), sym::rustc_lint_query_instability) {
154+
if find_attr!(
155+
cx.tcx.get_all_attrs(instance.def_id()),
156+
AttributeKind::RustcLintQueryInstability
157+
) {
155158
return true;
156159
}
157160
}

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
259259
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
260260
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
261261
| AttributeKind::RustcLintOptTy
262+
| AttributeKind::RustcLintQueryInstability
262263
| AttributeKind::RustcNeverReturnsNullPointer
263264
| AttributeKind::RustcScalableVector { .. }
264265
| AttributeKind::RustcSimdMonomorphizeLaneLimit(..)
@@ -307,9 +308,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
307308
self.check_diagnostic_on_const(attr.span(), hir_id, target, item)
308309
}
309310
[sym::thread_local, ..] => self.check_thread_local(attr, span, target),
310-
[sym::rustc_lint_query_instability, ..] => {
311-
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
312-
}
313311
[sym::rustc_lint_untracked_query_information, ..] => {
314312
self.check_applied_to_fn_or_method(hir_id, attr.span(), span, target)
315313
}

tests/ui/internal-lints/query_stability_incorrect.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#![feature(rustc_attrs)]
44

55
#[rustc_lint_query_instability]
6-
//~^ ERROR attribute should be applied to a function
6+
//~^ ERROR `#[rustc_lint_query_instability]` attribute cannot be used on structs
77
struct Foo;
88

99
impl Foo {
Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
error: malformed `rustc_lint_query_instability` attribute input
2-
--> $DIR/query_stability_incorrect.rs:10:5
3-
|
4-
LL | #[rustc_lint_query_instability(a)]
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[rustc_lint_query_instability]`
6-
7-
error: attribute should be applied to a function definition
1+
error: `#[rustc_lint_query_instability]` attribute cannot be used on structs
82
--> $DIR/query_stability_incorrect.rs:5:1
93
|
104
LL | #[rustc_lint_query_instability]
115
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12-
LL |
13-
LL | struct Foo;
14-
| ----------- not a function definition
6+
|
7+
= help: `#[rustc_lint_query_instability]` can only be applied to functions
8+
9+
error[E0565]: malformed `rustc_lint_query_instability` attribute input
10+
--> $DIR/query_stability_incorrect.rs:10:5
11+
|
12+
LL | #[rustc_lint_query_instability(a)]
13+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^---^
14+
| | |
15+
| | didn't expect any arguments here
16+
| help: must be of the form: `#[rustc_lint_query_instability]`
1517

1618
error: aborting due to 2 previous errors
1719

20+
For more information about this error, try `rustc --explain E0565`.

0 commit comments

Comments
 (0)