Skip to content

Improve AttrItem::span#159587

Merged
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
nnethercote:AttrItem-span
Jul 20, 2026
Merged

Improve AttrItem::span#159587
rust-bors[bot] merged 2 commits into
rust-lang:mainfrom
nnethercote:AttrItem-span

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

It has some shortcomings. Details in individual commits.

r? @petrochenkov

Currently the method computes the span from the path's span and the
args' span. That used to be fine but then `unsafe(..)`/`safe(..)` were
added without it being changed. So it doesn't account for those optional
keywords and parentheses. The only way to handle those reliably is with
a dedicated span for the entire `AttrItem`.

Consequences:
- `NormalAttr` grows from 72 bytes to 80. (It's the only AST node that
  contains an `AttrItem`.) Not ideal, but non-doc-comment attributes
  aren't that common (not compared to expressions, for example). Also,
  `NormalAttr` is always boxed and jemalloc will round up 72 byte
  allocations to 80 bytes anyway.
- In `lint-unsafe-code.rs` various spans now point to `unsafe(foo)`
  rather than just `foo`. (It makes sense to include the `unsafe` keyword
  in the complaint about unsafety.)
@rustbot

rustbot commented Jul 20, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

Some changes occurred in compiler/rustc_builtin_macros/src/autodiff.rs

cc @ZuseZ4

Some changes occurred in compiler/rustc_attr_parsing

cc @jdonszelmann, @JonathanBrouwer

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 20, 2026
@JonathanBrouwer

Copy link
Copy Markdown
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 20, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Jul 20, 2026
@rust-bors

rust-bors Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: a8ce121 (a8ce121c5d9b7781fed35525b58762bbcd5a3712)
Base parent: 730a6b5 (730a6b5dce9477b819de0ba79d6e7945e1248e3d)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (a8ce121): comparison URL.

Overall result: ✅ improvements - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

Our most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-2.2% [-2.2%, -2.2%] 1
All ❌✅ (primary) - - 0

Max RSS (memory usage)

This perf run didn't have relevant results for this metric.

Cycles

Results (secondary -3.7%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-3.7% [-3.7%, -3.7%] 1
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 485.867s -> 491.733s (1.21%)
Artifact size: 391.77 MiB -> 391.76 MiB (-0.00%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jul 20, 2026
@petrochenkov

Copy link
Copy Markdown
Contributor

@bors r+ rollup=maybe

@rust-bors

rust-bors Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

📌 Commit ea7bee7 has been approved by petrochenkov

It is now in the queue for this repository.

@rust-bors rust-bors Bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 20, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 20, 2026
…chenkov

Improve `AttrItem::span`

It has some shortcomings. Details in individual commits.

r? @petrochenkov
rust-bors Bot pushed a commit that referenced this pull request Jul 20, 2026
…uwer

Rollup of 10 pull requests

Successful merges:

 - #159600 (`rust-analyzer` subtree update)
 - #158046 (proc_macro: preserve file module spans for inner attrs)
 - #159000 (Small cleanups to the incr comp session code)
 - #159449 (Enable single Location to issue multiple borrows)
 - #159587 (Improve `AttrItem::span`)
 - #159460 (Do not mark unnormalized const aliases as rigid when normalizing param env)
 - #159529 (Add regression test for nested replacement ranges in `collect_tokens`)
 - #159585 (Minor `TokenStream` improvements)
 - #159586 (Separate `InterpCx` usage by `ConstAnalysis` phases)
 - #159603 (Clarify `push_stream`/`push_tree`)

Failed merges:

 - #159590 (Remove some dead code)
rust-bors Bot pushed a commit that referenced this pull request Jul 20, 2026
…uwer

Rollup of 18 pull requests

Successful merges:

 - #159600 (`rust-analyzer` subtree update)
 - #158046 (proc_macro: preserve file module spans for inner attrs)
 - #159000 (Small cleanups to the incr comp session code)
 - #159189 (Account for type alias projections in E0308 "expected/found" shortening logic)
 - #159449 (Enable single Location to issue multiple borrows)
 - #159544 (Suggest valid command-line crate names)
 - #159587 (Improve `AttrItem::span`)
 - #159594 (feat(rustc_hir_typeck): suggest `impl Fn` return for capturing closures)
 - #159597 (std: use `arc4random_buf` from libc)
 - #159599 (Resolver: Record at least 1 ambiguous trait if main decl is not a trait.)
 - #158061 (Make `pin!()` more foolproof.)
 - #159460 (Do not mark unnormalized const aliases as rigid when normalizing param env)
 - #159529 (Add regression test for nested replacement ranges in `collect_tokens`)
 - #159571 (Remove unused bundled library lookup for the local crate)
 - #159585 (Minor `TokenStream` improvements)
 - #159586 (Separate `InterpCx` usage by `ConstAnalysis` phases)
 - #159602 (Remove `ItemLike`)
 - #159603 (Clarify `push_stream`/`push_tree`)

Failed merges:

 - #159590 (Remove some dead code)
@rust-bors
rust-bors Bot merged commit 152c269 into rust-lang:main Jul 20, 2026
14 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 20, 2026
rust-timer added a commit that referenced this pull request Jul 20, 2026
Rollup merge of #159587 - nnethercote:AttrItem-span, r=petrochenkov

Improve `AttrItem::span`

It has some shortcomings. Details in individual commits.

r? @petrochenkov
@nnethercote
nnethercote deleted the AttrItem-span branch July 20, 2026 23:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants