Skip to main content Module transcribe Copy item path Source use std::mem ; π use rustc_ast::token ; π use rustc_ast::token::Delimiter ; π use rustc_ast::token::IdentKind ; π use rustc_ast::token::InvisibleOrigin ; π use rustc_ast::token::Lit ; π use rustc_ast::token::LitKind ; π use rustc_ast::token::MetaVarKind ; π use rustc_ast::token::Token ; π use rustc_ast::token::TokenKind ; π use rustc_ast::tokenstream::DelimSpacing ; π use rustc_ast::tokenstream::DelimSpan ; π use rustc_ast::tokenstream::Spacing ; π use rustc_ast::tokenstream::TokenStream ; π use rustc_ast::tokenstream::TokenTree ; π use rustc_ast::ExprKind ; π use rustc_ast::StmtKind ; π use rustc_ast::TyKind ; π use rustc_ast::UnOp ; π use rustc_data_structures::fx::FxHashMap ; π use rustc_errors::Diag ; π use rustc_errors::DiagCtxtHandle ; π use rustc_errors::PResult ; π use rustc_errors::listify ; π use rustc_errors::pluralize ; π use rustc_parse::lexer::nfc_normalize ; π use rustc_parse::parser::ParseNtResult ; π use rustc_session::parse::ParseSess ; π use rustc_span::hygiene::LocalExpnId ; π use rustc_span::hygiene::Transparency ; π use rustc_span::BytePos ; π use rustc_span::Ident ; π use rustc_span::MacroRulesNormalizedIdent ; π use rustc_span::Span ; π use rustc_span::Symbol ; π use rustc_span::SyntaxContext ; π use rustc_span::kw ; π use rustc_span::sym ; π use rustc_span::with_metavar_spans ; π use smallvec::SmallVec ; π use smallvec::smallvec ; π use crate::diagnostics::ConcatInvalidIdent ; π use crate::diagnostics::CountRepetitionMisplaced ; π use crate::diagnostics::InvalidIdentReason ; π use crate::diagnostics::MacroVarStillRepeating ; π use crate::diagnostics::MetaVarsDifSeqMatchers ; π use crate::diagnostics::MustRepeatOnce ; π use crate::diagnostics::MveUnrecognizedVar ; π use crate::diagnostics::NoRepeatableVar ; π use crate::diagnostics::NoSyntaxVarsExprRepeat ; π use crate::diagnostics::VarNoTypo ; π use crate::diagnostics::VarTypoSuggestionRepeatable ; π use crate::diagnostics::VarTypoSuggestionUnrepeatable ; π use crate::diagnostics::VarTypoSuggestionUnrepeatableLabel ; π use crate::mbe::macro_parser::NamedMatch ; π use crate::mbe::metavar_expr::MetaVarExprConcatElem ; π use crate::mbe::metavar_expr::validate_ident_kind ; π use crate::mbe ; π use crate::mbe::KleeneOp ; π use crate::mbe::MetaVarExpr ; π use crate::mbe::macro_parser::NamedMatch ::*; π Frame π An iterator over the token trees in a delimited token tree ({ ... }) or a sequence ($(...)). Marker π A Marker adds the given mark to the syntax context. TranscrCtx π Context needed to perform transcription of metavariable expressions. FrameKind π LockstepIterSize π An accumulator over a TokenTree to be used with fold. During transcription, we need to make
sure that the size of each sequence and all of its nested sequences are the same as the sizes
of all the matched (nested) sequences in the macro invocation. If they donβt match, somebody
has made a mistake (either the macro writer or caller). count_repetitions π Used solely by the count meta-variable expression, counts the outermost repetitions at a
given optional nested depth. extract_symbol_from_pnr π Extracts an metavariable symbol that can be an identifier, a token tree or a literal. lockstep_iter_size π Given a tree, make sure that all sequences have the same length as the matches for the
appropriate meta-vars in interpolations. lookup_cur_matched π Lookup the meta-var named ident and return the matched token tree from the invocation using
the set of matches interpolations. matched_from_ident π Returns a NamedMatch item declared on the LHS given an arbitrary Ident maybe_use_metavar_location π Store the metavariable span for this original span into a side table.
FIXME: Try to put the metavariable span into SpanData instead of a side table (#118517).
An optimal encoding for inlined spans will need to be selected to minimize regressions.
The side table approach is relatively good, but not perfect due to collisions.
In particular, collisions happen when token is passed as an argument through several macro
calls, like in recursive macros.
The old heuristic below is used to improve spans in case of collisions, but diagnostics are
still degraded sometimes in those cases. metavar_expr_concat π Shared logic for concat/concat_str metavariable expressions metavar_expr_concat_ident π Handle the ${concat(...)} metavariable expression. metavar_expr_concat_str π Handle the ${concat_str(...)} metavariable expression. out_of_bounds_err π Used by meta-variable expressions when an user input is out of the actual declared bounds. For
example, index(999999) in an repetition of only three elements. transcribe π This can do Macro-By-Example transcription. transcribe_metavar π Find the matched nonterminal from the macro invocation, and use it to replace
the meta-var. transcribe_metavar_expr π Turn ${expr(...)} metavariable expressionss into tokens. transcribe_pnr π transcribe_sequence π Turn $(...)* sequences into tokens.