mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 15:15:24 +00:00
Formatting
This commit is contained in:
parent
d3a252b559
commit
dffe318701
1 changed files with 20 additions and 10 deletions
|
@ -9,7 +9,10 @@ use crate::{MacroRulesError, Result};
|
||||||
use crate::tt_cursor::TtCursor;
|
use crate::tt_cursor::TtCursor;
|
||||||
|
|
||||||
pub(crate) fn expand(rules: &crate::MacroRules, input: &tt::Subtree) -> Result<tt::Subtree> {
|
pub(crate) fn expand(rules: &crate::MacroRules, input: &tt::Subtree) -> Result<tt::Subtree> {
|
||||||
rules.rules.iter().find_map(|it| expand_rule(it, input).ok())
|
rules
|
||||||
|
.rules
|
||||||
|
.iter()
|
||||||
|
.find_map(|it| expand_rule(it, input).ok())
|
||||||
.ok_or(MacroRulesError::NoMatchingRule)
|
.ok_or(MacroRulesError::NoMatchingRule)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,21 +83,24 @@ enum Binding {
|
||||||
|
|
||||||
impl Bindings {
|
impl Bindings {
|
||||||
fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree> {
|
fn get(&self, name: &SmolStr, nesting: &[usize]) -> Result<&tt::TokenTree> {
|
||||||
let mut b = self.inner.get(name).ok_or(MacroRulesError::BindingError(
|
let mut b = self
|
||||||
format!("could not find binding {}", name)
|
.inner
|
||||||
))?;
|
.get(name)
|
||||||
|
.ok_or(MacroRulesError::BindingError(format!("could not find binding {}", name)))?;
|
||||||
for &idx in nesting.iter() {
|
for &idx in nesting.iter() {
|
||||||
b = match b {
|
b = match b {
|
||||||
Binding::Simple(_) => break,
|
Binding::Simple(_) => break,
|
||||||
Binding::Nested(bs) => bs.get(idx).ok_or(MacroRulesError::BindingError(
|
Binding::Nested(bs) => bs.get(idx).ok_or(MacroRulesError::BindingError(
|
||||||
format!("could not find nested binding {}", name))
|
format!("could not find nested binding {}", name),
|
||||||
)?,
|
))?,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
match b {
|
match b {
|
||||||
Binding::Simple(it) => Ok(it),
|
Binding::Simple(it) => Ok(it),
|
||||||
Binding::Nested(_) => Err(MacroRulesError::BindingError(
|
Binding::Nested(_) => Err(MacroRulesError::BindingError(format!(
|
||||||
format!("expected simple binding, found nested binding {}", name))),
|
"expected simple binding, found nested binding {}",
|
||||||
|
name
|
||||||
|
))),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,8 +111,12 @@ impl Bindings {
|
||||||
}
|
}
|
||||||
match self.inner.get_mut(&key) {
|
match self.inner.get_mut(&key) {
|
||||||
Some(Binding::Nested(it)) => it.push(value),
|
Some(Binding::Nested(it)) => it.push(value),
|
||||||
_ => return Err(MacroRulesError::BindingError(
|
_ => {
|
||||||
format!("nested binding for {} not found", key))),
|
return Err(MacroRulesError::BindingError(format!(
|
||||||
|
"nested binding for {} not found",
|
||||||
|
key
|
||||||
|
)))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue