diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-13 14:02:26 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-13 14:02:26 +0000 |
commit | ebc95af2b5b91239fc1d8a5fc8344ded6f6ef3e4 (patch) | |
tree | fe84a7b9a434cb268faea247d9d6dbffed894696 /crates/ra_tt/src | |
parent | 16cf6bcf4b614a7a1a3a3f3659f7bb3df7cff086 (diff) | |
parent | 98f98cbb5404385703a404547aa2477d4a2fd1cb (diff) |
Merge #2551
2551: Refactor tt::Subtree delimiter r=matklad a=edwin0cheng
Refactor to :
```
#[derive(Debug, Clone, PartialEq, Eq, Hash, Default)]
pub struct Subtree {
pub delimiter: Option<Delimiter>,
pub token_trees: Vec<TokenTree>,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Delimiter {
Parenthesis,
Brace,
Bracket,
}
```
Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_tt/src')
-rw-r--r-- | crates/ra_tt/src/lib.rs | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 4c00b8f30..e7bfd5fd2 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -48,9 +48,9 @@ pub enum Leaf { | |||
48 | } | 48 | } |
49 | impl_froms!(Leaf: Literal, Punct, Ident); | 49 | impl_froms!(Leaf: Literal, Punct, Ident); |
50 | 50 | ||
51 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 51 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] |
52 | pub struct Subtree { | 52 | pub struct Subtree { |
53 | pub delimiter: Delimiter, | 53 | pub delimiter: Option<Delimiter>, |
54 | pub token_trees: Vec<TokenTree>, | 54 | pub token_trees: Vec<TokenTree>, |
55 | } | 55 | } |
56 | 56 | ||
@@ -59,7 +59,6 @@ pub enum Delimiter { | |||
59 | Parenthesis, | 59 | Parenthesis, |
60 | Brace, | 60 | Brace, |
61 | Bracket, | 61 | Bracket, |
62 | None, | ||
63 | } | 62 | } |
64 | 63 | ||
65 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 64 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
@@ -97,10 +96,10 @@ impl fmt::Display for TokenTree { | |||
97 | impl fmt::Display for Subtree { | 96 | impl fmt::Display for Subtree { |
98 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 97 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
99 | let (l, r) = match self.delimiter { | 98 | let (l, r) = match self.delimiter { |
100 | Delimiter::Parenthesis => ("(", ")"), | 99 | Some(Delimiter::Parenthesis) => ("(", ")"), |
101 | Delimiter::Brace => ("{", "}"), | 100 | Some(Delimiter::Brace) => ("{", "}"), |
102 | Delimiter::Bracket => ("[", "]"), | 101 | Some(Delimiter::Bracket) => ("[", "]"), |
103 | Delimiter::None => ("", ""), | 102 | None => ("", ""), |
104 | }; | 103 | }; |
105 | f.write_str(l)?; | 104 | f.write_str(l)?; |
106 | let mut needs_space = false; | 105 | let mut needs_space = false; |