Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rustc suggestsion with invalid syntax #91800

Closed
zakarumych opened this issue Dec 11, 2021 · 0 comments · Fixed by #97377
Closed

Rustc suggestsion with invalid syntax #91800

zakarumych opened this issue Dec 11, 2021 · 0 comments · Fixed by #97377
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@zakarumych
Copy link
Contributor

zakarumych commented Dec 11, 2021

// lib.rs  in proc-macro crate
#[proc_macro_derive(MyTrait)]
pub fn mytrait(item: TokenStream) -> TokenStream {
    "compile_error!()".parse().unwrap()
}

// lib.rs in other crate
#[derive(MyTrait)]
struct MyStruct;
error: macros that expand to items must be delimited with braces or followed by a semicolon
  --> examples\mytrait.rs:10:10
   |
10 | #[derive(MyTrait)]
   |          ^^^^^^^
   |
   = note: this error originates in the derive macro `MyTrait` (in Nightly builds, run with -Z macro-backtrace for more info)
help: change the delimiters to curly braces
   |
10 | #[derive({})]
   |          ~
help: add a semicolon
   |
10 | #[derive(MyTrait;)]
   |                 +

Both suggestions have invalid syntax.
Ideally rustc should suggest to add ; into token stream returned from derive-proc-macro.

@zakarumych zakarumych added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Dec 11, 2021
@bors bors closed this as completed in 5cd8679 Jun 17, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
1 participant