Add test for unifying impl Trait
This commit is contained in:
parent
4e24b25c66
commit
ac961b2614
1 changed files with 27 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
|||
use super::{infer, type_at, type_at_pos};
|
||||
use super::{infer, infer_with_mismatches, type_at, type_at_pos};
|
||||
use crate::test_db::TestDB;
|
||||
use insta::assert_snapshot;
|
||||
use ra_db::fixture::WithFixture;
|
||||
|
@ -1486,3 +1486,29 @@ fn test<T, U>() where T: Trait<U::Item>, U: Trait<T::Item> {
|
|||
// this is a legitimate cycle
|
||||
assert_eq!(t, "{unknown}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn unify_impl_trait() {
|
||||
assert_snapshot!(
|
||||
infer_with_mismatches(r#"
|
||||
trait Trait<T> {}
|
||||
|
||||
fn foo(x: impl Trait<u32>) { loop {} }
|
||||
fn bar<T>(x: impl Trait<T>) -> T { loop {} }
|
||||
|
||||
struct S<T>(T);
|
||||
impl<T> Trait<T> for S<T> {}
|
||||
|
||||
fn default<T>() -> T { loop {} }
|
||||
|
||||
fn test() -> impl Trait<i32> {
|
||||
let s1 = S(default());
|
||||
foo(s1);
|
||||
let x: i32 = bar(S(default()));
|
||||
S(default())
|
||||
}
|
||||
"#, true),
|
||||
@r###"
|
||||
"###
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue