mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 16:24:46 +00:00
Skip ref_match on same types, remove sorting in tests
This commit is contained in:
parent
661cc7f0c8
commit
8a9ebe62a1
@ -259,6 +259,7 @@ impl<'a> Render<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if let Some((_expected_name, expected_type)) = self.ctx.expected_name_and_type() {
|
if let Some((_expected_name, expected_type)) = self.ctx.expected_name_and_type() {
|
||||||
|
if ty != expected_type {
|
||||||
if let Some(ty_without_ref) = expected_type.remove_ref() {
|
if let Some(ty_without_ref) = expected_type.remove_ref() {
|
||||||
if relevance_type_match(self.ctx.db().upcast(), &ty, &ty_without_ref) {
|
if relevance_type_match(self.ctx.db().upcast(), &ty, &ty_without_ref) {
|
||||||
cov_mark::hit!(suggest_ref);
|
cov_mark::hit!(suggest_ref);
|
||||||
@ -272,6 +273,7 @@ impl<'a> Render<'a> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Add `<>` for generic types
|
// Add `<>` for generic types
|
||||||
if self.ctx.completion.is_path_type
|
if self.ctx.completion.is_path_type
|
||||||
@ -340,8 +342,6 @@ fn relevance_type_match(db: &dyn HirDatabase, ty: &Type, expected_type: &Type) -
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::cmp::Reverse;
|
|
||||||
|
|
||||||
use expect_test::{expect, Expect};
|
use expect_test::{expect, Expect};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -366,19 +366,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut completions = get_all_items(TEST_CONFIG, ra_fixture);
|
let actual = get_all_items(TEST_CONFIG, ra_fixture)
|
||||||
completions.sort_by_key(|it| {
|
|
||||||
// (Reverse(it.ref_match().map(|m| m.1).unwrap_or(it.relevance())), it.label().to_string())
|
|
||||||
if let Some((mutability, relevance)) = it.ref_match() {
|
|
||||||
let label = format!("&{}{}", mutability.as_keyword_for_ref(), it.label());
|
|
||||||
|
|
||||||
Reverse((relevance, label))
|
|
||||||
} else {
|
|
||||||
Reverse((it.relevance(), it.label().to_string()))
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
let actual = completions
|
|
||||||
.into_iter()
|
.into_iter()
|
||||||
.filter(|it| it.completion_kind == CompletionKind::Reference)
|
.filter(|it| it.completion_kind == CompletionKind::Reference)
|
||||||
.flat_map(|it| {
|
.flat_map(|it| {
|
||||||
@ -868,9 +856,9 @@ fn test(bar: u32) { }
|
|||||||
fn foo(s: S) { test(s.$0) }
|
fn foo(s: S) { test(s.$0) }
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
fd foo []
|
||||||
fd bar [type+name]
|
fd bar [type+name]
|
||||||
fd baz [type]
|
fd baz [type]
|
||||||
fd foo []
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -885,9 +873,9 @@ struct B { x: (), y: f32, bar: u32 }
|
|||||||
fn foo(a: A) { B { bar: a.$0 }; }
|
fn foo(a: A) { B { bar: a.$0 }; }
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
fd foo []
|
||||||
fd bar [type+name]
|
fd bar [type+name]
|
||||||
fd baz [type]
|
fd baz [type]
|
||||||
fd foo []
|
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -903,8 +891,8 @@ fn foo(a: A) { B { bar: f(a.$0) }; }
|
|||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
fd foo [type+name]
|
fd foo [type+name]
|
||||||
fd baz []
|
|
||||||
fd bar []
|
fd bar []
|
||||||
|
fd baz []
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
check_relevance(
|
check_relevance(
|
||||||
@ -915,9 +903,9 @@ fn f(foo: i64) { }
|
|||||||
fn foo(a: A) { f(B { bar: a.$0 }); }
|
fn foo(a: A) { f(B { bar: a.$0 }); }
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
fd foo []
|
||||||
fd bar [type+name]
|
fd bar [type+name]
|
||||||
fd baz [type]
|
fd baz [type]
|
||||||
fd foo []
|
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -931,9 +919,8 @@ fn go(world: &WorldSnapshot) { go(w$0) }
|
|||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
lc world [type+name]
|
lc world [type+name]
|
||||||
lc &world [type+name]
|
|
||||||
fn go(…) []
|
|
||||||
st WorldSnapshot []
|
st WorldSnapshot []
|
||||||
|
fn go(…) []
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -947,8 +934,8 @@ fn f(foo: &Foo) { f(foo, w$0) }
|
|||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
lc foo []
|
lc foo []
|
||||||
fn f(…) []
|
|
||||||
st Foo []
|
st Foo []
|
||||||
|
fn f(…) []
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -1050,14 +1037,14 @@ fn main() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
lc m []
|
||||||
lc t []
|
lc t []
|
||||||
lc &t [type]
|
lc &t [type]
|
||||||
fn main() []
|
|
||||||
lc m []
|
|
||||||
fn foo(…) []
|
|
||||||
st T []
|
st T []
|
||||||
st S []
|
st S []
|
||||||
|
fn main() []
|
||||||
tt Deref []
|
tt Deref []
|
||||||
|
fn foo(…) []
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -1104,15 +1091,15 @@ fn main() {
|
|||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
|
lc m []
|
||||||
lc t []
|
lc t []
|
||||||
lc &mut t [type]
|
lc &mut t [type]
|
||||||
fn main() []
|
tt DerefMut []
|
||||||
lc m []
|
tt Deref []
|
||||||
fn foo(…) []
|
fn foo(…) []
|
||||||
st T []
|
st T []
|
||||||
st S []
|
st S []
|
||||||
tt DerefMut []
|
fn main() []
|
||||||
tt Deref []
|
|
||||||
"#]],
|
"#]],
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user