diff options
Diffstat (limited to 'crates/ra_hir')
-rw-r--r-- | crates/ra_hir/Cargo.toml | 1 | ||||
-rw-r--r-- | crates/ra_hir/src/ty.rs | 22 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/backwards.txt | 2 | ||||
-rw-r--r-- | crates/ra_hir/src/ty/tests/data/binary_op.txt | 2 |
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" | |||
12 | rustc-hash = "1.0" | 12 | rustc-hash = "1.0" |
13 | parking_lot = "0.7.0" | 13 | parking_lot = "0.7.0" |
14 | ena = "0.11" | 14 | ena = "0.11" |
15 | join_to_string = "0.1.3" | ||
15 | ra_syntax = { path = "../ra_syntax" } | 16 | ra_syntax = { path = "../ra_syntax" } |
16 | ra_arena = { path = "../ra_arena" } | 17 | ra_arena = { path = "../ra_arena" } |
17 | ra_db = { path = "../ra_db" } | 18 | ra_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}; | |||
25 | use log; | 25 | use log; |
26 | use ena::unify::{InPlaceUnificationTable, UnifyKey, UnifyValue, NoError}; | 26 | use ena::unify::{InPlaceUnificationTable, UnifyKey, UnifyValue, NoError}; |
27 | use ra_arena::map::ArenaMap; | 27 | use ra_arena::map::ArenaMap; |
28 | use join_to_string::join; | ||
28 | 29 | ||
29 | use ra_db::Cancelable; | 30 | use 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 |