Skip to content

Commit 7771e67

Browse files
authored
Rollup merge of rust-lang#139778 - reddevilmidzy:add-success-test, r=lcnr
Add test for issue 34834 closes: rust-lang#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)
2 parents e668f8c + 6a8718c commit 7771e67

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//@ check-pass
2+
//! This test ensures that HRTB (higher-ranked trait bounds) on associated types
3+
//! compile correctly. This was previously rejected by the compiler.
4+
//! Related issue: <https://github.com/rust-lang/rust/issues/34834>
5+
6+
pub trait Provides<'a> {
7+
type Item;
8+
}
9+
10+
pub trait Selector: for<'a> Provides<'a> {
11+
type Namespace: PartialEq + for<'a> PartialEq<<Self as Provides<'a>>::Item>;
12+
13+
fn get_namespace(&self) -> <Self as Provides>::Item;
14+
}
15+
16+
pub struct MySelector;
17+
18+
impl<'a> Provides<'a> for MySelector {
19+
type Item = &'a str;
20+
}
21+
22+
impl Selector for MySelector {
23+
type Namespace = String;
24+
25+
fn get_namespace(&self) -> &str {
26+
unimplemented!()
27+
}
28+
}
29+
30+
fn main() {}

0 commit comments

Comments
 (0)