mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-12-26 21:13:37 +00:00
Merge #3858
3858: Hide unit function return types r=flodiebold a=lnicola r? @flodiebold This might be a bit heavy-handed (e.g. `|| -> ()` to `||`), what do you think? Co-authored-by: Laurențiu Nicola <lnicola@dend.ro>
This commit is contained in:
commit
bf2d91b26a
5 changed files with 28 additions and 20 deletions
|
@ -155,7 +155,11 @@ impl HirDisplay for ApplicationTy {
|
||||||
let sig = FnSig::from_fn_ptr_substs(&self.parameters);
|
let sig = FnSig::from_fn_ptr_substs(&self.parameters);
|
||||||
write!(f, "fn(")?;
|
write!(f, "fn(")?;
|
||||||
f.write_joined(sig.params(), ", ")?;
|
f.write_joined(sig.params(), ", ")?;
|
||||||
write!(f, ") -> {}", sig.ret().display(f.db))?;
|
write!(f, ")")?;
|
||||||
|
let ret = sig.ret();
|
||||||
|
if *ret != Ty::unit() {
|
||||||
|
write!(f, " -> {}", ret.display(f.db))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TypeCtor::FnDef(def) => {
|
TypeCtor::FnDef(def) => {
|
||||||
let sig = f.db.callable_item_signature(def).subst(&self.parameters);
|
let sig = f.db.callable_item_signature(def).subst(&self.parameters);
|
||||||
|
@ -180,7 +184,11 @@ impl HirDisplay for ApplicationTy {
|
||||||
}
|
}
|
||||||
write!(f, "(")?;
|
write!(f, "(")?;
|
||||||
f.write_joined(sig.params(), ", ")?;
|
f.write_joined(sig.params(), ", ")?;
|
||||||
write!(f, ") -> {}", sig.ret().display(f.db))?;
|
write!(f, ")")?;
|
||||||
|
let ret = sig.ret();
|
||||||
|
if *ret != Ty::unit() {
|
||||||
|
write!(f, " -> {}", ret.display(f.db))?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TypeCtor::Adt(def_id) => {
|
TypeCtor::Adt(def_id) => {
|
||||||
let name = match def_id {
|
let name = match def_id {
|
||||||
|
@ -242,16 +250,16 @@ impl HirDisplay for ApplicationTy {
|
||||||
let sig = self.parameters[0]
|
let sig = self.parameters[0]
|
||||||
.callable_sig(f.db)
|
.callable_sig(f.db)
|
||||||
.expect("first closure parameter should contain signature");
|
.expect("first closure parameter should contain signature");
|
||||||
let return_type_hint = sig.ret().display(f.db);
|
|
||||||
if sig.params().is_empty() {
|
if sig.params().is_empty() {
|
||||||
write!(f, "|| -> {}", return_type_hint)?;
|
write!(f, "||")?;
|
||||||
} else if f.omit_verbose_types() {
|
} else if f.omit_verbose_types() {
|
||||||
write!(f, "|{}| -> {}", TYPE_HINT_TRUNCATION, return_type_hint)?;
|
write!(f, "|{}|", TYPE_HINT_TRUNCATION)?;
|
||||||
} else {
|
} else {
|
||||||
write!(f, "|")?;
|
write!(f, "|")?;
|
||||||
f.write_joined(sig.params(), ", ")?;
|
f.write_joined(sig.params(), ", ")?;
|
||||||
write!(f, "| -> {}", return_type_hint)?;
|
write!(f, "|")?;
|
||||||
};
|
};
|
||||||
|
write!(f, " -> {}", sig.ret().display(f.db))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -407,16 +407,16 @@ fn test() {
|
||||||
[30; 31) 'x': &Foo
|
[30; 31) 'x': &Foo
|
||||||
[39; 41) '{}': ()
|
[39; 41) '{}': ()
|
||||||
[52; 133) '{ ...oo); }': ()
|
[52; 133) '{ ...oo); }': ()
|
||||||
[58; 71) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> ()
|
[58; 71) 'takes_ref_foo': fn takes_ref_foo(&Foo)
|
||||||
[58; 77) 'takes_...(&Foo)': ()
|
[58; 77) 'takes_...(&Foo)': ()
|
||||||
[72; 76) '&Foo': &Foo
|
[72; 76) '&Foo': &Foo
|
||||||
[73; 76) 'Foo': Foo
|
[73; 76) 'Foo': Foo
|
||||||
[83; 96) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> ()
|
[83; 96) 'takes_ref_foo': fn takes_ref_foo(&Foo)
|
||||||
[83; 103) 'takes_...&&Foo)': ()
|
[83; 103) 'takes_...&&Foo)': ()
|
||||||
[97; 102) '&&Foo': &&Foo
|
[97; 102) '&&Foo': &&Foo
|
||||||
[98; 102) '&Foo': &Foo
|
[98; 102) '&Foo': &Foo
|
||||||
[99; 102) 'Foo': Foo
|
[99; 102) 'Foo': Foo
|
||||||
[109; 122) 'takes_ref_foo': fn takes_ref_foo(&Foo) -> ()
|
[109; 122) 'takes_ref_foo': fn takes_ref_foo(&Foo)
|
||||||
[109; 130) 'takes_...&&Foo)': ()
|
[109; 130) 'takes_...&&Foo)': ()
|
||||||
[123; 129) '&&&Foo': &&&Foo
|
[123; 129) '&&&Foo': &&&Foo
|
||||||
[124; 129) '&&Foo': &&Foo
|
[124; 129) '&&Foo': &&Foo
|
||||||
|
@ -484,7 +484,7 @@ fn test() {
|
||||||
[171; 178) 'loop {}': !
|
[171; 178) 'loop {}': !
|
||||||
[176; 178) '{}': ()
|
[176; 178) '{}': ()
|
||||||
[191; 236) '{ ... }); }': ()
|
[191; 236) '{ ... }); }': ()
|
||||||
[197; 210) 'takes_ref_str': fn takes_ref_str(&str) -> ()
|
[197; 210) 'takes_ref_str': fn takes_ref_str(&str)
|
||||||
[197; 233) 'takes_...g() })': ()
|
[197; 233) 'takes_...g() })': ()
|
||||||
[211; 232) '&{ ret...ng() }': &String
|
[211; 232) '&{ ret...ng() }': &String
|
||||||
[212; 232) '{ retu...ng() }': String
|
[212; 232) '{ retu...ng() }': String
|
||||||
|
|
|
@ -376,7 +376,7 @@ fn issue_2669() {
|
||||||
),
|
),
|
||||||
@r###"
|
@r###"
|
||||||
[147; 262) '{ ... }': ()
|
[147; 262) '{ ... }': ()
|
||||||
[161; 164) 'end': fn end<{unknown}>() -> ()
|
[161; 164) 'end': fn end<{unknown}>()
|
||||||
[161; 166) 'end()': ()
|
[161; 166) 'end()': ()
|
||||||
[199; 252) '{ ... }': ()
|
[199; 252) '{ ... }': ()
|
||||||
[221; 223) '_x': !
|
[221; 223) '_x': !
|
||||||
|
|
|
@ -521,7 +521,7 @@ fn test() -> &mut &f64 {
|
||||||
[88; 89) 'a': u32
|
[88; 89) 'a': u32
|
||||||
[92; 108) 'unknow...nction': {unknown}
|
[92; 108) 'unknow...nction': {unknown}
|
||||||
[92; 110) 'unknow...tion()': u32
|
[92; 110) 'unknow...tion()': u32
|
||||||
[116; 125) 'takes_u32': fn takes_u32(u32) -> ()
|
[116; 125) 'takes_u32': fn takes_u32(u32)
|
||||||
[116; 128) 'takes_u32(a)': ()
|
[116; 128) 'takes_u32(a)': ()
|
||||||
[126; 127) 'a': u32
|
[126; 127) 'a': u32
|
||||||
[138; 139) 'b': i32
|
[138; 139) 'b': i32
|
||||||
|
@ -1749,9 +1749,9 @@ fn main() {
|
||||||
[67; 91) 'Vtable...| {} }': Vtable
|
[67; 91) 'Vtable...| {} }': Vtable
|
||||||
[84; 89) '|| {}': || -> ()
|
[84; 89) '|| {}': || -> ()
|
||||||
[87; 89) '{}': ()
|
[87; 89) '{}': ()
|
||||||
[101; 102) 'm': fn() -> ()
|
[101; 102) 'm': fn()
|
||||||
[105; 111) 'vtable': Vtable
|
[105; 111) 'vtable': Vtable
|
||||||
[105; 118) 'vtable.method': fn() -> ()
|
[105; 118) 'vtable.method': fn()
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -263,7 +263,7 @@ fn test() {
|
||||||
[119; 120) 'S': S<u32>(u32) -> S<u32>
|
[119; 120) 'S': S<u32>(u32) -> S<u32>
|
||||||
[119; 129) 'S(unknown)': S<u32>
|
[119; 129) 'S(unknown)': S<u32>
|
||||||
[121; 128) 'unknown': u32
|
[121; 128) 'unknown': u32
|
||||||
[135; 138) 'foo': fn foo<S<u32>>(S<u32>) -> ()
|
[135; 138) 'foo': fn foo<S<u32>>(S<u32>)
|
||||||
[135; 141) 'foo(s)': ()
|
[135; 141) 'foo(s)': ()
|
||||||
[139; 140) 's': S<u32>
|
[139; 140) 's': S<u32>
|
||||||
"###
|
"###
|
||||||
|
@ -962,7 +962,7 @@ fn test(x: impl Trait<u64>, y: &impl Trait<u32>) {
|
||||||
[224; 225) 'S': S<u16>(u16) -> S<u16>
|
[224; 225) 'S': S<u16>(u16) -> S<u16>
|
||||||
[224; 228) 'S(1)': S<u16>
|
[224; 228) 'S(1)': S<u16>
|
||||||
[226; 227) '1': u16
|
[226; 227) '1': u16
|
||||||
[234; 237) 'bar': fn bar(S<u16>) -> ()
|
[234; 237) 'bar': fn bar(S<u16>)
|
||||||
[234; 240) 'bar(z)': ()
|
[234; 240) 'bar(z)': ()
|
||||||
[238; 239) 'z': S<u16>
|
[238; 239) 'z': S<u16>
|
||||||
[246; 247) 'x': impl Trait<u64>
|
[246; 247) 'x': impl Trait<u64>
|
||||||
|
@ -1108,8 +1108,8 @@ fn test() {
|
||||||
[40; 47) 'loop {}': !
|
[40; 47) 'loop {}': !
|
||||||
[45; 47) '{}': ()
|
[45; 47) '{}': ()
|
||||||
[91; 124) '{ ...foo; }': ()
|
[91; 124) '{ ...foo; }': ()
|
||||||
[101; 102) 'f': fn(S) -> ()
|
[101; 102) 'f': fn(S)
|
||||||
[118; 121) 'foo': fn foo(S) -> ()
|
[118; 121) 'foo': fn foo(S)
|
||||||
"###
|
"###
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1962,7 +1962,7 @@ fn test() -> impl Trait<i32> {
|
||||||
[229; 241) 'S(default())': S<u32>
|
[229; 241) 'S(default())': S<u32>
|
||||||
[231; 238) 'default': fn default<u32>() -> u32
|
[231; 238) 'default': fn default<u32>() -> u32
|
||||||
[231; 240) 'default()': u32
|
[231; 240) 'default()': u32
|
||||||
[247; 250) 'foo': fn foo(S<u32>) -> ()
|
[247; 250) 'foo': fn foo(S<u32>)
|
||||||
[247; 254) 'foo(s1)': ()
|
[247; 254) 'foo(s1)': ()
|
||||||
[251; 253) 's1': S<u32>
|
[251; 253) 's1': S<u32>
|
||||||
[264; 265) 'x': i32
|
[264; 265) 'x': i32
|
||||||
|
@ -2012,7 +2012,7 @@ fn main() {
|
||||||
[147; 149) '_v': F
|
[147; 149) '_v': F
|
||||||
[192; 195) '{ }': ()
|
[192; 195) '{ }': ()
|
||||||
[207; 238) '{ ... }); }': ()
|
[207; 238) '{ ... }); }': ()
|
||||||
[213; 223) 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ()) -> ()
|
[213; 223) 'f::<(), _>': fn f<(), |&()| -> ()>(|&()| -> ())
|
||||||
[213; 235) 'f::<()... z; })': ()
|
[213; 235) 'f::<()... z; })': ()
|
||||||
[224; 234) '|z| { z; }': |&()| -> ()
|
[224; 234) '|z| { z; }': |&()| -> ()
|
||||||
[225; 226) 'z': &()
|
[225; 226) 'z': &()
|
||||||
|
|
Loading…
Reference in a new issue