rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
97.3k stars 12.58k forks source link

Derive macros may cause weird suggestion #99498

Open mladedav opened 2 years ago

mladedav commented 2 years ago

Given the following code:

#[derive(sqlx::FromRow)]
struct Foo {
    bar: _,
}

fn main() {}

The current output is:

error[E0121]: the placeholder `_` is not allowed within types on item signatures for structs
 --> src\main.rs:3:10
  |
3 |     bar: _,
  |          ^ not allowed in type signatures
  |
help: use type parameters instead
  |
2 ~ struct Foo<T> {
3 ~     bar: T,
  |

error[E0121]: the placeholder `_` is not allowed within types on item signatures for implementations
 --> src\main.rs:3:10
  |
3 |     bar: _,
  |          ^
  |          |
  |          not allowed in type signatures
  |          not allowed in type signatures
  |
help: use type parameters instead
  |
1 ~ #[derive(sqlx::FromRo, Tw)]
2 | struct Foo {
3 ~     bar: TT,
  |

For more information about this error, try `rustc --explain E0121`.
error: could not compile `sandbox` due to 2 previous errors

Additionally, here is a screenshot of the capture for coloring to be visible: image

Ideally the second error should either not provide any suggestion or be skipped altogether as it seems to be related to auto-generated code.

I was only able to reproduce this with an external derive macro. I am not knowledgeable enough to try to create one causing this myself.

compiler-errors commented 2 years ago

@mladedav what version of rust is this compiled on?

mladedav commented 2 years ago

I've tried with stable 1.62.1 and nightly 1.64.0 (f8588549c 2022-07-18). Both yielded the same output.

compiler-errors commented 2 years ago

Thanks. I'll look into it then.