diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-02-18 14:37:34 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2020-02-18 14:37:34 +0000 |
commit | cecf25b72f2af84fc1535cf52d6f3c1b52802565 (patch) | |
tree | 37c8dde0a459caacae6629da08d86be270469ef5 /crates/ra_mbe/src | |
parent | eab80cd961919b9321e1d34343ae3f3adb0502e5 (diff) | |
parent | f6816c253b96e8436f1156d6bd6b0942ee9fb4d3 (diff) |
Merge #3220
3220: Fix clippy warnings, update Cargo.toml versions r=matklad a=SomeoneToIgnore
In the `cargo xtask lint` ouptut, there were two interesting Clippy warnings that might be interesting to investigate further:
* warning: this argument (4 byte) is passed by reference, but would be more efficient if passed by value (limit: 8 byte)
* warning: large size difference between variants
Co-authored-by: Kirill Bulatov <[email protected]>
Diffstat (limited to 'crates/ra_mbe/src')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander/matcher.rs | 2 | ||||
-rw-r--r-- | crates/ra_mbe/src/parser.rs | 29 | ||||
-rw-r--r-- | crates/ra_mbe/src/subtree_source.rs | 2 |
3 files changed, 15 insertions, 18 deletions
diff --git a/crates/ra_mbe/src/mbe_expander/matcher.rs b/crates/ra_mbe/src/mbe_expander/matcher.rs index e36b5a412..2bdea11e1 100644 --- a/crates/ra_mbe/src/mbe_expander/matcher.rs +++ b/crates/ra_mbe/src/mbe_expander/matcher.rs | |||
@@ -101,7 +101,7 @@ fn match_subtree( | |||
101 | tt::Leaf::Literal(tt::Literal { text: lhs, .. }), | 101 | tt::Leaf::Literal(tt::Literal { text: lhs, .. }), |
102 | tt::Leaf::Literal(tt::Literal { text: rhs, .. }), | 102 | tt::Leaf::Literal(tt::Literal { text: rhs, .. }), |
103 | ) if lhs == rhs => (), | 103 | ) if lhs == rhs => (), |
104 | _ => Err(ExpandError::UnexpectedToken)?, | 104 | _ => return Err(ExpandError::UnexpectedToken), |
105 | } | 105 | } |
106 | } | 106 | } |
107 | Op::TokenTree(tt::TokenTree::Subtree(lhs)) => { | 107 | Op::TokenTree(tt::TokenTree::Subtree(lhs)) => { |
diff --git a/crates/ra_mbe/src/parser.rs b/crates/ra_mbe/src/parser.rs index 50b8011a9..10a6f300a 100644 --- a/crates/ra_mbe/src/parser.rs +++ b/crates/ra_mbe/src/parser.rs | |||
@@ -45,15 +45,15 @@ impl PartialEq for Separator { | |||
45 | } | 45 | } |
46 | } | 46 | } |
47 | 47 | ||
48 | pub(crate) fn parse_template<'a>( | 48 | pub(crate) fn parse_template( |
49 | template: &'a tt::Subtree, | 49 | template: &tt::Subtree, |
50 | ) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> { | 50 | ) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> { |
51 | parse_inner(template, Mode::Template) | 51 | parse_inner(template, Mode::Template) |
52 | } | 52 | } |
53 | 53 | ||
54 | pub(crate) fn parse_pattern<'a>( | 54 | pub(crate) fn parse_pattern( |
55 | pattern: &'a tt::Subtree, | 55 | pattern: &tt::Subtree, |
56 | ) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> { | 56 | ) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> { |
57 | parse_inner(pattern, Mode::Pattern) | 57 | parse_inner(pattern, Mode::Pattern) |
58 | } | 58 | } |
59 | 59 | ||
@@ -63,10 +63,7 @@ enum Mode { | |||
63 | Template, | 63 | Template, |
64 | } | 64 | } |
65 | 65 | ||
66 | fn parse_inner<'a>( | 66 | fn parse_inner(src: &tt::Subtree, mode: Mode) -> impl Iterator<Item = Result<Op<'_>, ExpandError>> { |
67 | src: &'a tt::Subtree, | ||
68 | mode: Mode, | ||
69 | ) -> impl Iterator<Item = Result<Op<'a>, ExpandError>> { | ||
70 | let mut src = TtIter::new(src); | 67 | let mut src = TtIter::new(src); |
71 | std::iter::from_fn(move || { | 68 | std::iter::from_fn(move || { |
72 | let first = src.next()?; | 69 | let first = src.next()?; |
@@ -100,7 +97,7 @@ fn next_op<'a>( | |||
100 | Op::Repeat { subtree, separator, kind } | 97 | Op::Repeat { subtree, separator, kind } |
101 | } | 98 | } |
102 | tt::TokenTree::Leaf(leaf) => match leaf { | 99 | tt::TokenTree::Leaf(leaf) => match leaf { |
103 | tt::Leaf::Punct(..) => Err(ExpandError::UnexpectedToken)?, | 100 | tt::Leaf::Punct(..) => return Err(ExpandError::UnexpectedToken), |
104 | tt::Leaf::Ident(ident) => { | 101 | tt::Leaf::Ident(ident) => { |
105 | let name = &ident.text; | 102 | let name = &ident.text; |
106 | let kind = eat_fragment_kind(src, mode)?; | 103 | let kind = eat_fragment_kind(src, mode)?; |
@@ -147,15 +144,15 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), Exp | |||
147 | for tt in src { | 144 | for tt in src { |
148 | let tt = match tt { | 145 | let tt = match tt { |
149 | tt::TokenTree::Leaf(leaf) => leaf, | 146 | tt::TokenTree::Leaf(leaf) => leaf, |
150 | tt::TokenTree::Subtree(_) => Err(ExpandError::InvalidRepeat)?, | 147 | tt::TokenTree::Subtree(_) => return Err(ExpandError::InvalidRepeat), |
151 | }; | 148 | }; |
152 | let has_sep = match &separator { | 149 | let has_sep = match &separator { |
153 | Separator::Puncts(puncts) => puncts.len() != 0, | 150 | Separator::Puncts(puncts) => !puncts.is_empty(), |
154 | _ => true, | 151 | _ => true, |
155 | }; | 152 | }; |
156 | match tt { | 153 | match tt { |
157 | tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => { | 154 | tt::Leaf::Ident(_) | tt::Leaf::Literal(_) if has_sep => { |
158 | Err(ExpandError::InvalidRepeat)? | 155 | return Err(ExpandError::InvalidRepeat) |
159 | } | 156 | } |
160 | tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()), | 157 | tt::Leaf::Ident(ident) => separator = Separator::Ident(ident.clone()), |
161 | tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()), | 158 | tt::Leaf::Literal(lit) => separator = Separator::Literal(lit.clone()), |
@@ -168,11 +165,11 @@ fn parse_repeat(src: &mut TtIter) -> Result<(Option<Separator>, RepeatKind), Exp | |||
168 | match &mut separator { | 165 | match &mut separator { |
169 | Separator::Puncts(puncts) => { | 166 | Separator::Puncts(puncts) => { |
170 | if puncts.len() == 3 { | 167 | if puncts.len() == 3 { |
171 | Err(ExpandError::InvalidRepeat)? | 168 | return Err(ExpandError::InvalidRepeat); |
172 | } | 169 | } |
173 | puncts.push(punct.clone()) | 170 | puncts.push(punct.clone()) |
174 | } | 171 | } |
175 | _ => Err(ExpandError::InvalidRepeat)?, | 172 | _ => return Err(ExpandError::InvalidRepeat), |
176 | } | 173 | } |
177 | continue; | 174 | continue; |
178 | } | 175 | } |
diff --git a/crates/ra_mbe/src/subtree_source.rs b/crates/ra_mbe/src/subtree_source.rs index c9f42b3dd..eb8b79e9a 100644 --- a/crates/ra_mbe/src/subtree_source.rs +++ b/crates/ra_mbe/src/subtree_source.rs | |||
@@ -124,7 +124,7 @@ fn convert_delim(d: Option<tt::DelimiterKind>, closing: bool) -> TtToken { | |||
124 | 124 | ||
125 | let idx = closing as usize; | 125 | let idx = closing as usize; |
126 | let kind = kinds[idx]; | 126 | let kind = kinds[idx]; |
127 | let text = if texts.len() > 0 { &texts[idx..texts.len() - (1 - idx)] } else { "" }; | 127 | let text = if !texts.is_empty() { &texts[idx..texts.len() - (1 - idx)] } else { "" }; |
128 | TtToken { kind, is_joint_to_next: false, text: SmolStr::new(text) } | 128 | TtToken { kind, is_joint_to_next: false, text: SmolStr::new(text) } |
129 | } | 129 | } |
130 | 130 | ||