Skip to content

Preserve parentheses around Fn trait bounds in pretty printer#153483

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
aytey:dyn_paren_impl_fn_return
Mar 6, 2026
Merged

Preserve parentheses around Fn trait bounds in pretty printer#153483
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
aytey:dyn_paren_impl_fn_return

Conversation

@aytey
Copy link
Copy Markdown
Contributor

@aytey aytey commented Mar 6, 2026

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.

@rustbot rustbot added 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 Mar 6, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 6, 2026

r? @fmease

rustbot has assigned @fmease.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 69 candidates
  • Random selection from 16 candidates

@aytey aytey changed the title Preserve parentheses around Fn trait bounds in pretty printer Preserve parentheses around Fn trait bounds in pretty printer Mar 6, 2026
Copy link
Copy Markdown
Member

@fmease fmease left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@fmease fmease added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 6, 2026
@fmease
Copy link
Copy Markdown
Member

fmease commented Mar 6, 2026

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>
@aytey aytey force-pushed the dyn_paren_impl_fn_return branch from b73812e to cb66c85 Compare March 6, 2026 10:38
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Mar 6, 2026

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.

@aytey
Copy link
Copy Markdown
Contributor Author

aytey commented Mar 6, 2026

Thanks! Final request: Could you please squash the two commits into a single one?

Done!

@fmease
Copy link
Copy Markdown
Member

fmease commented Mar 6, 2026

Perfect! @bors r+ rollup

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Mar 6, 2026

📌 Commit cb66c85 has been approved by fmease

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-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 6, 2026
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`.
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-bors rust-bors bot merged commit 03a8ae8 into rust-lang:main Mar 6, 2026
11 checks passed
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`.
@rustbot rustbot added this to the 1.96.0 milestone Mar 6, 2026
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)
flip1995 pushed a commit to flip1995/rust-clippy that referenced this pull request Mar 21, 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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

3 participants