Skip to content

Commit fd8a79f

Browse files
committed
Add a feature gate for the #[diagnostic] tool namespace
1 parent 784930e commit fd8a79f

File tree

10 files changed

+43
-7
lines changed

10 files changed

+43
-7
lines changed

compiler/rustc_feature/src/active.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,8 @@ declare_features! (
379379
(active, deprecated_safe, "1.61.0", Some(94978), None),
380380
/// Allows having using `suggestion` in the `#[deprecated]` attribute.
381381
(active, deprecated_suggestion, "1.61.0", Some(94785), None),
382+
/// Allows using the `#[diagnostic]` attribute tool namespace
383+
(active, diagnostic_namespace, "CURRENT_RUSTC_VERSION", Some(94785), None),
382384
/// Controls errors in trait implementations.
383385
(active, do_not_recommend, "1.67.0", Some(51992), None),
384386
/// Tells rustdoc to automatically generate `#[doc(cfg(...))]`.

compiler/rustc_lint_defs/src/builtin.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4259,6 +4259,7 @@ declare_lint! {
42594259
/// ### Example
42604260
///
42614261
/// ```rust
4262+
/// #![feature(diagnostic_namespace)]
42624263
/// #[diagnostic::does_not_exist]
42634264
/// struct Foo;
42644265
/// ```

compiler/rustc_resolve/src/macros.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,9 @@ pub(crate) fn registered_tools(tcx: TyCtxt<'_>, (): ()) -> RegisteredTools {
143143
// but it's not an error to register them explicitly.
144144
let predefined_tools = [sym::clippy, sym::rustfmt];
145145
registered_tools.extend(predefined_tools.iter().cloned().map(Ident::with_dummy_span));
146-
registered_tools.insert(Ident::with_dummy_span(sym::diagnostic));
146+
if tcx.features().diagnostic_namespace {
147+
registered_tools.insert(Ident::with_dummy_span(sym::diagnostic));
148+
}
147149
registered_tools
148150
}
149151

@@ -496,7 +498,8 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
496498
Err(Determinacy::Undetermined) => return Err(Indeterminate),
497499
};
498500

499-
if kind == MacroKind::Attr
501+
if self.tcx.features().diagnostic_namespace
502+
&& kind == MacroKind::Attr
500503
&& !path.segments.is_empty()
501504
&& path.segments[0].ident.as_str() == "diagnostic"
502505
{

compiler/rustc_span/src/symbol.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -620,6 +620,7 @@ symbols! {
620620
destruct,
621621
destructuring_assignment,
622622
diagnostic,
623+
diagnostic_namespace,
623624
direct,
624625
discriminant_kind,
625626
discriminant_type,
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// check-fail
2+
#[diagnostic::non_existing_attribute]
3+
//~^ERROR use of undeclared crate or module `diagnostic
4+
pub trait Bar {
5+
}
6+
7+
#[diagnostic::non_existing_attribute(with_option = "foo")]
8+
//~^ERROR use of undeclared crate or module `diagnostic
9+
struct Foo;
10+
11+
fn main() {
12+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0433]: failed to resolve: use of undeclared crate or module `diagnostic`
2+
--> $DIR/feature-gate-diagnostic_namespace.rs:7:3
3+
|
4+
LL | #[diagnostic::non_existing_attribute(with_option = "foo")]
5+
| ^^^^^^^^^^ use of undeclared crate or module `diagnostic`
6+
7+
error[E0433]: failed to resolve: use of undeclared crate or module `diagnostic`
8+
--> $DIR/feature-gate-diagnostic_namespace.rs:2:3
9+
|
10+
LL | #[diagnostic::non_existing_attribute]
11+
| ^^^^^^^^^^ use of undeclared crate or module `diagnostic`
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0433`.

tests/ui/diagnostic_namespace/non_existing_attributes_accepted.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(diagnostic_namespace)]
12
// check-pass
23
#[diagnostic::non_existing_attribute]
34
//~^WARN Unknown diagnostic attribute

tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
warning: Unknown diagnostic attribute
2-
--> $DIR/non_existing_attributes_accepted.rs:2:15
2+
--> $DIR/non_existing_attributes_accepted.rs:3:15
33
|
44
LL | #[diagnostic::non_existing_attribute]
55
| ^^^^^^^^^^^^^^^^^^^^^^
66
|
77
= note: `#[warn(unknown_diagnostic_attribute)]` on by default
88

99
warning: Unknown diagnostic attribute
10-
--> $DIR/non_existing_attributes_accepted.rs:7:15
10+
--> $DIR/non_existing_attributes_accepted.rs:8:15
1111
|
1212
LL | #[diagnostic::non_existing_attribute(with_option = "foo")]
1313
| ^^^^^^^^^^^^^^^^^^^^^^

tests/ui/diagnostic_namespace/requires_path.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#![feature(diagnostic_namespace)]
12
// check-fail
23

34
#[diagnostic]

tests/ui/diagnostic_namespace/requires_path.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: Diagnostic attributes requires a path with 2 segments
2-
--> $DIR/requires_path.rs:3:3
2+
--> $DIR/requires_path.rs:4:3
33
|
44
LL | #[diagnostic]
55
| ^^^^^^^^^^
66

77
error: Diagnostic attributes requires a path with 2 segments
8-
--> $DIR/requires_path.rs:3:3
8+
--> $DIR/requires_path.rs:4:3
99
|
1010
LL | #[diagnostic]
1111
| ^^^^^^^^^^
1212

1313
error: cannot find attribute `diagnostic` in this scope
14-
--> $DIR/requires_path.rs:3:3
14+
--> $DIR/requires_path.rs:4:3
1515
|
1616
LL | #[diagnostic]
1717
| ^^^^^^^^^^

0 commit comments

Comments
 (0)