Remove span generics from most of the mbe crate

This commit is contained in:
Lukas Wirth 2024-03-19 17:06:50 +01:00
parent 255a8aef92
commit 7e88fa5d3a
8 changed files with 187 additions and 228 deletions

View file

@ -6,20 +6,20 @@ mod matcher;
mod transcriber;
use rustc_hash::FxHashMap;
use span::Span;
use syntax::SmolStr;
use tt::Span;
use crate::{parser::MetaVarKind, ExpandError, ExpandResult};
pub(crate) fn expand_rules<S: Span>(
rules: &[crate::Rule<S>],
input: &tt::Subtree<S>,
marker: impl Fn(&mut S) + Copy,
pub(crate) fn expand_rules(
rules: &[crate::Rule],
input: &tt::Subtree<Span>,
marker: impl Fn(&mut Span) + Copy,
is_2021: bool,
new_meta_vars: bool,
call_site: S,
) -> ExpandResult<tt::Subtree<S>> {
let mut match_: Option<(matcher::Match<S>, &crate::Rule<S>)> = None;
call_site: Span,
) -> ExpandResult<tt::Subtree<Span>> {
let mut match_: Option<(matcher::Match, &crate::Rule)> = None;
for rule in rules {
let new_match = matcher::match_(&rule.lhs, input, is_2021);
@ -110,30 +110,24 @@ pub(crate) fn expand_rules<S: Span>(
/// In other words, `Bindings` is a *multi* mapping from `SmolStr` to
/// `tt::TokenTree`, where the index to select a particular `TokenTree` among
/// many is not a plain `usize`, but a `&[usize]`.
#[derive(Debug, Clone, PartialEq, Eq)]
struct Bindings<S> {
inner: FxHashMap<SmolStr, Binding<S>>,
}
impl<S> Default for Bindings<S> {
fn default() -> Self {
Self { inner: Default::default() }
}
#[derive(Debug, Default, Clone, PartialEq, Eq)]
struct Bindings {
inner: FxHashMap<SmolStr, Binding>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
enum Binding<S> {
Fragment(Fragment<S>),
Nested(Vec<Binding<S>>),
enum Binding {
Fragment(Fragment),
Nested(Vec<Binding>),
Empty,
Missing(MetaVarKind),
}
#[derive(Debug, Clone, PartialEq, Eq)]
enum Fragment<S> {
enum Fragment {
Empty,
/// token fragments are just copy-pasted into the output
Tokens(tt::TokenTree<S>),
Tokens(tt::TokenTree<Span>),
/// Expr ast fragments are surrounded with `()` on insertion to preserve
/// precedence. Note that this impl is different from the one currently in
/// `rustc` -- `rustc` doesn't translate fragments into token trees at all.
@ -141,7 +135,7 @@ enum Fragment<S> {
/// At one point in time, we tried to use "fake" delimiters here à la
/// proc-macro delimiter=none. As we later discovered, "none" delimiters are
/// tricky to handle in the parser, and rustc doesn't handle those either.
Expr(tt::Subtree<S>),
Expr(tt::Subtree<Span>),
/// There are roughly two types of paths: paths in expression context, where a
/// separator `::` between an identifier and its following generic argument list
/// is mandatory, and paths in type context, where `::` can be omitted.
@ -151,5 +145,5 @@ enum Fragment<S> {
/// and is trasncribed as an expression-context path, verbatim transcription
/// would cause a syntax error. We need to fix it up just before transcribing;
/// see `transcriber::fix_up_and_push_path_tt()`.
Path(tt::Subtree<S>),
Path(tt::Subtree<Span>),
}