mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
3964: Nicer Chalk debug logs r=matklad a=flodiebold
I'm looking at a lot of Chalk debug logs at the moment, so here's a few changes to make them slightly nicer...
3965: Implement inline associated type bounds r=matklad a=flodiebold
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 is cherry-picked from my recursive solver branch, where it works better, but I did manage to write a test that works with the current Chalk solver as well...)
3967: Handle `Self::Type` in trait definitions when referring to own associated type r=matklad a=flodiebold
It was implemented for other generic parameters for the trait, but not for `Self`.
(Last one off my recursive solver branch 😄 )
Co-authored-by: Florian Diebold <flodiebold@gmail.com>
This commit is contained in:
commit
d61909f904
10 changed files with 192 additions and 32 deletions
|
@ -451,8 +451,7 @@ pub mod str {
|
|||
"#,
|
||||
);
|
||||
|
||||
// should be Option<char>, but currently not because of Chalk ambiguity problem
|
||||
assert_eq!("(Option<{unknown}>, Option<{unknown}>)", super::type_at_pos(&db, pos));
|
||||
assert_eq!("(Option<char>, Option<char>)", super::type_at_pos(&db, pos));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -1803,7 +1803,7 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn unselected_projection_on_trait_self() {
|
||||
fn unselected_projection_on_impl_self() {
|
||||
assert_snapshot!(infer(
|
||||
r#"
|
||||
//- /main.rs
|
||||
|
@ -1843,6 +1843,30 @@ impl Trait for S2 {
|
|||
"###);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unselected_projection_on_trait_self() {
|
||||
let t = type_at(
|
||||
r#"
|
||||
//- /main.rs
|
||||
trait Trait {
|
||||
type Item;
|
||||
|
||||
fn f(&self) -> Self::Item { loop {} }
|
||||
}
|
||||
|
||||
struct S;
|
||||
impl Trait for S {
|
||||
type Item = u32;
|
||||
}
|
||||
|
||||
fn test() {
|
||||
S.f()<|>;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_eq!(t, "u32");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trait_impl_self_ty() {
|
||||
let t = type_at(
|
||||
|
@ -1923,6 +1947,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