forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#111780 - weiznich:diagnostic_namespace, r=pet…
…rochenkov Diagnostic namespace This PR implements the basic infrastructure for accepting the `#[diagnostic]` attribute tool namespace as specified in rust-lang/rfcs#3368. Note: This RFC is not merged yet, but it seems like it will be accepted soon. I open this PR early on to get feedback on the actual implementation as soon as possible. This hopefully enables getting at least the diagnostic namespace to stable rust "soon", so that crates do not need to bump their MSRV if we stabilize actual attributes in this namespace. This PR only adds infrastructure accept attributes from this namespace, it does not add any specific attribute. Therefore the compiler will emit a lint warning for each attribute that's actually used. This namespace is added behind a feature flag, so it will be only available on a nightly compiler for now. cc `@estebank` as they've supported me in planing, specifying and implementing this feature.
- Loading branch information
Showing
15 changed files
with
202 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
tests/ui/diagnostic_namespace/auxiliary/proc-macro-helper.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// force-host | ||
// no-prefer-dynamic | ||
#![crate_type = "proc-macro"] | ||
|
||
extern crate proc_macro; | ||
|
||
use proc_macro::TokenStream; | ||
|
||
#[proc_macro_attribute] | ||
pub fn diagnostic(i: TokenStream, _: TokenStream) -> TokenStream { | ||
i | ||
} |
13 changes: 13 additions & 0 deletions
13
tests/ui/diagnostic_namespace/can_use_the_diagnostic_name_in_other_places.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// check-pass | ||
|
||
mod diagnostic {} | ||
|
||
macro_rules! diagnostic{ | ||
() => {} | ||
} | ||
|
||
#[allow(non_upper_case_globals)] | ||
const diagnostic: () = (); | ||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#![feature(diagnostic_namespace)] | ||
// check-pass | ||
// aux-build:proc-macro-helper.rs | ||
|
||
extern crate proc_macro_helper; | ||
|
||
mod test1 { | ||
use proc_macro_helper::diagnostic; | ||
|
||
#[diagnostic] | ||
struct Foo; | ||
|
||
} | ||
|
||
mod test2 { | ||
mod diagnostic { | ||
pub use proc_macro_helper::diagnostic as on_unimplemented; | ||
} | ||
|
||
#[diagnostic::on_unimplemented] | ||
trait Foo {} | ||
} | ||
|
||
fn main() {} |
13 changes: 13 additions & 0 deletions
13
tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#[diagnostic::non_existing_attribute] | ||
//~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] | ||
//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes] | ||
pub trait Bar { | ||
} | ||
|
||
#[diagnostic::non_existing_attribute(with_option = "foo")] | ||
//~^ERROR `#[diagnostic]` attribute name space is experimental [E0658] | ||
//~|WARNING unknown diagnostic attribute [unknown_diagnostic_attributes] | ||
struct Foo; | ||
|
||
fn main() { | ||
} |
35 changes: 35 additions & 0 deletions
35
tests/ui/diagnostic_namespace/feature-gate-diagnostic_namespace.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
error[E0658]: `#[diagnostic]` attribute name space is experimental | ||
--> $DIR/feature-gate-diagnostic_namespace.rs:1:3 | ||
| | ||
LL | #[diagnostic::non_existing_attribute] | ||
| ^^^^^^^^^^ | ||
| | ||
= note: see issue #94785 <https://github.com/rust-lang/rust/issues/94785> for more information | ||
= help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable | ||
|
||
error[E0658]: `#[diagnostic]` attribute name space is experimental | ||
--> $DIR/feature-gate-diagnostic_namespace.rs:7:3 | ||
| | ||
LL | #[diagnostic::non_existing_attribute(with_option = "foo")] | ||
| ^^^^^^^^^^ | ||
| | ||
= note: see issue #94785 <https://github.com/rust-lang/rust/issues/94785> for more information | ||
= help: add `#![feature(diagnostic_namespace)]` to the crate attributes to enable | ||
|
||
warning: unknown diagnostic attribute | ||
--> $DIR/feature-gate-diagnostic_namespace.rs:1:15 | ||
| | ||
LL | #[diagnostic::non_existing_attribute] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unknown_diagnostic_attributes)]` on by default | ||
|
||
warning: unknown diagnostic attribute | ||
--> $DIR/feature-gate-diagnostic_namespace.rs:7:15 | ||
| | ||
LL | #[diagnostic::non_existing_attribute(with_option = "foo")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors; 2 warnings emitted | ||
|
||
For more information about this error, try `rustc --explain E0658`. |
13 changes: 13 additions & 0 deletions
13
tests/ui/diagnostic_namespace/non_existing_attributes_accepted.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![feature(diagnostic_namespace)] | ||
// check-pass | ||
#[diagnostic::non_existing_attribute] | ||
//~^WARN unknown diagnostic attribute | ||
pub trait Bar { | ||
} | ||
|
||
#[diagnostic::non_existing_attribute(with_option = "foo")] | ||
//~^WARN unknown diagnostic attribute | ||
struct Foo; | ||
|
||
fn main() { | ||
} |
16 changes: 16 additions & 0 deletions
16
tests/ui/diagnostic_namespace/non_existing_attributes_accepted.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
warning: unknown diagnostic attribute | ||
--> $DIR/non_existing_attributes_accepted.rs:3:15 | ||
| | ||
LL | #[diagnostic::non_existing_attribute] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
| | ||
= note: `#[warn(unknown_diagnostic_attributes)]` on by default | ||
|
||
warning: unknown diagnostic attribute | ||
--> $DIR/non_existing_attributes_accepted.rs:8:15 | ||
| | ||
LL | #[diagnostic::non_existing_attribute(with_option = "foo")] | ||
| ^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: 2 warnings emitted | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#![feature(diagnostic_namespace)] | ||
|
||
#[diagnostic] | ||
//~^ERROR cannot find attribute `diagnostic` in this scope | ||
pub struct Bar; | ||
|
||
|
||
fn main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
error: cannot find attribute `diagnostic` in this scope | ||
--> $DIR/requires_path.rs:3:3 | ||
| | ||
LL | #[diagnostic] | ||
| ^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|