Skip to content

Commit 35e268d

Browse files
committed
include fn prefix for all callable defs
1 parent 4c5b250 commit 35e268d

File tree

3 files changed

+29
-36
lines changed

3 files changed

+29
-36
lines changed

src/tools/rust-analyzer/crates/hir-ty/src/display.rs

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1014,29 +1014,22 @@ impl HirDisplay for Ty {
10141014
f.write_str("\" ")?;
10151015
}
10161016

1017+
write!(f, "fn ")?;
1018+
f.start_location_link(def.into());
10171019
match def {
1018-
CallableDefId::FunctionId(ff) => {
1019-
write!(f, "fn ")?;
1020-
f.start_location_link(def.into());
1021-
write!(
1022-
f,
1023-
"{}",
1024-
db.function_data(ff).name.display(f.db.upcast(), f.edition())
1025-
)?
1026-
}
1020+
CallableDefId::FunctionId(ff) => write!(
1021+
f,
1022+
"{}",
1023+
db.function_data(ff).name.display(f.db.upcast(), f.edition())
1024+
)?,
10271025
CallableDefId::StructId(s) => {
1028-
write!(f, "fn ")?;
1029-
f.start_location_link(def.into());
10301026
write!(f, "{}", db.struct_data(s).name.display(f.db.upcast(), f.edition()))?
10311027
}
1032-
CallableDefId::EnumVariantId(e) => {
1033-
f.start_location_link(def.into());
1034-
write!(
1035-
f,
1036-
"{}",
1037-
db.enum_variant_data(e).name.display(f.db.upcast(), f.edition())
1038-
)?
1039-
}
1028+
CallableDefId::EnumVariantId(e) => write!(
1029+
f,
1030+
"{}",
1031+
db.enum_variant_data(e).name.display(f.db.upcast(), f.edition())
1032+
)?,
10401033
};
10411034
f.end_location_link();
10421035

src/tools/rust-analyzer/crates/hir-ty/src/tests/simple.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ impl E {
634634
149..150 '1': isize
635635
184..230 '{ ... }': ()
636636
194..202 'Self::V1': E
637-
212..220 'Self::V2': V2(u32) -> E
637+
212..220 'Self::V2': fn V2(u32) -> E
638638
212..223 'Self::V2(1)': E
639639
221..222 '1': u32
640640
"#]],
@@ -1283,10 +1283,10 @@ fn infer_tuple_struct_generics() {
12831283
92..93 'A': fn A<u128>(u128) -> A<u128>
12841284
92..101 'A(42u128)': A<u128>
12851285
94..100 '42u128': u128
1286-
107..111 'Some': Some<&'static str>(&'static str) -> Option<&'static str>
1286+
107..111 'Some': fn Some<&'static str>(&'static str) -> Option<&'static str>
12871287
107..116 'Some("x")': Option<&'static str>
12881288
112..115 '"x"': &'static str
1289-
122..134 'Option::Some': Some<&'static str>(&'static str) -> Option<&'static str>
1289+
122..134 'Option::Some': fn Some<&'static str>(&'static str) -> Option<&'static str>
12901290
122..139 'Option...e("x")': Option<&'static str>
12911291
135..138 '"x"': &'static str
12921292
145..149 'None': Option<{unknown}>
@@ -1572,7 +1572,7 @@ fn infer_type_alias() {
15721572
204..207 'z.y': i8
15731573
298..362 '{ ... &e; }': ()
15741574
308..309 'e': Enum
1575-
312..325 'm::Alias::Foo': Foo(u8) -> Enum
1575+
312..325 'm::Alias::Foo': fn Foo(u8) -> Enum
15761576
312..328 'm::Ali...Foo(0)': Enum
15771577
326..327 '0': u8
15781578
338..354 'm::Ali...Foo(x)': Enum
@@ -2191,21 +2191,21 @@ fn main() {
21912191
103..231 '{ ... }); }': ()
21922192
109..161 'async ... }': impl Future<Output = Result<(), ()>>
21932193
125..139 'return Err(())': !
2194-
132..135 'Err': Err<(), ()>(()) -> Result<(), ()>
2194+
132..135 'Err': fn Err<(), ()>(()) -> Result<(), ()>
21952195
132..139 'Err(())': Result<(), ()>
21962196
136..138 '()': ()
2197-
149..151 'Ok': Ok<(), ()>(()) -> Result<(), ()>
2197+
149..151 'Ok': fn Ok<(), ()>(()) -> Result<(), ()>
21982198
149..155 'Ok(())': Result<(), ()>
21992199
152..154 '()': ()
22002200
167..171 'test': fn test<(), (), impl FnMut() -> impl Future<Output = Result<(), ()>>, impl Future<Output = Result<(), ()>>>(impl FnMut() -> impl Future<Output = Result<(), ()>>)
22012201
167..228 'test(|... })': ()
22022202
172..227 '|| asy... }': impl FnMut() -> impl Future<Output = Result<(), ()>>
22032203
175..227 'async ... }': impl Future<Output = Result<(), ()>>
22042204
191..205 'return Err(())': !
2205-
198..201 'Err': Err<(), ()>(()) -> Result<(), ()>
2205+
198..201 'Err': fn Err<(), ()>(()) -> Result<(), ()>
22062206
198..205 'Err(())': Result<(), ()>
22072207
202..204 '()': ()
2208-
215..217 'Ok': Ok<(), ()>(()) -> Result<(), ()>
2208+
215..217 'Ok': fn Ok<(), ()>(()) -> Result<(), ()>
22092209
215..221 'Ok(())': Result<(), ()>
22102210
218..220 '()': ()
22112211
"#]],
@@ -2234,7 +2234,7 @@ fn infer_generic_from_later_assignment() {
22342234
94..127 '{ ... }': ()
22352235
104..107 'end': Option<bool>
22362236
104..120 'end = ...(true)': ()
2237-
110..114 'Some': Some<bool>(bool) -> Option<bool>
2237+
110..114 'Some': fn Some<bool>(bool) -> Option<bool>
22382238
110..120 'Some(true)': Option<bool>
22392239
115..119 'true': bool
22402240
"#]],
@@ -2269,7 +2269,7 @@ fn infer_loop_break_with_val() {
22692269
111..121 'break None': !
22702270
117..121 'None': Option<bool>
22712271
142..158 'break ...(true)': !
2272-
148..152 'Some': Some<bool>(bool) -> Option<bool>
2272+
148..152 'Some': fn Some<bool>(bool) -> Option<bool>
22732273
148..158 'Some(true)': Option<bool>
22742274
153..157 'true': bool
22752275
"#]],
@@ -2516,7 +2516,7 @@ fn generic_default_in_struct_literal() {
25162516
254..281 'OtherT...1i32 }': OtherThing<i32>
25172517
275..279 '1i32': i32
25182518
291..292 'b': OtherThing<i32>
2519-
295..310 'OtherThing::Two': Two<i32>(i32) -> OtherThing<i32>
2519+
295..310 'OtherThing::Two': fn Two<i32>(i32) -> OtherThing<i32>
25202520
295..316 'OtherT...(1i32)': OtherThing<i32>
25212521
311..315 '1i32': i32
25222522
"#]],
@@ -3028,7 +3028,7 @@ fn f() {
30283028
expect![[r#"
30293029
72..166 '{ ... } }': ()
30303030
78..164 'match ... }': ()
3031-
84..92 'Foo::Bar': Bar(i32) -> Foo
3031+
84..92 'Foo::Bar': fn Bar(i32) -> Foo
30323032
84..95 'Foo::Bar(3)': Foo
30333033
93..94 '3': i32
30343034
106..119 'Qux::Bar(bar)': Foo

src/tools/rust-analyzer/crates/hir-ty/src/tests/traits.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,10 +1269,10 @@ fn bar() {
12691269
226..229 'foo': fn foo<i32>([R<(), i32>; 2]) -> i32
12701270
226..250 'foo([R...B(7)])': i32
12711271
230..249 '[R::A(...:B(7)]': [R<(), i32>; 2]
1272-
231..235 'R::A': A<(), i32>(()) -> R<(), i32>
1272+
231..235 'R::A': fn A<(), i32>(()) -> R<(), i32>
12731273
231..239 'R::A(())': R<(), i32>
12741274
236..238 '()': ()
1275-
241..245 'R::B': B<(), i32>(i32) -> R<(), i32>
1275+
241..245 'R::B': fn B<(), i32>(i32) -> R<(), i32>
12761276
241..248 'R::B(7)': R<(), i32>
12771277
246..247 '7': i32
12781278
"#]],
@@ -2046,7 +2046,7 @@ fn test() {
20462046
118..120 '{}': ()
20472047
136..255 '{ ... 1); }': ()
20482048
146..147 'x': Option<u32>
2049-
150..162 'Option::Some': Some<u32>(u32) -> Option<u32>
2049+
150..162 'Option::Some': fn Some<u32>(u32) -> Option<u32>
20502050
150..168 'Option...(1u32)': Option<u32>
20512051
163..167 '1u32': u32
20522052
174..175 'x': Option<u32>
@@ -2846,7 +2846,7 @@ fn main() {
28462846
1036..1041 'x > 0': bool
28472847
1040..1041 '0': i32
28482848
1042..1060 '{ Some...u32) }': Option<u32>
2849-
1044..1048 'Some': Some<u32>(u32) -> Option<u32>
2849+
1044..1048 'Some': fn Some<u32>(u32) -> Option<u32>
28502850
1044..1058 'Some(x as u32)': Option<u32>
28512851
1049..1050 'x': i32
28522852
1049..1057 'x as u32': u32
@@ -2984,7 +2984,7 @@ fn test() {
29842984
191..201 'bar.test()': bool
29852985
207..213 'Struct': fn Struct(usize) -> Struct
29862986
207..220 'Struct.test()': bool
2987-
226..239 'Enum::Variant': Variant(usize) -> Enum
2987+
226..239 'Enum::Variant': fn Variant(usize) -> Enum
29882988
226..246 'Enum::...test()': bool
29892989
"#]],
29902990
);

0 commit comments

Comments
 (0)