Parser: Recover from attributes applied to types and generic args#144195
Conversation
|
r? compiler-errors |
This comment has been minimized.
This comment has been minimized.
5502794 to
2b4000d
Compare
|
Well I added a branch to handle this (you can see it in review below) error[E0107]: struct takes 1 generic argument but 0 generic arguments were supplied
--> src/main.rs:4:12
|
4 | let _: Baz<#[cfg(any())]> = todo!();
| ^^^ expected 1 generic argument
|
note: struct defined here, with 1 generic parameter: `N`
--> src/main.rs:1:8
|
1 | struct Baz<const N: usize>(i32);
| ^^^ --------------
help: add missing generic argument
|
4 | let _: Baz<N#[cfg(any())]> = todo!();
| +
error: aborting due to 1 previous error
For more information about this error, try `rustc --explain E0107`. |
e267a23 to
516db8d
Compare
Kivooeo
left a comment
There was a problem hiding this comment.
I've called out the potentially surprising bits of this implementation with explanations to help reviewers in mine this and above reviews
This comment has been minimized.
This comment has been minimized.
|
@fmease, I spent significant time trying to address the secondary error you mentioned. Good news: I solved it for cases where there's something inside the generic. When we have But I hit a wall with empty generics like The problem is Whatever we pick will be wrong sometimes. If I default to I can pick a statistical default (types are most common), but some cases will still get secondary errors. Is that acceptable, or do you see another approach I'm missing? The architectural issue seems fundamental since parsing happens before we know what types expect what kinds of generics. |
|
@rustbot ready |
fmease
left a comment
There was a problem hiding this comment.
Final stretch, after that I'll approve.
|
|
Small breakdown what I've changed according to last reviews
What I did not made
|
|
@rustbot ready |
|
Thanks a lot! |
Rollup of 15 pull requests Successful merges: - #144195 (Parser: Recover from attributes applied to types and generic args) - #144794 (Port `#[coroutine]` to the new attribute system) - #144835 (Anonymize binders in tail call sig) - #144861 (Stabilize `panic_payload_as_str` feature) - #144917 (Enforce tail call type is related to body return type in borrowck) - #144948 (we only merge candidates for trait and normalizes-to goals) - #144956 (Gate const trait syntax) - #144970 (rustdoc: fix caching of intra-doc links on reexports) - #144972 (add code example showing that file_prefix treats dotfiles as the name of a file, not an extension) - #144975 (`File::set_times`: Update documentation and example to support setting timestamps on directories) - #144977 (Fortify generic param default checks) - #144996 (simplifycfg: Mark as changed when start is modified in collapse goto chain) - #144998 (mir: Do not modify NonUse in `super_projection_elem`) - #145000 (Remove unneeded `stage` parameter when setting up stdlib Cargo) - #145008 (Fix rustdoc scrape examples crash) r? `@ghost` `@rustbot` modify labels: rollup
r? compiler
Add clearer error messages for invalid attribute usage in types or generic types
fixes #135017
fixes #144132