|
105 | 105 | //! stored when entering a macro definition starting from the state in which the meta-variable is
|
106 | 106 | //! bound.
|
107 | 107 |
|
108 |
| -use std::iter; |
109 |
| - |
110 | 108 | use rustc_ast::token::{Delimiter, IdentIsRaw, Token, TokenKind};
|
111 | 109 | use rustc_ast::{DUMMY_NODE_ID, NodeId};
|
112 | 110 | use rustc_data_structures::fx::FxHashMap;
|
@@ -192,29 +190,22 @@ struct MacroState<'a> {
|
192 | 190 | ops: SmallVec<[KleeneToken; 1]>,
|
193 | 191 | }
|
194 | 192 |
|
195 |
| -/// Checks that meta-variables are used correctly in a macro definition. |
| 193 | +/// Checks that meta-variables are used correctly in one rule of a macro definition. |
196 | 194 | ///
|
197 | 195 | /// Arguments:
|
198 | 196 | /// - `psess` is used to emit diagnostics and lints
|
199 | 197 | /// - `node_id` is used to emit lints
|
200 |
| -/// - `span` is used when no spans are available |
201 |
| -/// - `lhses` and `rhses` should have the same length and represent the macro definition |
| 198 | +/// - `lhs` and `rhs` represent the rule |
202 | 199 | pub(super) fn check_meta_variables(
|
203 | 200 | psess: &ParseSess,
|
204 | 201 | node_id: NodeId,
|
205 |
| - span: Span, |
206 |
| - lhses: &[TokenTree], |
207 |
| - rhses: &[TokenTree], |
| 202 | + lhs: &TokenTree, |
| 203 | + rhs: &TokenTree, |
208 | 204 | ) -> Result<(), ErrorGuaranteed> {
|
209 |
| - if lhses.len() != rhses.len() { |
210 |
| - psess.dcx().span_bug(span, "length mismatch between LHSes and RHSes") |
211 |
| - } |
212 | 205 | let mut guar = None;
|
213 |
| - for (lhs, rhs) in iter::zip(lhses, rhses) { |
214 |
| - let mut binders = Binders::default(); |
215 |
| - check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar); |
216 |
| - check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar); |
217 |
| - } |
| 206 | + let mut binders = Binders::default(); |
| 207 | + check_binders(psess, node_id, lhs, &Stack::Empty, &mut binders, &Stack::Empty, &mut guar); |
| 208 | + check_occurrences(psess, node_id, rhs, &Stack::Empty, &binders, &Stack::Empty, &mut guar); |
218 | 209 | guar.map_or(Ok(()), Err)
|
219 | 210 | }
|
220 | 211 |
|
|
0 commit comments