Skip to content

Commit 64f510c

Browse files
committed
Auto merge of rust-lang#18269 - jhgg:hir-ty/change-struct-constructor-formatting, r=flodiebold
hir-ty: change struct + enum variant constructor formatting. before, when formatting struct constructor for `struct S(usize, usize)` it would format as: extern "rust-call" S(usize, usize) -> S but after this change, we'll format as: fn S(usize, usize) -> S likewise the second commit, also makes this uniform for enum variants as well. fixes rust-lang#18259
2 parents 84a16c4 + 35e268d commit 64f510c

File tree

6 files changed

+65
-71
lines changed

6 files changed

+65
-71
lines changed

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

+13-19
Original file line numberDiff line numberDiff line change
@@ -1008,34 +1008,28 @@ impl HirDisplay for Ty {
10081008
if let Safety::Unsafe = sig.safety {
10091009
write!(f, "unsafe ")?;
10101010
}
1011-
if !matches!(sig.abi, FnAbi::Rust) {
1011+
if !matches!(sig.abi, FnAbi::Rust | FnAbi::RustCall) {
10121012
f.write_str("extern \"")?;
10131013
f.write_str(sig.abi.as_str())?;
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-
f.start_location_link(def.into());
10291026
write!(f, "{}", db.struct_data(s).name.display(f.db.upcast(), f.edition()))?
10301027
}
1031-
CallableDefId::EnumVariantId(e) => {
1032-
f.start_location_link(def.into());
1033-
write!(
1034-
f,
1035-
"{}",
1036-
db.enum_variant_data(e).name.display(f.db.upcast(), f.edition())
1037-
)?
1038-
}
1028+
CallableDefId::EnumVariantId(e) => write!(
1029+
f,
1030+
"{}",
1031+
db.enum_variant_data(e).name.display(f.db.upcast(), f.edition())
1032+
)?,
10391033
};
10401034
f.end_location_link();
10411035

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/tests/macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ fn infer_macros_expanded() {
6464
"#,
6565
expect![[r#"
6666
!0..17 '{Foo(v...,2,])}': Foo
67-
!1..4 'Foo': extern "rust-call" Foo({unknown}) -> Foo
67+
!1..4 'Foo': fn Foo({unknown}) -> Foo
6868
!1..16 'Foo(vec![1,2,])': Foo
6969
!5..15 'vec![1,2,]': {unknown}
7070
155..181 '{ ...,2); }': ()
@@ -97,7 +97,7 @@ fn infer_legacy_textual_scoped_macros_expanded() {
9797
"#,
9898
expect![[r#"
9999
!0..17 '{Foo(v...,2,])}': Foo
100-
!1..4 'Foo': extern "rust-call" Foo({unknown}) -> Foo
100+
!1..4 'Foo': fn Foo({unknown}) -> Foo
101101
!1..16 'Foo(vec![1,2,])': Foo
102102
!5..15 'vec![1,2,]': {unknown}
103103
194..250 '{ ...,2); }': ()

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/tests/patterns.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -227,13 +227,13 @@ fn infer_pattern_match_ergonomics() {
227227
37..41 'A(n)': A<i32>
228228
39..40 'n': &'? i32
229229
44..49 '&A(1)': &'? A<i32>
230-
45..46 'A': extern "rust-call" A<i32>(i32) -> A<i32>
230+
45..46 'A': fn A<i32>(i32) -> A<i32>
231231
45..49 'A(1)': A<i32>
232232
47..48 '1': i32
233233
59..63 'A(n)': A<i32>
234234
61..62 'n': &'? mut i32
235235
66..75 '&mut A(1)': &'? mut A<i32>
236-
71..72 'A': extern "rust-call" A<i32>(i32) -> A<i32>
236+
71..72 'A': fn A<i32>(i32) -> A<i32>
237237
71..75 'A(1)': A<i32>
238238
73..74 '1': i32
239239
"#]],
@@ -548,18 +548,18 @@ impl Foo {
548548
56..64 'Self(s,)': Foo
549549
61..62 's': &'? usize
550550
67..75 '&Foo(0,)': &'? Foo
551-
68..71 'Foo': extern "rust-call" Foo(usize) -> Foo
551+
68..71 'Foo': fn Foo(usize) -> Foo
552552
68..75 'Foo(0,)': Foo
553553
72..73 '0': usize
554554
89..97 'Self(s,)': Foo
555555
94..95 's': &'? mut usize
556556
100..112 '&mut Foo(0,)': &'? mut Foo
557-
105..108 'Foo': extern "rust-call" Foo(usize) -> Foo
557+
105..108 'Foo': fn Foo(usize) -> Foo
558558
105..112 'Foo(0,)': Foo
559559
109..110 '0': usize
560560
126..134 'Self(s,)': Foo
561561
131..132 's': usize
562-
137..140 'Foo': extern "rust-call" Foo(usize) -> Foo
562+
137..140 'Foo': fn Foo(usize) -> Foo
563563
137..144 'Foo(0,)': Foo
564564
141..142 '0': usize
565565
"#]],
@@ -933,7 +933,7 @@ fn foo(foo: Foo) {
933933
48..51 'foo': Foo
934934
62..84 'const ... 32) }': Foo
935935
68..84 '{ Foo(... 32) }': Foo
936-
70..73 'Foo': extern "rust-call" Foo(usize) -> Foo
936+
70..73 'Foo': fn Foo(usize) -> Foo
937937
70..82 'Foo(15 + 32)': Foo
938938
74..76 '15': usize
939939
74..81 '15 + 32': usize

Diff for: src/tools/rust-analyzer/crates/hir-ty/src/tests/regression.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ fn issue_4953() {
645645
"#,
646646
expect![[r#"
647647
58..72 '{ Self(0i64) }': Foo
648-
60..64 'Self': extern "rust-call" Foo(i64) -> Foo
648+
60..64 'Self': fn Foo(i64) -> Foo
649649
60..70 'Self(0i64)': Foo
650650
65..69 '0i64': i64
651651
"#]],
@@ -659,7 +659,7 @@ fn issue_4953() {
659659
"#,
660660
expect![[r#"
661661
64..78 '{ Self(0i64) }': Foo<i64>
662-
66..70 'Self': extern "rust-call" Foo<i64>(i64) -> Foo<i64>
662+
66..70 'Self': fn Foo<i64>(i64) -> Foo<i64>
663663
66..76 'Self(0i64)': Foo<i64>
664664
71..75 '0i64': i64
665665
"#]],
@@ -859,7 +859,7 @@ fn main() {
859859
94..96 '{}': ()
860860
109..160 '{ ...10); }': ()
861861
119..120 's': S<i32>
862-
123..124 'S': extern "rust-call" S<i32>() -> S<i32>
862+
123..124 'S': fn S<i32>() -> S<i32>
863863
123..126 'S()': S<i32>
864864
132..133 's': S<i32>
865865
132..144 's.g(|_x| {})': ()
@@ -1616,7 +1616,7 @@ fn main() {
16161616
37..48 'S(.., a, b)': S
16171617
43..44 'a': usize
16181618
46..47 'b': {unknown}
1619-
51..52 'S': extern "rust-call" S(usize) -> S
1619+
51..52 'S': fn S(usize) -> S
16201620
51..55 'S(1)': S
16211621
53..54 '1': usize
16221622
65..75 '(.., a, b)': (i32, {unknown})

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

+25-25
Original file line numberDiff line numberDiff line change
@@ -236,14 +236,14 @@ fn test() {
236236
expect![[r#"
237237
71..153 '{ ...a.c; }': ()
238238
81..82 'c': C
239-
85..86 'C': extern "rust-call" C(usize) -> C
239+
85..86 'C': fn C(usize) -> C
240240
85..89 'C(1)': C
241241
87..88 '1': usize
242242
95..96 'B': B
243243
106..107 'a': A
244244
113..132 'A { b:...C(1) }': A
245245
120..121 'B': B
246-
126..127 'C': extern "rust-call" C(usize) -> C
246+
126..127 'C': fn C(usize) -> C
247247
126..130 'C(1)': C
248248
128..129 '1': usize
249249
138..139 'a': A
@@ -629,12 +629,12 @@ impl E {
629629
86..107 '{ ... }': ()
630630
96..100 'Self': S1
631631
134..158 '{ ... }': ()
632-
144..148 'Self': extern "rust-call" S2(isize) -> S2
632+
144..148 'Self': fn S2(isize) -> S2
633633
144..151 'Self(1)': S2
634634
149..150 '1': isize
635635
184..230 '{ ... }': ()
636636
194..202 'Self::V1': E
637-
212..220 'Self::V2': extern "rust-call" 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
"#]],
@@ -860,11 +860,11 @@ fn test() {
860860
256..277 'A::foo...42))))': &'? i32
861861
263..276 '&&B(B(A(42)))': &'? &'? B<B<A<i32>>>
862862
264..276 '&B(B(A(42)))': &'? B<B<A<i32>>>
863-
265..266 'B': extern "rust-call" B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
863+
265..266 'B': fn B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
864864
265..276 'B(B(A(42)))': B<B<A<i32>>>
865-
267..268 'B': extern "rust-call" B<A<i32>>(A<i32>) -> B<A<i32>>
865+
267..268 'B': fn B<A<i32>>(A<i32>) -> B<A<i32>>
866866
267..275 'B(A(42))': B<A<i32>>
867-
269..270 'A': extern "rust-call" A<i32>(i32) -> A<i32>
867+
269..270 'A': fn A<i32>(i32) -> A<i32>
868868
269..274 'A(42)': A<i32>
869869
271..273 '42': i32
870870
"#]],
@@ -914,16 +914,16 @@ fn test(a: A<i32>) {
914914
253..254 'a': A<i32>
915915
264..310 '{ ...))); }': ()
916916
274..275 't': &'? i32
917-
278..279 'A': extern "rust-call" A<i32>(*mut i32) -> A<i32>
917+
278..279 'A': fn A<i32>(*mut i32) -> A<i32>
918918
278..292 'A(0 as *mut _)': A<i32>
919919
278..307 'A(0 as...B(a)))': &'? i32
920920
280..281 '0': usize
921921
280..291 '0 as *mut _': *mut i32
922922
297..306 '&&B(B(a))': &'? &'? B<B<A<i32>>>
923923
298..306 '&B(B(a))': &'? B<B<A<i32>>>
924-
299..300 'B': extern "rust-call" B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
924+
299..300 'B': fn B<B<A<i32>>>(B<A<i32>>) -> B<B<A<i32>>>
925925
299..306 'B(B(a))': B<B<A<i32>>>
926-
301..302 'B': extern "rust-call" B<A<i32>>(A<i32>) -> B<A<i32>>
926+
301..302 'B': fn B<A<i32>>(A<i32>) -> B<A<i32>>
927927
301..305 'B(a)': B<A<i32>>
928928
303..304 'a': A<i32>
929929
"#]],
@@ -1277,16 +1277,16 @@ fn infer_tuple_struct_generics() {
12771277
"#,
12781278
expect![[r#"
12791279
75..183 '{ ...one; }': ()
1280-
81..82 'A': extern "rust-call" A<i32>(i32) -> A<i32>
1280+
81..82 'A': fn A<i32>(i32) -> A<i32>
12811281
81..86 'A(42)': A<i32>
12821282
83..85 '42': i32
1283-
92..93 'A': extern "rust-call" A<u128>(u128) -> A<u128>
1283+
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': extern "rust-call" 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': extern "rust-call" 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': extern "rust-call" 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': extern "rust-call" Err<(), ()>(()) -> Result<(), ()>
2194+
132..135 'Err': fn Err<(), ()>(()) -> Result<(), ()>
21952195
132..139 'Err(())': Result<(), ()>
21962196
136..138 '()': ()
2197-
149..151 'Ok': extern "rust-call" 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': extern "rust-call" Err<(), ()>(()) -> Result<(), ()>
2205+
198..201 'Err': fn Err<(), ()>(()) -> Result<(), ()>
22062206
198..205 'Err(())': Result<(), ()>
22072207
202..204 '()': ()
2208-
215..217 'Ok': extern "rust-call" 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': extern "rust-call" 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': extern "rust-call" 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': extern "rust-call" 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': extern "rust-call" 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
@@ -3087,9 +3087,9 @@ fn main() {
30873087
322..324 '{}': Foo<T>
30883088
338..559 '{ ...r(); }': ()
30893089
348..353 'boxed': Box<Foo<i32>>
3090-
356..359 'Box': extern "rust-call" Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
3090+
356..359 'Box': fn Box<Foo<i32>>(Foo<i32>) -> Box<Foo<i32>>
30913091
356..371 'Box(Foo(0_i32))': Box<Foo<i32>>
3092-
360..363 'Foo': extern "rust-call" Foo<i32>(i32) -> Foo<i32>
3092+
360..363 'Foo': fn Foo<i32>(i32) -> Foo<i32>
30933093
360..370 'Foo(0_i32)': Foo<i32>
30943094
364..369 '0_i32': i32
30953095
382..386 'bad1': &'? i32

0 commit comments

Comments
 (0)