mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
cb66c85555
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>
12 lines
338 B
Rust
12 lines
338 B
Rust
//@ pp-exact
|
|
|
|
trait Dummy {}
|
|
|
|
// Without parens, `+ Send` would bind to `dyn Dummy` instead of the outer `dyn`.
|
|
fn f1(_: Box<dyn (Fn() -> Box<dyn Dummy>) + Send>) {}
|
|
|
|
// Without parens, `+ Send + Sync` would bind to `dyn Dummy` instead of the outer `impl`.
|
|
fn f2(_: impl (FnMut(&mut u8) -> &mut dyn Dummy) + Send + Sync) {}
|
|
|
|
fn main() {}
|