mbe: Fold calls to check_meta_variables into the parser loop
This commit is contained in:
parent
6c04e0a7ae
commit
07760822db
2 changed files with 8 additions and 18 deletions
|
|
@ -105,8 +105,6 @@
|
|||
//! stored when entering a macro definition starting from the state in which the meta-variable is
|
||||
//! bound.
|
||||
|
||||
use std::iter;
|
||||
|
||||
use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind};
|
||||
use rustc_ast::{DUMMY_NODE_ID, NodeId};
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
|
|
@ -190,29 +188,22 @@ struct MacroState<'a> {
|
|||
ops: SmallVec<[KleeneToken; 1]>,
|
||||
}
|
||||
|
||||
/// Checks that meta-variables are used correctly in a macro definition.
|
||||
/// Checks that meta-variables are used correctly in one rule of a macro definition.
|
||||
///
|
||||
/// Arguments:
|
||||
/// - `psess` is used to emit diagnostics and lints
|
||||
/// - `node_id` is used to emit lints
|
||||
/// - `span` is used when no spans are available
|
||||
/// - `lhses` and `rhses` should have the same length and represent the macro definition
|
||||
/// - `lhs` and `rhs` represent the rule
|
||||
pub(super) fn check_meta_variables(
|
||||
psess: &ParseSess,
|
||||
node_id: NodeId,
|
||||
span: Span,
|
||||
lhses: &[TokenTree],
|
||||
rhses: &[TokenTree],
|
||||
lhs: &TokenTree,
|
||||
rhs: &TokenTree,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
if lhses.len() != rhses.len() {
|
||||
psess.dcx().span_bug(span, "length mismatch between LHSes and RHSes")
|
||||
}
|
||||
let mut guar = None;
|
||||
for (lhs, rhs) in iter::zip(lhses, rhses) {
|
||||
let mut binders = Binders::default();
|
||||
check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
|
||||
check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
|
||||
}
|
||||
let mut binders = Binders::default();
|
||||
check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar);
|
||||
check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar);
|
||||
guar.map_or(Ok(()), Err)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -423,6 +423,7 @@ pub fn compile_declarative_macro(
|
|||
.pop()
|
||||
.unwrap();
|
||||
check_emission(check_rhs(sess, &rhs_tt));
|
||||
check_emission(macro_check::check_meta_variables(&sess.psess, node_id, &lhs_tt, &rhs_tt));
|
||||
lhses.push(lhs_tt);
|
||||
rhses.push(rhs_tt);
|
||||
if p.token == token::Eof {
|
||||
|
|
@ -438,8 +439,6 @@ pub fn compile_declarative_macro(
|
|||
return dummy_syn_ext(guar);
|
||||
}
|
||||
|
||||
check_emission(macro_check::check_meta_variables(&sess.psess, node_id, span, &lhses, &rhses));
|
||||
|
||||
let transparency = find_attr!(attrs, AttributeKind::MacroTransparency(x) => *x)
|
||||
.unwrap_or(Transparency::fallback(macro_rules));
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue