diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-14 21:55:38 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-14 21:55:38 +0200 |
| commit | bf247c70863cc938819d36731eee79d58c25ffd5 (patch) | |
| tree | d8a7194a9fc292cae7eef276b1d9c0603d9a0af7 | |
| parent | 9b564dfc1df52e12876a6a00c4efcece058b688c (diff) | |
| parent | 6a8718cab772ecfbce3de7a701e9abf8e476bc37 (diff) | |
| download | rust-bf247c70863cc938819d36731eee79d58c25ffd5.tar.gz rust-bf247c70863cc938819d36731eee79d58c25ffd5.zip | |
Rollup merge of #139778 - reddevilmidzy:add-success-test, r=lcnr
Add test for issue 34834
closes: #34834
This PR adds a UI test for a case where a trait with an associated type using a higher-ranked trait bound (HRTB) failed to compile in Rust 1.55.0 but succeeded starting from 1.56.0.
```rust
pub trait Provides<'a> {
type Item;
}
pub trait Selector: for<'a> Provides<'a> {
type Namespace: PartialEq + for<'a> PartialEq<<Self as Provides<'a>>::Item>;
fn get_namespace(&self) -> <Self as Provides>::Item;
}
pub struct MySelector;
impl<'a> Provides<'a> for MySelector {
type Item = &'a str;
}
impl Selector for MySelector {
type Namespace = String;
fn get_namespace(&self) -> &str {
unimplemented!()
}
}
fn main() {}
```
* ❌ [compile fail (rustc: 1.55.0)](https://godbolt.org/z/T1jY1Ebo6)
* ⭕ [compile pass (rustc: 1.56.0)](https://godbolt.org/z/e4jo11Ma7)
| -rw-r--r-- | tests/ui/traits/associated_type_bound/hrtb-associated.rs | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/ui/traits/associated_type_bound/hrtb-associated.rs b/tests/ui/traits/associated_type_bound/hrtb-associated.rs new file mode 100644 index 00000000000..59e5a09c0cb --- /dev/null +++ b/tests/ui/traits/associated_type_bound/hrtb-associated.rs @@ -0,0 +1,30 @@ +//@ check-pass +//! This test ensures that HRTB (higher-ranked trait bounds) on associated types +//! compile correctly. This was previously rejected by the compiler. +//! Related issue: <https://github.com/rust-lang/rust/issues/34834> + +pub trait Provides<'a> { + type Item; +} + +pub trait Selector: for<'a> Provides<'a> { + type Namespace: PartialEq + for<'a> PartialEq<<Self as Provides<'a>>::Item>; + + fn get_namespace(&self) -> <Self as Provides>::Item; +} + +pub struct MySelector; + +impl<'a> Provides<'a> for MySelector { + type Item = &'a str; +} + +impl Selector for MySelector { + type Namespace = String; + + fn get_namespace(&self) -> &str { + unimplemented!() + } +} + +fn main() {} |
