Reject outer attributes on cfg_select branches#155734
Reject outer attributes on cfg_select branches#155734qaijuang wants to merge 6 commits intorust-lang:mainfrom
cfg_select branches#155734Conversation
fb8cf2e to
9c49112
Compare
Co-authored-by: Copilot <copilot@github.com>
|
Some changes occurred in compiler/rustc_attr_parsing |
|
rustbot has assigned @JonathanBrouwer. Use Why was this reviewer chosen?The reviewer was selected based on:
|
|
Reminder, once the PR becomes ready for a review, use |
|
@bors r+ rollup |
…=JonathanBrouwer Lint doc comments in cfg_select branches Fixes rust-lang#155701.
…uwer Rollup of 6 pull requests Successful merges: - #154803 (Fix ICE from cfg_attr_trace ) - #155485 (Add an edge-case test for `--remap-path-prefix` for `rustc` & `rustdoc`) - #155659 (cleanup, restructure and merge `tests/ui/deriving` into `tests/ui/derives`) - #155696 (Add a higher-level API for parsing attributes) - #155734 (Lint doc comments in cfg_select branches) - #155769 (triagebot.toml: Ping Enselic when tests/debuginfo/basic-stepping.rs changes)
|
This PR allows more code to compile, so it's a language change and technically needs a T-lang FCP. cc @rust-lang/lang |
|
I'm sorry @bors r- |
Thanks @fmease for catching this and navigating it. |
cfg_select branches
|
The parser was modified, potentially altering the grammar of (stable) Rust cc @fmease |
Co-authored-by: Copilot <copilot@github.com>
Co-authored-by: Copilot <copilot@github.com>
| // `parse_outer_attributes` recovers inner doc comments as outer ones, so collect their | ||
| // spans first and suppress the follow-up `cfg_select` branch diagnostic for them. | ||
| let mut inner_doc_comment_spans = Vec::new(); | ||
| let mut snapshot = self.create_snapshot_for_diagnostic(); |
There was a problem hiding this comment.
IINM this is creating a parser snapshot in the happy path, right? this is an expensive operation and should only happen in error paths.
There was a problem hiding this comment.
Why is this using a snapshot in the first place? Can't you just use parse_inner_attributes and reject inner attrs afterwards? That function is smart enough not to bail out when it encounters outer attributes so you don't need to worry about that.
There was a problem hiding this comment.
calling parse_inner_attributes first for /// outer followed by //! inner would return empty at the /// and would never notice the later //!
The test case:
cfg_select! {
/// outer doc comment
//! inner doc comment
debug_assertions => {}
_ => {}
}There was a problem hiding this comment.
IINM this is creating a parser snapshot in the happy path, right? this is an expensive operation and should only happen in error paths.
That’s a good point. I’m thinking of classifying recovered doc comments directly from their source snippet in the error path, so we can avoid the snapshot cost
View all comments
Fixes #155701.