diff options
Diffstat (limited to 'crates/ra_mbe')
-rw-r--r-- | crates/ra_mbe/src/mbe_expander.rs | 14 | ||||
-rw-r--r-- | crates/ra_mbe/src/mbe_parser.rs | 4 |
2 files changed, 8 insertions, 10 deletions
diff --git a/crates/ra_mbe/src/mbe_expander.rs b/crates/ra_mbe/src/mbe_expander.rs index 7cfb47f7a..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 `{}`", |
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 | } |