Skip to content

Commit 1aad7e7

Browse files
committed
Err if the debugging options are not passed.
1 parent 219603a commit 1aad7e7

File tree

6 files changed

+68
-1
lines changed

6 files changed

+68
-1
lines changed

compiler/rustc_passes/src/check_attr.rs

Lines changed: 19 additions & 0 deletions
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,19 @@ impl CheckAttrVisitor<'tcx> {
10121018
}
10131019
}
10141020

1021+
/// Checks if `#[rustc_legacy_const_generics]` is applied to a function and has a valid argument.
1022+
fn check_rustc_dirty_clean(&self, attr: &Attribute) -> bool {
1023+
if self.tcx.sess.opts.debugging_opts.query_dep_graph {
1024+
true
1025+
} else {
1026+
self.tcx
1027+
.sess
1028+
.struct_span_err(attr.span, "attribute requires -Z query-dep-graph to be enabled")
1029+
.emit();
1030+
false
1031+
}
1032+
}
1033+
10151034
/// Checks if `#[link_section]` is applied to a function or static.
10161035
fn check_link_section(&self, hir_id: HirId, attr: &Attribute, span: &Span, target: Target) {
10171036
match target {

src/test/incremental/ich_nested_items.rs

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 20 additions & 0 deletions
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> {}
Lines changed: 26 additions & 0 deletions
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)