Add test for Deref

This commit is contained in:
Florian Diebold 2019-05-12 17:53:33 +02:00
parent 41c56c8a0d
commit 6f946f9656

View File

@ -2737,6 +2737,35 @@ fn main() {
assert_eq!(t, "Foo");
}
#[test]
fn deref_trait() {
let t = type_at(
r#"
//- /main.rs
#[lang = "deref"]
trait Deref {
type Target;
fn deref(&self) -> &Self::Target;
}
struct Arc<T>;
impl<T> Deref for Arc<T> {
type Target = T;
}
struct S;
impl S {
fn foo(&self) -> u128 {}
}
fn test(s: Arc<S>) {
(*s, s.foo())<|>
}
"#,
);
assert_eq!(t, "(S, u128)");
}
fn type_at_pos(db: &MockDatabase, pos: FilePosition) -> String {
let file = db.parse(pos.file_id).ok().unwrap();
let expr = algo::find_node_at_offset::<ast::Expr>(file.syntax(), pos.offset).unwrap();