aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-09 16:14:21 +0000
committerAleksey Kladov <[email protected]>2019-01-09 16:14:21 +0000
commite8815b614e4a02f9270245f2d5c557999b58239d (patch)
tree790d941add3eb804b3b4bfbc570a4e8287127273
parentecfa68a3f50c2e305d2fcd7be09cde729147e023 (diff)
nicer trailing comma handling in types
-rw-r--r--Cargo.lock9
-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
5 files changed, 21 insertions, 15 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 43458f60e..b3172dc28 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -409,7 +409,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
409 409
410[[package]] 410[[package]]
411name = "join_to_string" 411name = "join_to_string"
412version = "0.1.1" 412version = "0.1.3"
413source = "registry+https://github.com/rust-lang/crates.io-index" 413source = "registry+https://github.com/rust-lang/crates.io-index"
414 414
415[[package]] 415[[package]]
@@ -646,7 +646,7 @@ version = "0.1.0"
646dependencies = [ 646dependencies = [
647 "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)", 647 "clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
648 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", 648 "failure 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)",
649 "join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 649 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
650 "ra_ide_api_light 0.1.0", 650 "ra_ide_api_light 0.1.0",
651 "ra_syntax 0.1.0", 651 "ra_syntax 0.1.0",
652 "tools 0.1.0", 652 "tools 0.1.0",
@@ -672,6 +672,7 @@ dependencies = [
672 "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)", 672 "arrayvec 0.4.10 (registry+https://github.com/rust-lang/crates.io-index)",
673 "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)", 673 "ena 0.11.0 (registry+https://github.com/rust-lang/crates.io-index)",
674 "flexi_logger 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)", 674 "flexi_logger 0.10.4 (registry+https://github.com/rust-lang/crates.io-index)",
675 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
675 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", 676 "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
676 "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)", 677 "parking_lot 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)",
677 "ra_arena 0.1.0", 678 "ra_arena 0.1.0",
@@ -709,7 +710,7 @@ name = "ra_ide_api_light"
709version = "0.1.0" 710version = "0.1.0"
710dependencies = [ 711dependencies = [
711 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", 712 "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)",
712 "join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", 713 "join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)",
713 "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)", 714 "proptest 0.8.7 (registry+https://github.com/rust-lang/crates.io-index)",
714 "ra_syntax 0.1.0", 715 "ra_syntax 0.1.0",
715 "ra_text_edit 0.1.0", 716 "ra_text_edit 0.1.0",
@@ -1531,7 +1532,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1531"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" 1532"checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d"
1532"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358" 1533"checksum itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5b8467d9c1cebe26feb08c640139247fac215782d35371ade9a2136ed6085358"
1533"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b" 1534"checksum itoa 0.4.3 (registry+https://github.com/rust-lang/crates.io-index)" = "1306f3464951f30e30d12373d31c79fbd52d236e5e896fd92f96ec7babbbe60b"
1534"checksum join_to_string 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7bddc885f3fd69dd4b5d747c2efe6dd2c36d795ea9938281ed50910e32c95e31" 1535"checksum join_to_string 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "4dc7a5290e8c2606ce2be49f456d50f69173cb96d1541e4f66e34ac8b331a98f"
1535"checksum languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7c01845f71b8b3b3557a8179af4434a4b2570829da12371f05272d28183a06ce" 1536"checksum languageserver-types 0.53.1 (registry+https://github.com/rust-lang/crates.io-index)" = "7c01845f71b8b3b3557a8179af4434a4b2570829da12371f05272d28183a06ce"
1536"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1" 1537"checksum lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a374c89b9db55895453a74c1e38861d9deec0b01b405a82516e9d5de4820dea1"
1537"checksum libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)" = "023a4cd09b2ff695f9734c1934145a315594b7986398496841c7031a5a1bbdbd" 1538"checksum libc 0.2.46 (registry+https://github.com/rust-lang/crates.io-index)" = "023a4cd09b2ff695f9734c1934145a315594b7986398496841c7031a5a1bbdbd"
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