Skip to content

fix: add parens in transformed dyn type in ref type#22741

Open
A4-Tacks wants to merge 1 commit into
rust-lang:masterfrom
A4-Tacks:transform-ty-parens
Open

fix: add parens in transformed dyn type in ref type#22741
A4-Tacks wants to merge 1 commit into
rust-lang:masterfrom
A4-Tacks:transform-ty-parens

Conversation

@A4-Tacks

@A4-Tacks A4-Tacks commented Jul 8, 2026

Copy link
Copy Markdown
Member

Fixes #10326

Example

trait A<T: ?Sized> { fn a(&self) -> &T; }
trait B {}
impl<'a, T: B> A<dyn 'a + B> for T {$0}

Before this PR

impl<'a, T: B> A<dyn 'a + B> for T {
    fn a(&self) -> &dyn 'a + B {
                 // ^^^^^^^^^^ ambiguous `+` in a type
        ${0:todo!()}
    }
}

After this PR

impl<'a, T: B> A<dyn 'a + B> for T {
    fn a(&self) -> &(dyn 'a + B) {
        ${0:todo!()}
    }
}
Example
---
```rust
trait A<T: ?Sized> { fn a(&self) -> &T; }
trait B {}
impl<'a, T: B> A<dyn 'a + B> for T {$0}
```

**Before this PR**

```rust
impl<'a, T: B> A<dyn 'a + B> for T {
    fn a(&self) -> &dyn 'a + B {
                 // ^^^^^^^^^^ ambiguous `+` in a type
        ${0:todo!()}
    }
}
```

**After this PR**

```rust
impl<'a, T: B> A<dyn 'a + B> for T {
    fn a(&self) -> &(dyn 'a + B) {
        ${0:todo!()}
    }
}
```
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.

2 participants