mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Implement inline associated type bounds
Like `Iterator<Item: SomeTrait>`. This is an unstable feature, but it's used in the standard library e.g. in the definition of Flatten, so we can't get away with not implementing it :)
This commit is contained in:
parent
c388130f5f
commit
db32a2e421
6 changed files with 120 additions and 17 deletions
|
@ -1923,6 +1923,53 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
|
|||
assert_eq!(t, "{unknown}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_assoc_type_bounds_1() {
|
||||
let t = type_at(
|
||||
r#"
|
||||
//- /main.rs
|
||||
trait Iterator {
|
||||
type Item;
|
||||
}
|
||||
trait OtherTrait<T> {
|
||||
fn foo(&self) -> T;
|
||||
}
|
||||
|
||||
// workaround for Chalk assoc type normalization problems
|
||||
pub struct S<T>;
|
||||
impl<T: Iterator> Iterator for S<T> {
|
||||
type Item = <T as Iterator>::Item;
|
||||
}
|
||||
|
||||
fn test<I: Iterator<Item: OtherTrait<u32>>>() {
|
||||
let x: <S<I> as Iterator>::Item;
|
||||
x.foo()<|>;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_eq!(t, "u32");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_assoc_type_bounds_2() {
|
||||
let t = type_at(
|
||||
r#"
|
||||
//- /main.rs
|
||||
trait Iterator {
|
||||
type Item;
|
||||
}
|
||||
|
||||
fn test<I: Iterator<Item: Iterator<Item = u32>>>() {
|
||||
let x: <<I as Iterator>::Item as Iterator>::Item;
|
||||
x<|>;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
// assert_eq!(t, "u32");
|
||||
// doesn't currently work, Chalk #234
|
||||
assert_eq!(t, "{unknown}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unify_impl_trait() {
|
||||
assert_snapshot!(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue