mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Do autoderef for indexing
This commit is contained in:
parent
e313efb992
commit
31171eed5e
4 changed files with 74 additions and 7 deletions
|
@ -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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue