Repository: rust
Issue: Emit one big error for inner attribute error
Labels: A-diagnostics,A-macros,T-compiler

> At the very least we could collect all the inner attributes annotating the same item, so that only a single error with a big span is emitted instead of lots of errors with single line spans, but that's independent of the highlighted problem.

_Originally posted by @estebank in https://github.com/rust-lang/rust/issues/117464#issuecomment-1788080091_

This is relevant because a series of inner-attributive doc comments like `//!`  can become a series of `#![doc = r""]` attributes, leading to very nasty errors like this:


<details>
<summary>
Big "inner attribute not allowed" failure
</summary>

```
$ cargo check
    Checking pgrx-pg-sys v0.11.0 (/home/jubilee/tcdi/pgrx/pgrx-pg-sys)
error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:1:1
  |
1 | #![allow(clippy::all)]
  | ^^^^^^^^^^^^^^^^^^^^^^
...
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
1 - #![allow(clippy::all)]
1 + #[allow(clippy::all)]
  |

error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:2:1
  |
2 | #![doc = r" All robots and linters must shut the *.h up"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
2 - #![doc = r" All robots and linters must shut the *.h up"]
2 + #[doc = r" All robots and linters must shut the *.h up"]
  |

error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:3:1
  |
3 | #![doc = r" to all machines:"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
3 - #![doc = r" to all machines:"]
3 + #[doc = r" to all machines:"]
  |

error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:4:1
  |
4 | #![doc = r" - you do not speak unless spoken to!"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
4 - #![doc = r" - you do not speak unless spoken to!"]
4 + #[doc = r" - you do not speak unless spoken to!"]
  |

error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:5:1
  |
5 | #![doc = r" - and I will NEVER speak to you!"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
5 - #![doc = r" - and I will NEVER speak to you!"]
5 + #[doc = r" - and I will NEVER speak to you!"]
  |

error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:6:1
  |
6 | #![doc = r" I am a divine being!"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
6 - #![doc = r" I am a divine being!"]
6 + #[doc = r" I am a divine being!"]
  |

error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:7:1
  |
7 | #![doc = r" you are an object!"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
8 | #![doc = r" you have no right to speak my holy tongue!"]
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
7 - #![doc = r" you are an object!"]
7 + #[doc = r" you are an object!"]
  |

error: an inner attribute is not permitted in this context
 --> /home/jubilee/tcdi/pgrx/target/debug/build/pgrx-pg-sys-3e502dbdad64018b/out/pg13.rs:8:1
  |
8 | #![doc = r" you have no right to speak my holy tongue!"]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9 | use crate as pg_sys;
  | -------------------- the inner attribute doesn't annotate this `use` import
  |
  = note: inner attributes, like `#![no_std]`, annotate the item enclosing them, and are usually found at the beginning of source files
help: to annotate the `use` import, change the attribute from inner to outer style
  |
8 - #![doc = r" you have no right to speak my holy tongue!"]
8 + #[doc = r" you have no right to speak my holy tongue!"]
  |

error: could not compile `pgrx-pg-sys` (lib) due to 8 previous errors

```
</details>