mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Change Option<u32> to u32 for shift value
This commit is contained in:
parent
63e42bb5bd
commit
42661a3b27
1 changed files with 5 additions and 8 deletions
|
@ -43,7 +43,7 @@ pub use crate::syntax_bridge::{
|
|||
pub struct MacroRules {
|
||||
pub(crate) rules: Vec<Rule>,
|
||||
/// Highest id of the token we have in TokenMap
|
||||
pub(crate) shift: Option<u32>,
|
||||
pub(crate) shift: u32,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -53,14 +53,14 @@ pub(crate) struct Rule {
|
|||
}
|
||||
|
||||
/// Find the "shift" (the highest id of the TokenId) inside a subtree
|
||||
fn find_subtree_shift(tt: &tt::Subtree, mut cur: Option<u32>) -> Option<u32> {
|
||||
fn find_subtree_shift(tt: &tt::Subtree, mut cur: u32) -> u32 {
|
||||
use std::cmp::max;
|
||||
|
||||
for t in &tt.token_trees {
|
||||
cur = match t {
|
||||
tt::TokenTree::Leaf(leaf) => match leaf {
|
||||
tt::Leaf::Ident(ident) if ident.id != tt::TokenId::unspecified() => {
|
||||
Some(max(cur.unwrap_or(0), ident.id.0))
|
||||
max(cur, ident.id.0)
|
||||
}
|
||||
_ => cur,
|
||||
},
|
||||
|
@ -110,16 +110,13 @@ impl MacroRules {
|
|||
validate(&rule.lhs)?;
|
||||
}
|
||||
|
||||
Ok(MacroRules { rules, shift: find_subtree_shift(tt, None) })
|
||||
Ok(MacroRules { rules, shift: find_subtree_shift(tt, 0) })
|
||||
}
|
||||
|
||||
pub fn expand(&self, tt: &tt::Subtree) -> Result<tt::Subtree, ExpandError> {
|
||||
// apply shift
|
||||
let mut tt = tt.clone();
|
||||
if let Some(shift) = self.shift {
|
||||
shift_subtree(&mut tt, shift)
|
||||
}
|
||||
|
||||
shift_subtree(&mut tt, self.shift);
|
||||
mbe_expander::expand(self, &tt)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue