Do autoderef for indexing

This commit is contained in:
Florian Diebold 2020-02-29 22:48:23 +01:00
parent e313efb992
commit 31171eed5e
4 changed files with 74 additions and 7 deletions

View file

@ -567,6 +567,34 @@ mod ops {
assert_eq!("Foo", type_at_pos(&db, pos));
}
#[test]
fn infer_ops_index_autoderef() {
let (db, pos) = TestDB::with_position(
r#"
//- /main.rs crate:main deps:std
fn test() {
let a = &[1u32, 2, 3];
let b = a[1];
b<|>;
}
//- /std.rs crate:std
impl<T> ops::Index<u32> for [T] {
type Output = T;
}
#[prelude_import] use ops::*;
mod ops {
#[lang = "index"]
pub trait Index<Idx> {
type Output;
}
}
"#,
);
assert_eq!("u32", type_at_pos(&db, pos));
}
#[test]
fn deref_trait() {
let t = type_at(