aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_mbe
diff options
context:
space:
mode:
authorbors[bot] <bors[bot]@users.noreply.github.com>2019-06-04 23:14:46 +0100
committerbors[bot] <bors[bot]@users.noreply.github.com>2019-06-04 23:14:46 +0100
commit5deb907b4321d8328978d3322b0826b781814452 (patch)
tree2baa3b75b1ef62c02617c37ba9b800c41a3dd102 /crates/ra_mbe
parent8bd0e844247dc28d6ceb24b00f3cc3396bd5bf03 (diff)
parentaa30c4909ebb1e85f1591f465c9e2875aa4d394e (diff)
Merge #1374
1374: Implement `cargo lint` and fix some clippy errors r=alanhdu a=alanhdu This creates a `cargo lint` command that runs clippy with certain lints disabled. I've also gone ahead and fixed some of the lint errors, although there are many more still to go. cc #848 Co-authored-by: Alan Du <[email protected]>
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r--crates/ra_mbe/src/mbe_expander.rs38
-rw-r--r--crates/ra_mbe/src/mbe_parser.rs4
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs9
3 files changed, 25 insertions, 26 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs
index a0bd0c5f8..55a6ecf58 100644
--- a/crates/ra_mbe/src/mbe_expander.rs
+++ b/crates/ra_mbe/src/mbe_expander.rs
@@ -105,17 +105,15 @@ impl Bindings {
105 } 105 }
106 106
107 fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree, ExpandError> { 107 fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree, ExpandError> {
108 let mut b = self 108 let mut b = self.inner.get(name).ok_or_else(|| {
109 .inner 109 ExpandError::BindingError(format!("could not find binding `{}`", name))
110 .get(name) 110 })?;
111 .ok_or(ExpandError::BindingError(format!("could not find binding `{}`", name)))?;
112 for &idx in nesting.iter() { 111 for &idx in nesting.iter() {
113 b = match b { 112 b = match b {
114 Binding::Simple(_) => break, 113 Binding::Simple(_) => break,
115 Binding::Nested(bs) => bs.get(idx).ok_or(ExpandError::BindingError(format!( 114 Binding::Nested(bs) => bs.get(idx).ok_or_else(|| {
116 "could not find nested binding `{}`", 115 ExpandError::BindingError(format!("could not find nested binding `{}`", name))
117 name 116 })?,
118 )))?,
119 Binding::Empty => { 117 Binding::Empty => {
120 return Err(ExpandError::BindingError(format!( 118 return Err(ExpandError::BindingError(format!(
121 "could not find empty binding `{}`", 119 "could not find empty binding `{}`",
@@ -206,48 +204,48 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
206 "path" => { 204 "path" => {
207 let path = 205 let path =
208 input.eat_path().ok_or(ExpandError::UnexpectedToken)?.clone(); 206 input.eat_path().ok_or(ExpandError::UnexpectedToken)?.clone();
209 res.inner.insert(text.clone(), Binding::Simple(path.into())); 207 res.inner.insert(text.clone(), Binding::Simple(path));
210 } 208 }
211 "expr" => { 209 "expr" => {
212 let expr = 210 let expr =
213 input.eat_expr().ok_or(ExpandError::UnexpectedToken)?.clone(); 211 input.eat_expr().ok_or(ExpandError::UnexpectedToken)?.clone();
214 res.inner.insert(text.clone(), Binding::Simple(expr.into())); 212 res.inner.insert(text.clone(), Binding::Simple(expr));
215 } 213 }
216 "ty" => { 214 "ty" => {
217 let ty = input.eat_ty().ok_or(ExpandError::UnexpectedToken)?.clone(); 215 let ty = input.eat_ty().ok_or(ExpandError::UnexpectedToken)?.clone();
218 res.inner.insert(text.clone(), Binding::Simple(ty.into())); 216 res.inner.insert(text.clone(), Binding::Simple(ty));
219 } 217 }
220 "pat" => { 218 "pat" => {
221 let pat = input.eat_pat().ok_or(ExpandError::UnexpectedToken)?.clone(); 219 let pat = input.eat_pat().ok_or(ExpandError::UnexpectedToken)?.clone();
222 res.inner.insert(text.clone(), Binding::Simple(pat.into())); 220 res.inner.insert(text.clone(), Binding::Simple(pat));
223 } 221 }
224 "stmt" => { 222 "stmt" => {
225 let pat = input.eat_stmt().ok_or(ExpandError::UnexpectedToken)?.clone(); 223 let pat = input.eat_stmt().ok_or(ExpandError::UnexpectedToken)?.clone();
226 res.inner.insert(text.clone(), Binding::Simple(pat.into())); 224 res.inner.insert(text.clone(), Binding::Simple(pat));
227 } 225 }
228 "block" => { 226 "block" => {
229 let block = 227 let block =
230 input.eat_block().ok_or(ExpandError::UnexpectedToken)?.clone(); 228 input.eat_block().ok_or(ExpandError::UnexpectedToken)?.clone();
231 res.inner.insert(text.clone(), Binding::Simple(block.into())); 229 res.inner.insert(text.clone(), Binding::Simple(block));
232 } 230 }
233 "meta" => { 231 "meta" => {
234 let meta = 232 let meta =
235 input.eat_meta().ok_or(ExpandError::UnexpectedToken)?.clone(); 233 input.eat_meta().ok_or(ExpandError::UnexpectedToken)?.clone();
236 res.inner.insert(text.clone(), Binding::Simple(meta.into())); 234 res.inner.insert(text.clone(), Binding::Simple(meta));
237 } 235 }
238 "tt" => { 236 "tt" => {
239 let token = input.eat().ok_or(ExpandError::UnexpectedToken)?.clone(); 237 let token = input.eat().ok_or(ExpandError::UnexpectedToken)?.clone();
240 res.inner.insert(text.clone(), Binding::Simple(token.into())); 238 res.inner.insert(text.clone(), Binding::Simple(token));
241 } 239 }
242 "item" => { 240 "item" => {
243 let item = 241 let item =
244 input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone(); 242 input.eat_item().ok_or(ExpandError::UnexpectedToken)?.clone();
245 res.inner.insert(text.clone(), Binding::Simple(item.into())); 243 res.inner.insert(text.clone(), Binding::Simple(item));
246 } 244 }
247 "lifetime" => { 245 "lifetime" => {
248 let lifetime = 246 let lifetime =
249 input.eat_lifetime().ok_or(ExpandError::UnexpectedToken)?.clone(); 247 input.eat_lifetime().ok_or(ExpandError::UnexpectedToken)?.clone();
250 res.inner.insert(text.clone(), Binding::Simple(lifetime.into())); 248 res.inner.insert(text.clone(), Binding::Simple(lifetime));
251 } 249 }
252 "literal" => { 250 "literal" => {
253 let literal = 251 let literal =
@@ -262,7 +260,7 @@ fn match_lhs(pattern: &crate::Subtree, input: &mut TtCursor) -> Result<Bindings,
262 // `vis` is optional 260 // `vis` is optional
263 if let Some(vis) = input.try_eat_vis() { 261 if let Some(vis) = input.try_eat_vis() {
264 let vis = vis.clone(); 262 let vis = vis.clone();
265 res.inner.insert(text.clone(), Binding::Simple(vis.into())); 263 res.inner.insert(text.clone(), Binding::Simple(vis));
266 } else { 264 } else {
267 res.push_optional(&text); 265 res.push_optional(&text);
268 } 266 }
@@ -452,7 +450,7 @@ fn expand_tt(
452 450
453 let idx = ctx.nesting.pop().unwrap(); 451 let idx = ctx.nesting.pop().unwrap();
454 ctx.nesting.push(idx + 1); 452 ctx.nesting.push(idx + 1);
455 token_trees.push(reduce_single_token(t).into()); 453 token_trees.push(reduce_single_token(t));
456 454
457 if let Some(ref sep) = repeat.separator { 455 if let Some(ref sep) = repeat.separator {
458 match sep { 456 match sep {
diff --git a/crates/ra_mbe/src/mbe_parser.rs b/crates/ra_mbe/src/mbe_parser.rs
index d8fe293c7..dca16b537 100644
--- a/crates/ra_mbe/src/mbe_parser.rs
+++ b/crates/ra_mbe/src/mbe_parser.rs
@@ -125,8 +125,8 @@ fn parse_repeat(p: &mut TtCursor, transcriber: bool) -> Result<crate::Repeat, Pa
125 } 125 }
126 } 126 }
127 127
128 let sep = p.eat_seperator().ok_or(ParseError::Expected(String::from("separator")))?; 128 let sep = p.eat_seperator().ok_or_else(|| ParseError::Expected(String::from("separator")))?;
129 let rep = p.eat_punct().ok_or(ParseError::Expected(String::from("repeat")))?; 129 let rep = p.eat_punct().ok_or_else(|| ParseError::Expected(String::from("repeat")))?;
130 130
131 mk_repeat(rep.char, subtree, Some(sep)) 131 mk_repeat(rep.char, subtree, Some(sep))
132} 132}
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 0edb6f9a2..9d3d2ad5b 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -155,9 +155,10 @@ fn convert_doc_comment<'a>(token: &ra_syntax::SyntaxToken<'a>) -> Option<Vec<tt:
155 if let ast::CommentPlacement::Inner = doc { 155 if let ast::CommentPlacement::Inner = doc {
156 token_trees.push(mk_punct('!')); 156 token_trees.push(mk_punct('!'));
157 } 157 }
158 token_trees.push(tt::TokenTree::from(tt::Subtree::from( 158 token_trees.push(tt::TokenTree::from(tt::Subtree {
159 tt::Subtree { delimiter: tt::Delimiter::Bracket, token_trees: meta_tkns }.into(), 159 delimiter: tt::Delimiter::Bracket,
160 ))); 160 token_trees: meta_tkns,
161 }));
161 162
162 return Some(token_trees); 163 return Some(token_trees);
163 164
@@ -292,7 +293,7 @@ fn delim_to_str(d: tt::Delimiter, closing: bool) -> SmolStr {
292 }; 293 };
293 294
294 let idx = closing as usize; 295 let idx = closing as usize;
295 let text = if texts.len() > 0 { &texts[idx..texts.len() - (1 - idx)] } else { "" }; 296 let text = if !texts.is_empty() { &texts[idx..texts.len() - (1 - idx)] } else { "" };
296 text.into() 297 text.into()
297} 298}
298 299