Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 7e88fa5

Browse files
committed
Remove span generics from most of the mbe crate
1 parent 255a8ae commit 7e88fa5

File tree

8 files changed

+187
-228
lines changed

8 files changed

+187
-228
lines changed

crates/hir-expand/src/declarative.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::{
1616
/// Old-style `macro_rules` or the new macros 2.0
1717
#[derive(Debug, Clone, Eq, PartialEq)]
1818
pub struct DeclarativeMacroExpander {
19-
pub mac: mbe::DeclarativeMacro<span::Span>,
19+
pub mac: mbe::DeclarativeMacro,
2020
pub transparency: Transparency,
2121
}
2222

crates/hir-expand/src/lib.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,9 @@ use crate::{
5454

5555
pub use crate::files::{AstId, ErasedAstId, InFile, InMacroFile, InRealFile};
5656

57-
pub use mbe::ValueResult;
57+
pub use mbe::{DeclarativeMacro, ValueResult};
5858
pub use span::{HirFileId, MacroCallId, MacroFileId};
5959

60-
pub type DeclarativeMacro = ::mbe::DeclarativeMacro<tt::Span>;
61-
6260
pub mod tt {
6361
pub use span::Span;
6462
pub use tt::{DelimiterKind, Spacing};

crates/mbe/src/benchmark.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ fn benchmark_expand_macro_rules() {
5151
assert_eq!(hash, 69413);
5252
}
5353

54-
fn macro_rules_fixtures() -> FxHashMap<String, DeclarativeMacro<Span>> {
54+
fn macro_rules_fixtures() -> FxHashMap<String, DeclarativeMacro> {
5555
macro_rules_fixtures_tt()
5656
.into_iter()
5757
.map(|(id, tt)| (id, DeclarativeMacro::parse_macro_rules(&tt, true, true)))
@@ -80,7 +80,7 @@ fn macro_rules_fixtures_tt() -> FxHashMap<String, tt::Subtree<Span>> {
8080

8181
/// Generate random invocation fixtures from rules
8282
fn invocation_fixtures(
83-
rules: &FxHashMap<String, DeclarativeMacro<Span>>,
83+
rules: &FxHashMap<String, DeclarativeMacro>,
8484
) -> Vec<(String, tt::Subtree<Span>)> {
8585
let mut seed = 123456789;
8686
let mut res = Vec::new();
@@ -128,11 +128,7 @@ fn invocation_fixtures(
128128
}
129129
return res;
130130

131-
fn collect_from_op(
132-
op: &Op<Span>,
133-
token_trees: &mut Vec<tt::TokenTree<Span>>,
134-
seed: &mut usize,
135-
) {
131+
fn collect_from_op(op: &Op, token_trees: &mut Vec<tt::TokenTree<Span>>, seed: &mut usize) {
136132
return match op {
137133
Op::Var { kind, .. } => match kind.as_ref() {
138134
Some(MetaVarKind::Ident) => token_trees.push(make_ident("foo")),

crates/mbe/src/expander.rs

Lines changed: 18 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,20 @@ mod matcher;
66
mod transcriber;
77

88
use rustc_hash::FxHashMap;
9+
use span::Span;
910
use syntax::SmolStr;
10-
use tt::Span;
1111

1212
use crate::{parser::MetaVarKind, ExpandError, ExpandResult};
1313

14-
pub(crate) fn expand_rules<S: Span>(
15-
rules: &[crate::Rule<S>],
16-
input: &tt::Subtree<S>,
17-
marker: impl Fn(&mut S) + Copy,
14+
pub(crate) fn expand_rules(
15+
rules: &[crate::Rule],
16+
input: &tt::Subtree<Span>,
17+
marker: impl Fn(&mut Span) + Copy,
1818
is_2021: bool,
1919
new_meta_vars: bool,
20-
call_site: S,
21-
) -> ExpandResult<tt::Subtree<S>> {
22-
let mut match_: Option<(matcher::Match<S>, &crate::Rule<S>)> = None;
20+
call_site: Span,
21+
) -> ExpandResult<tt::Subtree<Span>> {
22+
let mut match_: Option<(matcher::Match, &crate::Rule)> = None;
2323
for rule in rules {
2424
let new_match = matcher::match_(&rule.lhs, input, is_2021);
2525

@@ -110,38 +110,32 @@ pub(crate) fn expand_rules<S: Span>(
110110
/// In other words, `Bindings` is a *multi* mapping from `SmolStr` to
111111
/// `tt::TokenTree`, where the index to select a particular `TokenTree` among
112112
/// many is not a plain `usize`, but a `&[usize]`.
113-
#[derive(Debug, Clone, PartialEq, Eq)]
114-
struct Bindings<S> {
115-
inner: FxHashMap<SmolStr, Binding<S>>,
116-
}
117-
118-
impl<S> Default for Bindings<S> {
119-
fn default() -> Self {
120-
Self { inner: Default::default() }
121-
}
113+
#[derive(Debug, Default, Clone, PartialEq, Eq)]
114+
struct Bindings {
115+
inner: FxHashMap<SmolStr, Binding>,
122116
}
123117

124118
#[derive(Debug, Clone, PartialEq, Eq)]
125-
enum Binding<S> {
126-
Fragment(Fragment<S>),
127-
Nested(Vec<Binding<S>>),
119+
enum Binding {
120+
Fragment(Fragment),
121+
Nested(Vec<Binding>),
128122
Empty,
129123
Missing(MetaVarKind),
130124
}
131125

132126
#[derive(Debug, Clone, PartialEq, Eq)]
133-
enum Fragment<S> {
127+
enum Fragment {
134128
Empty,
135129
/// token fragments are just copy-pasted into the output
136-
Tokens(tt::TokenTree<S>),
130+
Tokens(tt::TokenTree<Span>),
137131
/// Expr ast fragments are surrounded with `()` on insertion to preserve
138132
/// precedence. Note that this impl is different from the one currently in
139133
/// `rustc` -- `rustc` doesn't translate fragments into token trees at all.
140134
///
141135
/// At one point in time, we tried to use "fake" delimiters here à la
142136
/// proc-macro delimiter=none. As we later discovered, "none" delimiters are
143137
/// tricky to handle in the parser, and rustc doesn't handle those either.
144-
Expr(tt::Subtree<S>),
138+
Expr(tt::Subtree<Span>),
145139
/// There are roughly two types of paths: paths in expression context, where a
146140
/// separator `::` between an identifier and its following generic argument list
147141
/// is mandatory, and paths in type context, where `::` can be omitted.
@@ -151,5 +145,5 @@ enum Fragment<S> {
151145
/// and is trasncribed as an expression-context path, verbatim transcription
152146
/// would cause a syntax error. We need to fix it up just before transcribing;
153147
/// see `transcriber::fix_up_and_push_path_tt()`.
154-
Path(tt::Subtree<S>),
148+
Path(tt::Subtree<Span>),
155149
}

0 commit comments

Comments
 (0)