Skip to content

Commit 2f611da

Browse files
authored
Rollup merge of #83313 - cjgillot:assert, r=michaelwoerister
Only enable assert_dep_graph when query-dep-graph is enabled. This is a debugging option. The only effect should be on rustc tests. r? ``@michaelwoerister``
2 parents f134ca3 + 31447f6 commit 2f611da

File tree

8 files changed

+77
-1
lines changed

8 files changed

+77
-1
lines changed

compiler/rustc_incremental/src/assert_dep_graph.rs

+4
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ pub fn assert_dep_graph(tcx: TyCtxt<'_>) {
5757
dump_graph(tcx);
5858
}
5959

60+
if !tcx.sess.opts.debugging_opts.query_dep_graph {
61+
return;
62+
}
63+
6064
// if the `rustc_attrs` feature is not enabled, then the
6165
// attributes we are interested in cannot be present anyway, so
6266
// skip the walk.

compiler/rustc_incremental/src/persist/dirty_clean.rs

+4
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,10 @@ impl Assertion {
148148
}
149149

150150
pub fn check_dirty_clean_annotations(tcx: TyCtxt<'_>) {
151+
if !tcx.sess.opts.debugging_opts.query_dep_graph {
152+
return;
153+
}
154+
151155
// can't add `#[rustc_dirty]` etc without opting in to this feature
152156
if !tcx.features().rustc_attrs {
153157
return;

compiler/rustc_passes/src/check_attr.rs

+20
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ impl CheckAttrVisitor<'tcx> {
9999
self.check_naked(hir_id, attr, span, target)
100100
} else if self.tcx.sess.check_name(attr, sym::rustc_legacy_const_generics) {
101101
self.check_rustc_legacy_const_generics(&attr, span, target, item)
102+
} else if self.tcx.sess.check_name(attr, sym::rustc_clean)
103+
|| self.tcx.sess.check_name(attr, sym::rustc_dirty)
104+
|| self.tcx.sess.check_name(attr, sym::rustc_if_this_changed)
105+
|| self.tcx.sess.check_name(attr, sym::rustc_then_this_would_need)
106+
{
107+
self.check_rustc_dirty_clean(&attr)
102108
} else {
103109
// lint-only checks
104110
if self.tcx.sess.check_name(attr, sym::cold) {
@@ -1012,6 +1018,20 @@ impl CheckAttrVisitor<'tcx> {
10121018
}
10131019
}
10141020

1021+
/// Checks that the dep-graph debugging attributes are only present when the query-dep-graph
1022+
/// option is passed to the compiler.
1023+
fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool {
1024+
if self.tcx.sess.opts.debugging_opts.query_dep_graph {
1025+
true
1026+
} else {
1027+
self.tcx
1028+
.sess
1029+
.struct_span_err(attr.span, "attribute requires -Z query-dep-graph to be enabled")
1030+
.emit();
1031+
false
1032+
}
1033+
}
1034+
10151035
/// Checks if `#[link_section]` is applied to a function or static.
10161036
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
10171037
match target {

src/test/incremental/ich_nested_items.rs

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
// revisions: cfail1 cfail2
55
// build-pass (FIXME(62277): could be check-pass?)
6+
// compile-flags: -Z query-dep-graph
67

78
#![crate_type = "rlib"]
89
#![feature(rustc_attrs)]

src/test/incremental/ich_resolve_results.rs

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// `use` to something different.
33

44
// revisions: rpass1 rpass2 rpass3
5+
// compile-flags: -Z query-dep-graph
56

67
#![feature(rustc_attrs)]
78

src/test/incremental/spans_significant_w_panic.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
// revisions:rpass1 rpass2
55

6-
// compile-flags: -C overflow-checks=on
6+
// compile-flags: -C overflow-checks=on -Z query-dep-graph
77

88
#![feature(rustc_attrs)]
99

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Test that using rustc_clean/dirty/if_this_changed/then_this_would_need
2+
// are forbidden when `-Z query-dep-graph` is not enabled.
3+
4+
#![feature(rustc_attrs)]
5+
#![allow(dead_code)]
6+
#![allow(unused_variables)]
7+
8+
#[rustc_dirty(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph
9+
fn main() {}
10+
11+
#[rustc_if_this_changed(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph
12+
struct Foo<T> {
13+
f: T,
14+
}
15+
16+
#[rustc_clean(hir_owner)] //~ ERROR attribute requires -Z query-dep-graph
17+
type TypeAlias<T> = Foo<T>;
18+
19+
#[rustc_then_this_would_need(variances_of)] //~ ERROR attribute requires -Z query-dep-graph
20+
trait Use<T> {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error: attribute requires -Z query-dep-graph to be enabled
2+
--> $DIR/dep-graph-check-attr.rs:8:1
3+
|
4+
LL | #[rustc_dirty(hir_owner)]
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: attribute requires -Z query-dep-graph to be enabled
8+
--> $DIR/dep-graph-check-attr.rs:11:1
9+
|
10+
LL | #[rustc_if_this_changed(hir_owner)]
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: attribute requires -Z query-dep-graph to be enabled
14+
--> $DIR/dep-graph-check-attr.rs:16:1
15+
|
16+
LL | #[rustc_clean(hir_owner)]
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error: attribute requires -Z query-dep-graph to be enabled
20+
--> $DIR/dep-graph-check-attr.rs:19:1
21+
|
22+
LL | #[rustc_then_this_would_need(variances_of)]
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error: aborting due to 4 previous errors
26+

0 commit comments

Comments
 (0)