fix: Fix bind pat hint padding

This commit is contained in:
Lukas Wirth 2023-05-18 08:39:54 +02:00
parent c06f088968
commit 03fb1310c2
2 changed files with 105 additions and 122 deletions

View file

@ -89,8 +89,8 @@ pub(super) fn hints(
None None
}; };
let has_colon = matches!(type_ascriptable, Some(Some(_))) && !config.render_colons; let render_colons = config.render_colons && !matches!(type_ascriptable, Some(Some(_)));
if !has_colon { if render_colons {
label.prepend_str(": "); label.prepend_str(": ");
} }
@ -107,7 +107,7 @@ pub(super) fn hints(
label, label,
text_edit, text_edit,
position: InlayHintPosition::After, position: InlayHintPosition::After,
pad_left: false, pad_left: !render_colons,
pad_right: false, pad_right: false,
}); });
@ -194,7 +194,7 @@ mod tests {
fn foo(a: i32, b: i32) -> i32 { a + b } fn foo(a: i32, b: i32) -> i32 { a + b }
fn main() { fn main() {
let _x = foo(4, 4); let _x = foo(4, 4);
//^^ : i32 //^^ i32
}"#, }"#,
); );
} }
@ -206,17 +206,17 @@ fn main() {
//- minicore: option //- minicore: option
fn main() { fn main() {
let ref foo @ bar @ ref mut baz = 0; let ref foo @ bar @ ref mut baz = 0;
//^^^ : &i32 //^^^ &i32
//^^^ : i32 //^^^ i32
//^^^ : &mut i32 //^^^ &mut i32
let [x @ ..] = [0]; let [x @ ..] = [0];
//^ : [i32; 1] //^ [i32; 1]
if let x @ Some(_) = Some(0) {} if let x @ Some(_) = Some(0) {}
//^ : Option<i32> //^ Option<i32>
let foo @ (bar, baz) = (3, 3); let foo @ (bar, baz) = (3, 3);
//^^^ : (i32, i32) //^^^ (i32, i32)
//^^^ : i32 //^^^ i32
//^^^ : i32 //^^^ i32
}"#, }"#,
); );
} }
@ -229,11 +229,11 @@ struct Test<K, T = u8> { k: K, t: T }
fn main() { fn main() {
let zz = Test { t: 23u8, k: 33 }; let zz = Test { t: 23u8, k: 33 };
//^^ : Test<i32> //^^ Test<i32>
let zz_ref = &zz; let zz_ref = &zz;
//^^^^^^ : &Test<i32> //^^^^^^ &Test<i32>
let test = || zz; let test = || zz;
//^^^^ : impl FnOnce() -> Test<i32> //^^^^ impl FnOnce() -> Test<i32>
}"#, }"#,
); );
} }
@ -261,10 +261,10 @@ impl<T> Iterator for SomeIter<T> {
fn main() { fn main() {
let mut some_iter = SomeIter::new(); let mut some_iter = SomeIter::new();
//^^^^^^^^^ : SomeIter<Take<Repeat<i32>>> //^^^^^^^^^ SomeIter<Take<Repeat<i32>>>
some_iter.push(iter::repeat(2).take(2)); some_iter.push(iter::repeat(2).take(2));
let iter_of_iters = some_iter.take(2); let iter_of_iters = some_iter.take(2);
//^^^^^^^^^^^^^ : impl Iterator<Item = impl Iterator<Item = i32>> //^^^^^^^^^^^^^ impl Iterator<Item = impl Iterator<Item = i32>>
} }
"#, "#,
); );
@ -323,7 +323,7 @@ fn main(a: SliceIter<'_, Container>) {
pub fn quux<T: Foo>() -> T::Bar { pub fn quux<T: Foo>() -> T::Bar {
let y = Default::default(); let y = Default::default();
//^ : <T as Foo>::Bar //^ <T as Foo>::Bar
y y
} }
@ -347,21 +347,21 @@ fn foo7() -> *const (impl Fn(f64, f64) -> u32 + Sized) { loop {} }
fn main() { fn main() {
let foo = foo(); let foo = foo();
// ^^^ : impl Fn() // ^^^ impl Fn()
let foo = foo1(); let foo = foo1();
// ^^^ : impl Fn(f64) // ^^^ impl Fn(f64)
let foo = foo2(); let foo = foo2();
// ^^^ : impl Fn(f64, f64) // ^^^ impl Fn(f64, f64)
let foo = foo3(); let foo = foo3();
// ^^^ : impl Fn(f64, f64) -> u32 // ^^^ impl Fn(f64, f64) -> u32
let foo = foo4(); let foo = foo4();
// ^^^ : &dyn Fn(f64, f64) -> u32 // ^^^ &dyn Fn(f64, f64) -> u32
let foo = foo5(); let foo = foo5();
// ^^^ : &dyn Fn(&dyn Fn(f64, f64) -> u32, f64) -> u32 // ^^^ &dyn Fn(&dyn Fn(f64, f64) -> u32, f64) -> u32
let foo = foo6(); let foo = foo6();
// ^^^ : impl Fn(f64, f64) -> u32 // ^^^ impl Fn(f64, f64) -> u32
let foo = foo7(); let foo = foo7();
// ^^^ : *const impl Fn(f64, f64) -> u32 // ^^^ *const impl Fn(f64, f64) -> u32
} }
"#, "#,
) )
@ -384,9 +384,9 @@ fn main() {
let foo = foo(); let foo = foo();
let foo = foo1(); let foo = foo1();
let foo = foo2(); let foo = foo2();
// ^^^ : impl Fn(f64, f64) // ^^^ impl Fn(f64, f64)
let foo = foo3(); let foo = foo3();
// ^^^ : impl Fn(f64, f64) -> u32 // ^^^ impl Fn(f64, f64) -> u32
let foo = foo4(); let foo = foo4();
let foo = foo5(); let foo = foo5();
let foo = foo6(); let foo = foo6();
@ -427,25 +427,25 @@ fn foo10() -> *const (impl Fn() + Sized + ?Sized) { loop {} }
fn main() { fn main() {
let foo = foo1(); let foo = foo1();
// ^^^ : *const impl Fn() // ^^^ *const impl Fn()
let foo = foo2(); let foo = foo2();
// ^^^ : *const impl Fn() // ^^^ *const impl Fn()
let foo = foo3(); let foo = foo3();
// ^^^ : *const (impl Fn() + ?Sized) // ^^^ *const (impl Fn() + ?Sized)
let foo = foo4(); let foo = foo4();
// ^^^ : *const impl Fn() // ^^^ *const impl Fn()
let foo = foo5(); let foo = foo5();
// ^^^ : *const (impl Fn() + ?Sized) // ^^^ *const (impl Fn() + ?Sized)
let foo = foo6(); let foo = foo6();
// ^^^ : *const (impl Fn() + Trait) // ^^^ *const (impl Fn() + Trait)
let foo = foo7(); let foo = foo7();
// ^^^ : *const (impl Fn() + Trait) // ^^^ *const (impl Fn() + Trait)
let foo = foo8(); let foo = foo8();
// ^^^ : *const (impl Fn() + Trait + ?Sized) // ^^^ *const (impl Fn() + Trait + ?Sized)
let foo = foo9(); let foo = foo9();
// ^^^ : *const (impl Fn() -> u8 + ?Sized) // ^^^ *const (impl Fn() -> u8 + ?Sized)
let foo = foo10(); let foo = foo10();
// ^^^ : *const impl Fn() // ^^^ *const impl Fn()
} }
"#, "#,
) )
@ -496,24 +496,24 @@ fn main() {
struct InnerStruct {} struct InnerStruct {}
let test = 54; let test = 54;
//^^^^ : i32 //^^^^ i32
let test: i32 = 33; let test: i32 = 33;
let mut test = 33; let mut test = 33;
//^^^^ : i32 //^^^^ i32
let _ = 22; let _ = 22;
let test = "test"; let test = "test";
//^^^^ : &str //^^^^ &str
let test = InnerStruct {}; let test = InnerStruct {};
//^^^^ : InnerStruct //^^^^ InnerStruct
let test = unresolved(); let test = unresolved();
let test = (42, 'a'); let test = (42, 'a');
//^^^^ : (i32, char) //^^^^ (i32, char)
let (a, (b, (c,)) = (2, (3, (9.2,)); let (a, (b, (c,)) = (2, (3, (9.2,));
//^ : i32 ^ : i32 ^ : f64 //^ i32 ^ i32 ^ f64
let &x = &92; let &x = &92;
//^ : i32 //^ i32
}"#, }"#,
); );
} }
@ -526,24 +526,7 @@ fn main() {
struct Test { a: Option<u32>, b: u8 } struct Test { a: Option<u32>, b: u8 }
fn main() { fn main() {
let test = Some(Test { a: Some(3), b: 1 });
//^^^^ : Option<Test>
if let None = &test {};
if let test = &test {};
//^^^^ : &Option<Test>
if let Some(test) = &test {};
//^^^^ : &Test
if let Some(Test { a, b }) = &test {};
//^ : &Option<u32> ^ : &u8
if let Some(Test { a: x, b: y }) = &test {};
//^ : &Option<u32> ^ : &u8
if let Some(Test { a: Some(x), b: y }) = &test {};
//^ : &u32 ^ : &u8
if let Some(Test { a: None, b: y }) = &test {};
//^ : &u8
if let Some(Test { b: y, .. }) = &test {};
//^ : &u8
if test == None {}
}"#, }"#,
); );
} }
@ -557,9 +540,9 @@ struct Test { a: Option<u32>, b: u8 }
fn main() { fn main() {
let test = Some(Test { a: Some(3), b: 1 }); let test = Some(Test { a: Some(3), b: 1 });
//^^^^ : Option<Test> //^^^^ Option<Test>
while let Some(Test { a: Some(x), b: y }) = &test {}; while let Some(Test { a: Some(x), b: y }) = &test {};
//^ : &u32 ^ : &u8 //^ &u32 ^ &u8
}"#, }"#,
); );
} }
@ -575,9 +558,9 @@ fn main() {
match Some(Test { a: Some(3), b: 1 }) { match Some(Test { a: Some(3), b: 1 }) {
None => (), None => (),
test => (), test => (),
//^^^^ : Option<Test> //^^^^ Option<Test>
Some(Test { a: Some(x), b: y }) => (), Some(Test { a: Some(x), b: y }) => (),
//^ : u32 ^ : u8 //^ u32 ^ u8
_ => {} _ => {}
} }
}"#, }"#,
@ -609,12 +592,12 @@ impl<T> Iterator for IntoIter<T> {
fn main() { fn main() {
let mut data = Vec::new(); let mut data = Vec::new();
//^^^^ : Vec<&str> //^^^^ Vec<&str>
data.push("foo"); data.push("foo");
for i in data { for i in data {
//^ : &str //^ &str
let z = i; let z = i;
//^ : &str //^ &str
} }
} }
"#, "#,
@ -639,11 +622,11 @@ auto trait Sync {}
fn main() { fn main() {
// The block expression wrapping disables the constructor hint hiding logic // The block expression wrapping disables the constructor hint hiding logic
let _v = { Vec::<Box<&(dyn Display + Sync)>>::new() }; let _v = { Vec::<Box<&(dyn Display + Sync)>>::new() };
//^^ : Vec<Box<&(dyn Display + Sync)>> //^^ Vec<Box<&(dyn Display + Sync)>>
let _v = { Vec::<Box<*const (dyn Display + Sync)>>::new() }; let _v = { Vec::<Box<*const (dyn Display + Sync)>>::new() };
//^^ : Vec<Box<*const (dyn Display + Sync)>> //^^ Vec<Box<*const (dyn Display + Sync)>>
let _v = { Vec::<Box<dyn Display + Sync>>::new() }; let _v = { Vec::<Box<dyn Display + Sync>>::new() };
//^^ : Vec<Box<dyn Display + Sync>> //^^ Vec<Box<dyn Display + Sync>>
} }
"#, "#,
); );
@ -667,14 +650,14 @@ impl Iterator for MyIter {
fn main() { fn main() {
let _x = MyIter; let _x = MyIter;
//^^ : MyIter //^^ MyIter
let _x = iter::repeat(0); let _x = iter::repeat(0);
//^^ : impl Iterator<Item = i32> //^^ impl Iterator<Item = i32>
fn generic<T: Clone>(t: T) { fn generic<T: Clone>(t: T) {
let _x = iter::repeat(t); let _x = iter::repeat(t);
//^^ : impl Iterator<Item = T> //^^ impl Iterator<Item = T>
let _chained = iter::repeat(t).take(10); let _chained = iter::repeat(t).take(10);
//^^^^^^^^ : impl Iterator<Item = T> //^^^^^^^^ impl Iterator<Item = T>
} }
} }
"#, "#,
@ -738,20 +721,20 @@ fn main() {
let tuple_struct = TupleStruct(); let tuple_struct = TupleStruct();
let generic0 = Generic::new(); let generic0 = Generic::new();
// ^^^^^^^^ : Generic<i32> // ^^^^^^^^ Generic<i32>
let generic1 = Generic(0); let generic1 = Generic(0);
// ^^^^^^^^ : Generic<i32> // ^^^^^^^^ Generic<i32>
let generic2 = Generic::<i32>::new(); let generic2 = Generic::<i32>::new();
let generic3 = <Generic<i32>>::new(); let generic3 = <Generic<i32>>::new();
let generic4 = Generic::<i32>(0); let generic4 = Generic::<i32>(0);
let option = Some(0); let option = Some(0);
// ^^^^^^ : Option<i32> // ^^^^^^ Option<i32>
let func = times2; let func = times2;
// ^^^^ : fn times2(i32) -> i32 // ^^^^ fn times2(i32) -> i32
let closure = |x: i32| x * 2; let closure = |x: i32| x * 2;
// ^^^^^^^ : impl Fn(i32) -> i32 // ^^^^^^^ impl Fn(i32) -> i32
} }
fn fallible() -> ControlFlow<()> { fn fallible() -> ControlFlow<()> {
@ -789,20 +772,20 @@ impl Generic<i32> {
fn main() { fn main() {
let strukt = Struct::new(); let strukt = Struct::new();
// ^^^^^^ : Struct // ^^^^^^ Struct
let tuple_struct = TupleStruct(); let tuple_struct = TupleStruct();
// ^^^^^^^^^^^^ : TupleStruct // ^^^^^^^^^^^^ TupleStruct
let generic0 = Generic::new(); let generic0 = Generic::new();
// ^^^^^^^^ : Generic<i32> // ^^^^^^^^ Generic<i32>
let generic1 = Generic::<i32>::new(); let generic1 = Generic::<i32>::new();
// ^^^^^^^^ : Generic<i32> // ^^^^^^^^ Generic<i32>
let generic2 = <Generic<i32>>::new(); let generic2 = <Generic<i32>>::new();
// ^^^^^^^^ : Generic<i32> // ^^^^^^^^ Generic<i32>
} }
fn fallible() -> ControlFlow<()> { fn fallible() -> ControlFlow<()> {
let strukt = Struct::try_new()?; let strukt = Struct::try_new()?;
// ^^^^^^ : Struct // ^^^^^^ Struct
} }
"#, "#,
); );
@ -816,15 +799,15 @@ fn fallible() -> ControlFlow<()> {
//- minicore: fn //- minicore: fn
fn main() { fn main() {
let x = || 2; let x = || 2;
//^ : impl Fn() -> i32 //^ impl Fn() -> i32
let y = |t: i32| x() + t; let y = |t: i32| x() + t;
//^ : impl Fn(i32) -> i32 //^ impl Fn(i32) -> i32
let mut t = 5; let mut t = 5;
//^ : i32 //^ i32
let z = |k: i32| { t += k; }; let z = |k: i32| { t += k; };
//^ : impl FnMut(i32) //^ impl FnMut(i32)
let p = (y, z); let p = (y, z);
//^ : (impl Fn(i32) -> i32, impl FnMut(i32)) //^ (impl Fn(i32) -> i32, impl FnMut(i32))
} }
"#, "#,
); );
@ -838,15 +821,15 @@ fn main() {
//- minicore: fn //- minicore: fn
fn main() { fn main() {
let x = || 2; let x = || 2;
//^ : || -> i32 //^ || -> i32
let y = |t: i32| x() + t; let y = |t: i32| x() + t;
//^ : |i32| -> i32 //^ |i32| -> i32
let mut t = 5; let mut t = 5;
//^ : i32 //^ i32
let z = |k: i32| { t += k; }; let z = |k: i32| { t += k; };
//^ : |i32| -> () //^ |i32| -> ()
let p = (y, z); let p = (y, z);
//^ : (|i32| -> i32, |i32| -> ()) //^ (|i32| -> i32, |i32| -> ())
} }
"#, "#,
); );
@ -860,15 +843,15 @@ fn main() {
//- minicore: fn //- minicore: fn
fn main() { fn main() {
let x = || 2; let x = || 2;
//^ : {closure#0} //^ {closure#0}
let y = |t: i32| x() + t; let y = |t: i32| x() + t;
//^ : {closure#1} //^ {closure#1}
let mut t = 5; let mut t = 5;
//^ : i32 //^ i32
let z = |k: i32| { t += k; }; let z = |k: i32| { t += k; };
//^ : {closure#2} //^ {closure#2}
let p = (y, z); let p = (y, z);
//^ : ({closure#1}, {closure#2}) //^ ({closure#1}, {closure#2})
} }
"#, "#,
); );
@ -882,15 +865,15 @@ fn main() {
//- minicore: fn //- minicore: fn
fn main() { fn main() {
let x = || 2; let x = || 2;
//^ : //^
let y = |t: i32| x() + t; let y = |t: i32| x() + t;
//^ : //^
let mut t = 5; let mut t = 5;
//^ : i32 //^ i32
let z = |k: i32| { t += k; }; let z = |k: i32| { t += k; };
//^ : //^
let p = (y, z); let p = (y, z);
//^ : (…, …) //^ (…, …)
} }
"#, "#,
); );
@ -910,24 +893,24 @@ fn main() {
let multiple_2 = |x: i32| { x * 2 }; let multiple_2 = |x: i32| { x * 2 };
let multiple_2 = |x: i32| x * 2; let multiple_2 = |x: i32| x * 2;
// ^^^^^^^^^^ : impl Fn(i32) -> i32 // ^^^^^^^^^^ impl Fn(i32) -> i32
let (not) = (|x: bool| { !x }); let (not) = (|x: bool| { !x });
// ^^^ : impl Fn(bool) -> bool // ^^^ impl Fn(bool) -> bool
let (is_zero, _b) = (|x: usize| { x == 0 }, false); let (is_zero, _b) = (|x: usize| { x == 0 }, false);
// ^^^^^^^ : impl Fn(usize) -> bool // ^^^^^^^ impl Fn(usize) -> bool
// ^^ : bool // ^^ bool
let plus_one = |x| { x + 1 }; let plus_one = |x| { x + 1 };
// ^ : u8 // ^ u8
foo(plus_one); foo(plus_one);
let add_mul = bar(|x: u8| { x + 1 }); let add_mul = bar(|x: u8| { x + 1 });
// ^^^^^^^ : impl FnOnce(u8) -> u8 + ?Sized // ^^^^^^^ impl FnOnce(u8) -> u8 + ?Sized
let closure = if let Some(6) = add_mul(2).checked_sub(1) { let closure = if let Some(6) = add_mul(2).checked_sub(1) {
// ^^^^^^^ : fn(i32) -> i32 // ^^^^^^^ fn(i32) -> i32
|x: i32| { x * 2 } |x: i32| { x * 2 }
} else { } else {
|x: i32| { x * 3 } |x: i32| { x * 3 }
@ -954,11 +937,11 @@ struct VeryLongOuterName<T>(T);
fn main() { fn main() {
let a = Smol(0u32); let a = Smol(0u32);
//^ : Smol<u32> //^ Smol<u32>
let b = VeryLongOuterName(0usize); let b = VeryLongOuterName(0usize);
//^ : VeryLongOuterName<…> //^ VeryLongOuterName<…>
let c = Smol(Smol(0u32)) let c = Smol(Smol(0u32))
//^ : Smol<Smol<…>> //^ Smol<Smol<…>>
}"#, }"#,
); );
} }

View file

@ -626,11 +626,11 @@ fn main() {
InlayHint { InlayHint {
range: 124..130, range: 124..130,
position: After, position: After,
pad_left: false, pad_left: true,
pad_right: false, pad_right: false,
kind: Type, kind: Type,
label: [ label: [
": ", "",
InlayHintLabelPart { InlayHintLabelPart {
text: "Struct", text: "Struct",
linked_location: Some( linked_location: Some(