minor: Add test for parameter and reborrow hint order

This commit is contained in:
Lukas Wirth 2022-04-26 11:46:03 +02:00
parent 1b120216de
commit 5e413997a1

View file

@ -36,13 +36,13 @@ pub enum LifetimeElisionHints {
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
pub enum InlayKind { pub enum InlayKind {
ImplicitReborrow,
TypeHint,
ParameterHint,
ClosureReturnTypeHint,
ChainingHint, ChainingHint,
ClosureReturnTypeHint,
GenericParamListHint, GenericParamListHint,
ImplicitReborrow,
LifetimeHint, LifetimeHint,
ParameterHint,
TypeHint,
} }
#[derive(Debug)] #[derive(Debug)]
@ -110,11 +110,11 @@ fn hints(
config: &InlayHintsConfig, config: &InlayHintsConfig,
node: SyntaxNode, node: SyntaxNode,
) { ) {
let krate = match sema.scope(&node) { let famous_defs = match sema.scope(&node) {
Some(it) => it.krate(), Some(it) => FamousDefs(sema, it.krate()),
None => return, None => return,
}; };
let famous_defs = FamousDefs(sema, krate);
if let Some(expr) = ast::Expr::cast(node.clone()) { if let Some(expr) = ast::Expr::cast(node.clone()) {
chaining_hints(hints, sema, &famous_defs, config, &expr); chaining_hints(hints, sema, &famous_defs, config, &expr);
match expr { match expr {
@ -1637,10 +1637,7 @@ fn main() {
fn skip_constructor_and_enum_type_hints() { fn skip_constructor_and_enum_type_hints() {
check_with_config( check_with_config(
InlayHintsConfig { InlayHintsConfig {
render_colons: true,
type_hints: true, type_hints: true,
parameter_hints: true,
chaining_hints: true,
hide_named_constructor_hints: true, hide_named_constructor_hints: true,
..DISABLED_CONFIG ..DISABLED_CONFIG
}, },
@ -2147,7 +2144,7 @@ impl () {
#[test] #[test]
fn hints_implicit_reborrow() { fn hints_implicit_reborrow() {
check_with_config( check_with_config(
InlayHintsConfig { reborrow_hints: true, ..DISABLED_CONFIG }, InlayHintsConfig { reborrow_hints: true, parameter_hints: true, ..DISABLED_CONFIG },
r#" r#"
fn __() { fn __() {
let unique = &mut (); let unique = &mut ();
@ -2155,12 +2152,15 @@ fn __() {
let foo: &mut _ = unique; let foo: &mut _ = unique;
//^^^^^^ &mut * //^^^^^^ &mut *
ref_mut_id(unique); ref_mut_id(unique);
//^^^^^^ mut_ref
//^^^^^^ &mut * //^^^^^^ &mut *
let shared = ref_id(unique); let shared = ref_id(unique);
//^^^^^^ shared_ref
//^^^^^^ &* //^^^^^^ &*
let mov = shared; let mov = shared;
let r_mov: &_ = shared; let r_mov: &_ = shared;
ref_id(shared); ref_id(shared);
//^^^^^^ shared_ref
identity(unique); identity(unique);
identity(shared); identity(shared);
@ -2168,12 +2168,12 @@ fn __() {
fn identity<T>(t: T) -> T { fn identity<T>(t: T) -> T {
t t
} }
fn ref_mut_id(x: &mut ()) -> &mut () { fn ref_mut_id(mut_ref: &mut ()) -> &mut () {
x mut_ref
//^ &mut * //^^^^^^^ &mut *
} }
fn ref_id(x: &()) -> &() { fn ref_id(shared_ref: &()) -> &() {
x shared_ref
} }
"#, "#,
); );