Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
739f4ac
Derive Copy+Hash for IntErrorKind
ranger-ross Oct 19, 2024
6c04e0a
Rewrite `macro_rules!` parser to not use the MBE engine itself
joshtriplett Jun 26, 2025
0776082
mbe: Fold calls to `check_meta_variables` into the parser loop
joshtriplett Jun 26, 2025
4698c92
Assemble const bounds via normal item bounds in old solver too
compiler-errors Jun 30, 2025
187babc
NoArgsAttributeParser
GrigorenkoPV Jun 18, 2025
96fea30
Feed explicit_predicates_of instead of predicates_of
compiler-errors Jun 30, 2025
ef4f719
Remove doc comments from TyCtxtFeed
compiler-errors Jul 1, 2025
7d6764a
Detect more cases of unused_parens around types
Jun 4, 2025
aa7cc5d
loop match: run exhaustiveness check
folkertdev Jul 1, 2025
8fdf0ef
loop match: handle opaque patterns
folkertdev Jul 1, 2025
15bd619
Change `{Box,Arc,Rc,Weak}::into_raw` to only work with `A = Global`
Amanieu May 18, 2025
8797d54
make Box::into_raw compatible with Stacked Borrows again
RalfJung May 19, 2025
8bb7fdb
NoArgsAttributeParser: use an assoc const instead
GrigorenkoPV Jul 1, 2025
b4d35fd
Add `track_caller` attributes to trace origin of Clippy lints
samueltardieu Jul 1, 2025
2ab641d
bootstrap: `validate rust.codegen-backends` & `targer.<triple>.codege…
GrigorenkoPV Jun 26, 2025
845d9ff
Remove some unsized tuple impls now that we don't support unsizing tu…
oli-obk Mar 6, 2025
e0499e4
Rollup merge of #131923 - ranger-ross:impl-copy-hash-interrorkind, r=…
matthiaskrgr Jul 2, 2025
7c9a03b
Rollup merge of #138340 - oli-obk:one-size-fits-all, r=m-ou-se
matthiaskrgr Jul 2, 2025
1a686c6
Rollup merge of #141219 - Amanieu:leak_alloc, r=joboet
matthiaskrgr Jul 2, 2025
d50240b
Rollup merge of #142212 - GrigorenkoPV:codegens, r=Kobzol
matthiaskrgr Jul 2, 2025
6ebf642
Rollup merge of #142237 - benschulz:unused-parens-fn, r=fee1-dead
matthiaskrgr Jul 2, 2025
2dbb9be
Rollup merge of #142964 - GrigorenkoPV:attributes/argless, r=oli-obk
matthiaskrgr Jul 2, 2025
383f107
Rollup merge of #143070 - joshtriplett:macro-rules-parse, r=petrochenkov
matthiaskrgr Jul 2, 2025
2ce579d
Rollup merge of #143235 - compiler-errors:const-item-bound, r=oli-obk
matthiaskrgr Jul 2, 2025
2becacf
Rollup merge of #143261 - compiler-errors:explicit-pred, r=oli-obk
matthiaskrgr Jul 2, 2025
0617a9e
Rollup merge of #143276 - folkertdev:loop-match-opaque-pattern, r=Nad…
matthiaskrgr Jul 2, 2025
bc8bcc7
Rollup merge of #143306 - samueltardieu:track-clippy-lints-emission, …
matthiaskrgr Jul 2, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
mbe: Fold calls to check_meta_variables into the parser loop
  • Loading branch information
joshtriplett committed Jun 26, 2025
commit 07760822db8dab9dc2bec7d2af23d804ab19da22
23 changes: 7 additions & 16 deletions compiler/rustc_expand/src/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
}

Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_expand/src/mbe/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));

Expand Down
Loading