Skip to content

Commit 522778e

Browse files
committed
Move query-dep-graph opt check to attr parsing
1 parent de70679 commit 522778e

File tree

5 files changed

+21
-27
lines changed

5 files changed

+21
-27
lines changed

compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_span::Symbol;
1010

1111
use super::prelude::*;
1212
use super::util::parse_single_integer;
13-
use crate::session_diagnostics::RustcScalableVectorCountOutOfRange;
13+
use crate::session_diagnostics::{AttributeRequiresOpt, RustcScalableVectorCountOutOfRange};
1414

1515
pub(crate) struct RustcMainParser;
1616

@@ -543,6 +543,9 @@ impl<S: Stage> CombineAttributeParser<S> for RustcCleanParser {
543543
cx: &mut AcceptContext<'_, '_, S>,
544544
args: &ArgParser,
545545
) -> impl IntoIterator<Item = Self::Item> {
546+
if !cx.cx.sess.opts.unstable_opts.query_dep_graph {
547+
cx.emit_err(AttributeRequiresOpt { span: cx.attr_span, opt: "-Z query-dep-graph" });
548+
}
546549
let Some(list) = args.list() else {
547550
cx.expected_list(cx.attr_span, args);
548551
return None;
@@ -641,6 +644,9 @@ impl<S: Stage> SingleAttributeParser<S> for RustcIfThisChangedParser {
641644
const TEMPLATE: AttributeTemplate = template!(Word, List: &["DepNode"]);
642645

643646
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
647+
if !cx.cx.sess.opts.unstable_opts.query_dep_graph {
648+
cx.emit_err(AttributeRequiresOpt { span: cx.attr_span, opt: "-Z query-dep-graph" });
649+
}
644650
match args {
645651
ArgParser::NoArgs => Some(AttributeKind::RustcIfThisChanged(cx.attr_span, None)),
646652
ArgParser::List(list) => {
@@ -701,6 +707,9 @@ impl<S: Stage> CombineAttributeParser<S> for RustcThenThisWouldNeedParser {
701707
cx: &mut AcceptContext<'_, '_, S>,
702708
args: &ArgParser,
703709
) -> impl IntoIterator<Item = Self::Item> {
710+
if !cx.cx.sess.opts.unstable_opts.query_dep_graph {
711+
cx.emit_err(AttributeRequiresOpt { span: cx.attr_span, opt: "-Z query-dep-graph" });
712+
}
704713
let Some(item) = args.list().and_then(|l| l.single()) else {
705714
cx.expected_single_argument(cx.inner_span);
706715
return None;

compiler/rustc_attr_parsing/src/session_diagnostics.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -532,6 +532,14 @@ pub(crate) struct RustcScalableVectorCountOutOfRange {
532532
pub n: u128,
533533
}
534534

535+
#[derive(Diagnostic)]
536+
#[diag("attribute requires {$opt} to be enabled")]
537+
pub(crate) struct AttributeRequiresOpt {
538+
#[primary_span]
539+
pub span: Span,
540+
pub opt: &'static str,
541+
}
542+
535543
pub(crate) enum AttributeParseErrorReason<'a> {
536544
ExpectedNoArgs,
537545
ExpectedStringLiteral {

compiler/rustc_passes/messages.ftl

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -439,9 +439,6 @@ passes_rustc_allow_const_fn_unstable =
439439
attribute should be applied to `const fn`
440440
.label = not a `const fn`
441441
442-
passes_rustc_clean =
443-
attribute requires -Z query-dep-graph to be enabled
444-
445442
passes_rustc_const_stable_indirect_pairing =
446443
`const_stable_indirect` attribute does not make sense on `rustc_const_stable` function, its behavior is already implied
447444

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -231,14 +231,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
231231
self.check_rustc_must_implement_one_of(*attr_span, fn_names, hir_id,target)
232232
},
233233
Attribute::Parsed(AttributeKind::DoNotRecommend{attr_span}) => {self.check_do_not_recommend(*attr_span, hir_id, target, item)},
234-
Attribute::Parsed(AttributeKind::RustcClean(attrs)) => {
235-
for attr in attrs {
236-
self.check_rustc_clean(attr.span);
237-
}
238-
},
239-
Attribute::Parsed(AttributeKind::RustcIfThisChanged(span, _) | AttributeKind::RustcThenThisWouldNeed(span, _)) => {
240-
self.check_rustc_clean(*span);
241-
}
242234
Attribute::Parsed(
243235
// tidy-alphabetical-start
244236
AttributeKind::RustcAllowIncoherentImpl(..)
@@ -300,6 +292,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
300292
| AttributeKind::RustcAsPtr(..)
301293
| AttributeKind::RustcBodyStability { .. }
302294
| AttributeKind::RustcBuiltinMacro { .. }
295+
| AttributeKind::RustcClean(..)
303296
| AttributeKind::RustcCoherenceIsCore(..)
304297
| AttributeKind::RustcCoinductive(..)
305298
| AttributeKind::RustcConfusables { .. }
@@ -315,6 +308,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
315308
| AttributeKind::RustcDynIncompatibleTrait(..)
316309
| AttributeKind::RustcHasIncoherentInherentImpls
317310
| AttributeKind::RustcHiddenTypeOfOpaques
311+
| AttributeKind::RustcIfThisChanged(..)
318312
| AttributeKind::RustcLayout(..)
319313
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
320314
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
@@ -343,6 +337,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
343337
| AttributeKind::RustcSkipDuringMethodDispatch { .. }
344338
| AttributeKind::RustcSpecializationTrait(..)
345339
| AttributeKind::RustcStdInternalSymbol (..)
340+
| AttributeKind::RustcThenThisWouldNeed(..)
346341
| AttributeKind::RustcUnsafeSpecializationMarker(..)
347342
| AttributeKind::RustcVariance
348343
| AttributeKind::RustcVarianceOfOpaques
@@ -1264,14 +1259,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12641259
}
12651260
}
12661261

1267-
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
1268-
/// option is passed to the compiler.
1269-
fn check_rustc_clean(&self, span: Span) {
1270-
if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
1271-
self.dcx().emit_err(errors::RustcClean { span });
1272-
}
1273-
}
1274-
12751262
/// Checks if the `#[repr]` attributes on `item` are valid.
12761263
fn check_repr(
12771264
&self,

compiler/rustc_passes/src/errors.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,13 +217,6 @@ pub(crate) struct RustcLegacyConstGenericsIndexExceed {
217217
pub arg_count: usize,
218218
}
219219

220-
#[derive(Diagnostic)]
221-
#[diag(passes_rustc_clean)]
222-
pub(crate) struct RustcClean {
223-
#[primary_span]
224-
pub span: Span,
225-
}
226-
227220
#[derive(Diagnostic)]
228221
#[diag(passes_repr_conflicting, code = E0566)]
229222
pub(crate) struct ReprConflicting {

0 commit comments

Comments
 (0)