Preserve parentheses around Fn trait bounds in pretty printer#153483
Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom Mar 6, 2026
Merged
Preserve parentheses around Fn trait bounds in pretty printer#153483rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Fn trait bounds in pretty printer#153483rust-bors[bot] merged 1 commit intorust-lang:mainfrom
Conversation
Collaborator
|
r? @fmease rustbot has assigned @fmease. Use Why was this reviewer chosen?The reviewer was selected based on:
|
Fn trait bounds in pretty printer
Member
|
Thanks! Final request: Could you please squash the two commits into a single one? |
The AST pretty printer was dropping parentheses around `Fn` trait
bounds in `dyn`/`impl` types when additional `+` bounds were present.
For example:
dyn (FnMut(&mut T) -> &mut dyn ResourceLimiter) + Send + Sync
was pretty-printed as:
dyn FnMut(&mut T) -> &mut dyn ResourceLimiter + Send + Sync
Without parens, `+ Send + Sync` binds to the inner `dyn ResourceLimiter`
instead of the outer type, producing invalid Rust.
The parser already tracks parentheses via `PolyTraitRef.parens`, but
`print_poly_trait_ref` never checked this field. This adds `popen()`
and `pclose()` calls when `parens == Parens::Yes`.
Signed-off-by: Andrew V. Teylu <andrew.teylu@vector.com>
b73812e to
cb66c85
Compare
Collaborator
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
Contributor
Author
Done! |
Member
|
Perfect! @bors r+ rollup |
Contributor
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 6, 2026
…fmease
Preserve parentheses around `Fn` trait bounds in pretty printer
The AST pretty printer was dropping parentheses around `Fn` trait bounds in `dyn`/`impl` types when additional `+` bounds were present. For example:
dyn (FnMut(&mut T) -> &mut dyn ResourceLimiter) + Send + Sync
was pretty-printed as:
dyn FnMut(&mut T) -> &mut dyn ResourceLimiter + Send + Sync
Without parens, `+ Send + Sync` binds to the inner `dyn ResourceLimiter` instead of the outer type, producing invalid Rust.
The parser already tracks parentheses via `PolyTraitRef.parens`, but `print_poly_trait_ref` never checked this field. This adds `popen()` and `pclose()` calls when `parens == Parens::Yes`.
rust-bors bot
pushed a commit
that referenced
this pull request
Mar 6, 2026
…uwer Rollup of 9 pull requests Successful merges: - #153466 (`rust-analyzer` subtree update) - #151280 (Fix incorrect trailing comma suggested in no_accessible_fields) - #152593 (Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`) - #153174 (std: add wasm64 to sync::Once and thread_parking atomics cfg guards) - #153189 (refactor: move `check_align` to `parse_alignment`) - #153230 (Roll rustfmt reviewers for in-tree rustfmt) - #153445 (Consider try blocks as block-like for overflowed expr) - #153476 (bootstrap.py: fix typo "parallle") - #153483 (Preserve parentheses around `Fn` trait bounds in pretty printer)
JonathanBrouwer
added a commit
to JonathanBrouwer/rust
that referenced
this pull request
Mar 6, 2026
…fmease
Preserve parentheses around `Fn` trait bounds in pretty printer
The AST pretty printer was dropping parentheses around `Fn` trait bounds in `dyn`/`impl` types when additional `+` bounds were present. For example:
dyn (FnMut(&mut T) -> &mut dyn ResourceLimiter) + Send + Sync
was pretty-printed as:
dyn FnMut(&mut T) -> &mut dyn ResourceLimiter + Send + Sync
Without parens, `+ Send + Sync` binds to the inner `dyn ResourceLimiter` instead of the outer type, producing invalid Rust.
The parser already tracks parentheses via `PolyTraitRef.parens`, but `print_poly_trait_ref` never checked this field. This adds `popen()` and `pclose()` calls when `parens == Parens::Yes`.
This was referenced Mar 6, 2026
rust-bors bot
pushed a commit
that referenced
this pull request
Mar 6, 2026
…uwer Rollup of 14 pull requests Successful merges: - #153466 (`rust-analyzer` subtree update) - #151280 (Fix incorrect trailing comma suggested in no_accessible_fields) - #152593 (Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`) - #153174 (std: add wasm64 to sync::Once and thread_parking atomics cfg guards) - #153485 (libcore float tests: replace macro shadowing by const-compatible macro) - #153495 (Fix ICE in `offset_of!` error recovery) - #152040 (Do not emit ConstEvaluatable goals if type-const) - #152741 (Suppress invalid suggestions in destructuring assignment) - #153189 (refactor: move `check_align` to `parse_alignment`) - #153230 (Roll rustfmt reviewers for in-tree rustfmt) - #153445 (Consider try blocks as block-like for overflowed expr) - #153452 (Cleanup unused diagnostic emission methods) - #153476 (bootstrap.py: fix typo "parallle") - #153483 (Preserve parentheses around `Fn` trait bounds in pretty printer)
rust-timer
added a commit
that referenced
this pull request
Mar 6, 2026
Rollup merge of #153483 - aytey:dyn_paren_impl_fn_return, r=fmease Preserve parentheses around `Fn` trait bounds in pretty printer The AST pretty printer was dropping parentheses around `Fn` trait bounds in `dyn`/`impl` types when additional `+` bounds were present. For example: dyn (FnMut(&mut T) -> &mut dyn ResourceLimiter) + Send + Sync was pretty-printed as: dyn FnMut(&mut T) -> &mut dyn ResourceLimiter + Send + Sync Without parens, `+ Send + Sync` binds to the inner `dyn ResourceLimiter` instead of the outer type, producing invalid Rust. The parser already tracks parentheses via `PolyTraitRef.parens`, but `print_poly_trait_ref` never checked this field. This adds `popen()` and `pclose()` calls when `parens == Parens::Yes`.
github-actions bot
pushed a commit
to rust-lang/rust-analyzer
that referenced
this pull request
Mar 9, 2026
…uwer Rollup of 14 pull requests Successful merges: - rust-lang/rust#153466 (`rust-analyzer` subtree update) - rust-lang/rust#151280 (Fix incorrect trailing comma suggested in no_accessible_fields) - rust-lang/rust#152593 (Box in `ValTreeKind::Branch(Box<[I::Const]>)` changed to `List`) - rust-lang/rust#153174 (std: add wasm64 to sync::Once and thread_parking atomics cfg guards) - rust-lang/rust#153485 (libcore float tests: replace macro shadowing by const-compatible macro) - rust-lang/rust#153495 (Fix ICE in `offset_of!` error recovery) - rust-lang/rust#152040 (Do not emit ConstEvaluatable goals if type-const) - rust-lang/rust#152741 (Suppress invalid suggestions in destructuring assignment) - rust-lang/rust#153189 (refactor: move `check_align` to `parse_alignment`) - rust-lang/rust#153230 (Roll rustfmt reviewers for in-tree rustfmt) - rust-lang/rust#153445 (Consider try blocks as block-like for overflowed expr) - rust-lang/rust#153452 (Cleanup unused diagnostic emission methods) - rust-lang/rust#153476 (bootstrap.py: fix typo "parallle") - rust-lang/rust#153483 (Preserve parentheses around `Fn` trait bounds in pretty printer)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The AST pretty printer was dropping parentheses around
Fntrait bounds indyn/impltypes when additional+bounds were present. For example:was pretty-printed as:
Without parens,
+ Send + Syncbinds to the innerdyn ResourceLimiterinstead of the outer type, producing invalid Rust.The parser already tracks parentheses via
PolyTraitRef.parens, butprint_poly_trait_refnever checked this field. This addspopen()andpclose()calls whenparens == Parens::Yes.