mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Handle cycles in impl types better
- impl Trait<Self> for S is allowed - impl Trait for S<Self> is an invalid cycle, but we can add cycle recovery for it in Salsa now
This commit is contained in:
parent
7cecd0f331
commit
cf6809645e
8 changed files with 82 additions and 53 deletions
|
@ -4675,6 +4675,48 @@ fn test<T, U>() where T::Item: Trait2, T: Trait<U::Item>, U: Trait<()> {
|
|||
assert_eq!(t, "u32");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trait_impl_self_ty() {
|
||||
let t = type_at(
|
||||
r#"
|
||||
//- /main.rs
|
||||
trait Trait<T> {
|
||||
fn foo(&self);
|
||||
}
|
||||
|
||||
struct S;
|
||||
|
||||
impl Trait<Self> for S {}
|
||||
|
||||
fn test() {
|
||||
S.foo()<|>;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_eq!(t, "()");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn trait_impl_self_ty_cycle() {
|
||||
let t = type_at(
|
||||
r#"
|
||||
//- /main.rs
|
||||
trait Trait {
|
||||
fn foo(&self);
|
||||
}
|
||||
|
||||
struct S<T>;
|
||||
|
||||
impl Trait for S<Self> {}
|
||||
|
||||
fn test() {
|
||||
S.foo()<|>;
|
||||
}
|
||||
"#,
|
||||
);
|
||||
assert_eq!(t, "{unknown}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
// FIXME this is currently a Salsa panic; it would be nicer if it just returned
|
||||
// in Unknown, and we should be able to do that once Salsa allows us to handle
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue