Skip to content

Commit 4135696

Browse files
committed
Cleanup
1 parent 6bfdd38 commit 4135696

4 files changed

Lines changed: 11 additions & 6 deletions

File tree

‎crates/hir-expand/src/db.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
use base_db::{salsa,CrateId,FileId,SourceDatabase};
44
use either::Either;
55
use limit::Limit;
6-
use mbe::syntax_node_to_token_tree;
6+
use mbe::{syntax_node_to_token_tree,MatchedArmIndex};
77
use rustc_hash::FxHashSet;
88
use span::{AstIdMap,Span,SyntaxContextData,SyntaxContextId};
99
use syntax::{ast,AstNode,Parse,SyntaxElement,SyntaxError,SyntaxNode,SyntaxToken,T};
@@ -546,7 +546,7 @@ fn macro_expand(
546546
db:&dynExpandDatabase,
547547
macro_call_id:MacroCallId,
548548
loc:MacroCallLoc,
549-
) -> ExpandResult<(CowArc<tt::Subtree>,Option<u32>)>{
549+
) -> ExpandResult<(CowArc<tt::Subtree>,MatchedArmIndex)>{
550550
let _p = tracing::span!(tracing::Level::INFO,"macro_expand").entered();
551551

552552
let(ExpandResult{value:(tt, matched_arm), err }, span) = match loc.def.kind{

‎crates/mbe/src/expander.rs‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use rustc_hash::FxHashMap;
99
use span::{Edition,Span};
1010
use syntax::SmolStr;
1111

12-
usecrate::{parser::MetaVarKind,ExpandError,ExpandResult};
12+
usecrate::{parser::MetaVarKind,ExpandError,ExpandResult,MatchedArmIndex};
1313

1414
pub(crate)fnexpand_rules(
1515
rules:&[crate::Rule],
@@ -18,7 +18,7 @@ pub(crate) fn expand_rules(
1818
new_meta_vars:bool,
1919
call_site:Span,
2020
def_site_edition:Edition,
21-
) -> ExpandResult<(tt::Subtree<Span>,Option<u32>)>{
21+
) -> ExpandResult<(tt::Subtree<Span>,MatchedArmIndex)>{
2222
letmut match_:Option<(matcher::Match,&crate::Rule,usize)> = None;
2323
for(idx, rule)in rules.iter().enumerate(){
2424
let new_match = matcher::match_(&rule.lhs, input, def_site_edition);
@@ -53,7 +53,7 @@ pub(crate) fn expand_rules(
5353
// if we got here, there was no match without errors
5454
letExpandResult{ value,err: transcribe_err } =
5555
transcriber::transcribe(&rule.rhs,&match_.bindings, marker, new_meta_vars, call_site);
56-
ExpandResult{value:(value,Some(idxasu32)),err: match_.err.or(transcribe_err)}
56+
ExpandResult{value:(value, idx.try_into().ok()),err: match_.err.or(transcribe_err)}
5757
}else{
5858
ExpandResult::new(
5959
(

‎crates/mbe/src/lib.rs‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,9 @@ impl fmt::Display for CountError {
122122
}
123123
}
124124

125+
/// Index of the matched macro arm on successful expansion.
126+
pubtypeMatchedArmIndex = Option<u32>;
127+
125128
/// This struct contains AST for a single `macro_rules` definition. What might
126129
/// be very confusing is that AST has almost exactly the same shape as
127130
/// `tt::TokenTree`, but there's a crucial difference: in macro rules, `$ident`
@@ -251,7 +254,7 @@ impl DeclarativeMacro {
251254
new_meta_vars:bool,
252255
call_site:Span,
253256
def_site_edition:Edition,
254-
) -> ExpandResult<(tt::Subtree<Span>,Option<u32>)>{
257+
) -> ExpandResult<(tt::Subtree<Span>,MatchedArmIndex)>{
255258
expander::expand_rules(&self.rules, tt, marker, new_meta_vars, call_site, def_site_edition)
256259
}
257260
}

‎crates/span/src/map.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ use crate::{
1515
#[derive(Debug,PartialEq,Eq,Clone,Hash)]
1616
pubstructSpanMap<S>{
1717
spans:Vec<(TextSize,SpanData<S>)>,
18+
/// Index of the matched macro arm on successful expansion for declarative macros.
19+
// FIXME: Does it make sense to have this here?
1820
pubmatched_arm:Option<u32>,
1921
}
2022

0 commit comments

Comments
 (0)