Skip to content

Rustc suggestsion with invalid syntax #91800

Closed
@zakarumych

Description

@zakarumych
// 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions