aboutsummaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-01-09 16:15:32 +0000
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-01-09 16:15:32 +0000
commitc2b8aa1ce5e5398d981387079e86ff67a5b7e8c0 (patch)
tree790d941add3eb804b3b4bfbc570a4e8287127273 /crates
parentecfa68a3f50c2e305d2fcd7be09cde729147e023 (diff)
parente8815b614e4a02f9270245f2d5c557999b58239d (diff)
Merge #476
476: nicer trailing comma handling in types r=matklad a=matklad Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates')
-rw-r--r--crates/ra_hir/Cargo.toml1
-rw-r--r--crates/ra_hir/src/ty.rs22
-rw-r--r--crates/ra_hir/src/ty/tests/data/backwards.txt2
-rw-r--r--crates/ra_hir/src/ty/tests/data/binary_op.txt2
4 files changed, 16 insertions, 11 deletions
diff --git a/crates/ra_hir/Cargo.toml b/crates/ra_hir/Cargo.toml
index 5a8fdbfc6..0135e0e16 100644
--- a/crates/ra_hir/Cargo.toml
+++ b/crates/ra_hir/Cargo.toml
@@ -12,6 +12,7 @@ salsa = "0.9.1"
12rustc-hash = "1.0" 12rustc-hash = "1.0"
13parking_lot = "0.7.0" 13parking_lot = "0.7.0"
14ena = "0.11" 14ena = "0.11"
15join_to_string = "0.1.3"
15ra_syntax = { path = "../ra_syntax" } 16ra_syntax = { path = "../ra_syntax" }
16ra_arena = { path = "../ra_arena" } 17ra_arena = { path = "../ra_arena" }
17ra_db = { path = "../ra_db" } 18ra_db = { path = "../ra_db" }
diff --git a/crates/ra_hir/src/ty.rs b/crates/ra_hir/src/ty.rs
index 3b2bfd67a..eb7764f65 100644
--- a/crates/ra_hir/src/ty.rs
+++ b/crates/ra_hir/src/ty.rs
@@ -25,6 +25,7 @@ use std::{fmt, mem};
25use log; 25use log;
26use ena::unify::{InPlaceUnificationTable, UnifyKey, UnifyValue, NoError}; 26use ena::unify::{InPlaceUnificationTable, UnifyKey, UnifyValue, NoError};
27use ra_arena::map::ArenaMap; 27use ra_arena::map::ArenaMap;
28use join_to_string::join;
28 29
29use ra_db::Cancelable; 30use ra_db::Cancelable;
30 31
@@ -396,18 +397,21 @@ impl fmt::Display for Ty {
396 Ty::Ref(t, m) => write!(f, "&{}{}", m.as_keyword_for_ref(), t), 397 Ty::Ref(t, m) => write!(f, "&{}{}", m.as_keyword_for_ref(), t),
397 Ty::Never => write!(f, "!"), 398 Ty::Never => write!(f, "!"),
398 Ty::Tuple(ts) => { 399 Ty::Tuple(ts) => {
399 write!(f, "(")?; 400 if ts.len() == 1 {
400 for t in ts.iter() { 401 write!(f, "({},)", ts[0])
401 write!(f, "{},", t)?; 402 } else {
403 join(ts.iter())
404 .surround_with("(", ")")
405 .separator(", ")
406 .to_fmt(f)
402 } 407 }
403 write!(f, ")")
404 } 408 }
405 Ty::FnPtr(sig) => { 409 Ty::FnPtr(sig) => {
406 write!(f, "fn(")?; 410 join(sig.input.iter())
407 for t in &sig.input { 411 .surround_with("fn(", ")")
408 write!(f, "{},", t)?; 412 .separator(", ")
409 } 413 .to_fmt(f)?;
410 write!(f, ") -> {}", sig.output) 414 write!(f, " -> {}", sig.output)
411 } 415 }
412 Ty::Adt { name, .. } => write!(f, "{}", name), 416 Ty::Adt { name, .. } => write!(f, "{}", name),
413 Ty::Unknown => write!(f, "[unknown]"), 417 Ty::Unknown => write!(f, "[unknown]"),
diff --git a/crates/ra_hir/src/ty/tests/data/backwards.txt b/crates/ra_hir/src/ty/tests/data/backwards.txt
index b6807fb2a..b8593cfd1 100644
--- a/crates/ra_hir/src/ty/tests/data/backwards.txt
+++ b/crates/ra_hir/src/ty/tests/data/backwards.txt
@@ -4,7 +4,7 @@
4[88; 89) 'a': u32 4[88; 89) 'a': u32
5[92; 108) 'unknow...nction': [unknown] 5[92; 108) 'unknow...nction': [unknown]
6[92; 110) 'unknow...tion()': u32 6[92; 110) 'unknow...tion()': u32
7[116; 125) 'takes_u32': fn(u32,) -> () 7[116; 125) 'takes_u32': fn(u32) -> ()
8[116; 128) 'takes_u32(a)': () 8[116; 128) 'takes_u32(a)': ()
9[126; 127) 'a': u32 9[126; 127) 'a': u32
10[138; 139) 'b': i32 10[138; 139) 'b': i32
diff --git a/crates/ra_hir/src/ty/tests/data/binary_op.txt b/crates/ra_hir/src/ty/tests/data/binary_op.txt
index 0fb9dc097..8a515ac5e 100644
--- a/crates/ra_hir/src/ty/tests/data/binary_op.txt
+++ b/crates/ra_hir/src/ty/tests/data/binary_op.txt
@@ -22,7 +22,7 @@
22[166; 188) 'minus_...ONST_2': bool 22[166; 188) 'minus_...ONST_2': bool
23[181; 188) 'CONST_2': isize 23[181; 188) 'CONST_2': isize
24[198; 199) 'c': i32 24[198; 199) 'c': i32
25[202; 203) 'f': fn(bool,) -> i32 25[202; 203) 'f': fn(bool) -> i32
26[202; 211) 'f(z || y)': i32 26[202; 211) 'f(z || y)': i32
27[202; 215) 'f(z || y) + 5': i32 27[202; 215) 'f(z || y) + 5': i32
28[204; 205) 'z': bool 28[204; 205) 'z': bool