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:
Florian Diebold 2019-11-30 12:35:37 +01:00
parent 7cecd0f331
commit cf6809645e
8 changed files with 82 additions and 53 deletions

View file

@ -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