Skip to content

Commit 25d87a9

Browse files
committed
Move query-dep-graph opt check to attr parsing
1 parent c409b8f commit 25d87a9

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;
@@ -648,6 +651,9 @@ impl<S: Stage> SingleAttributeParser<S> for RustcIfThisChangedParser {
648651
const TEMPLATE: AttributeTemplate = template!(Word, List: &["DepNode"]);
649652

650653
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser) -> Option<AttributeKind> {
654+
if !cx.cx.sess.opts.unstable_opts.query_dep_graph {
655+
cx.emit_err(AttributeRequiresOpt { span: cx.attr_span, opt: "-Z query-dep-graph" });
656+
}
651657
match args {
652658
ArgParser::NoArgs => Some(AttributeKind::RustcIfThisChanged(cx.attr_span, None)),
653659
ArgParser::List(list) => {
@@ -708,6 +714,9 @@ impl<S: Stage> CombineAttributeParser<S> for RustcThenThisWouldNeedParser {
708714
cx: &mut AcceptContext<'_, '_, S>,
709715
args: &ArgParser,
710716
) -> impl IntoIterator<Item = Self::Item> {
717+
if !cx.cx.sess.opts.unstable_opts.query_dep_graph {
718+
cx.emit_err(AttributeRequiresOpt { span: cx.attr_span, opt: "-Z query-dep-graph" });
719+
}
711720
let Some(item) = args.list().and_then(|l| l.single()) else {
712721
cx.expected_single_argument(cx.inner_span);
713722
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
@@ -435,9 +435,6 @@ passes_rustc_allow_const_fn_unstable =
435435
attribute should be applied to `const fn`
436436
.label = not a `const fn`
437437
438-
passes_rustc_clean =
439-
attribute requires -Z query-dep-graph to be enabled
440-
441438
passes_rustc_const_stable_indirect_pairing =
442439
`const_stable_indirect` attribute does not make sense on `rustc_const_stable` function, its behavior is already implied
443440

compiler/rustc_passes/src/check_attr.rs

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -224,14 +224,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
224224
self.check_rustc_must_implement_one_of(*attr_span, fn_names, hir_id,target)
225225
},
226226
Attribute::Parsed(AttributeKind::DoNotRecommend{attr_span}) => {self.check_do_not_recommend(*attr_span, hir_id, target, item)},
227-
Attribute::Parsed(AttributeKind::RustcClean(attrs)) => {
228-
for attr in attrs {
229-
self.check_rustc_clean(attr.span);
230-
}
231-
},
232-
Attribute::Parsed(AttributeKind::RustcIfThisChanged(span, _) | AttributeKind::RustcThenThisWouldNeed(span, _)) => {
233-
self.check_rustc_clean(*span);
234-
}
235227
Attribute::Parsed(
236228
// tidy-alphabetical-start
237229
AttributeKind::RustcAllowIncoherentImpl(..)
@@ -293,6 +285,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
293285
| AttributeKind::RustcAsPtr(..)
294286
| AttributeKind::RustcBodyStability { .. }
295287
| AttributeKind::RustcBuiltinMacro { .. }
288+
| AttributeKind::RustcClean(..)
296289
| AttributeKind::RustcCoherenceIsCore(..)
297290
| AttributeKind::RustcCoinductive(..)
298291
| AttributeKind::RustcConfusables { .. }
@@ -308,6 +301,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
308301
| AttributeKind::RustcDynIncompatibleTrait(..)
309302
| AttributeKind::RustcHasIncoherentInherentImpls
310303
| AttributeKind::RustcHiddenTypeOfOpaques
304+
| AttributeKind::RustcIfThisChanged(..)
311305
| AttributeKind::RustcLayout(..)
312306
| AttributeKind::RustcLayoutScalarValidRangeEnd(..)
313307
| AttributeKind::RustcLayoutScalarValidRangeStart(..)
@@ -336,6 +330,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
336330
| AttributeKind::RustcSkipDuringMethodDispatch { .. }
337331
| AttributeKind::RustcSpecializationTrait(..)
338332
| AttributeKind::RustcStdInternalSymbol (..)
333+
| AttributeKind::RustcThenThisWouldNeed(..)
339334
| AttributeKind::RustcUnsafeSpecializationMarker(..)
340335
| AttributeKind::RustcVariance
341336
| AttributeKind::RustcVarianceOfOpaques
@@ -1248,14 +1243,6 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
12481243
}
12491244
}
12501245

1251-
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
1252-
/// option is passed to the compiler.
1253-
fn check_rustc_clean(&self, span: Span) {
1254-
if !self.tcx.sess.opts.unstable_opts.query_dep_graph {
1255-
self.dcx().emit_err(errors::RustcClean { span });
1256-
}
1257-
}
1258-
12591246
/// Checks if the `#[repr]` attributes on `item` are valid.
12601247
fn check_repr(
12611248
&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)