1
Fork 0

Rollup merge of #132653 - BoxyUwU:const_arg_stmt_mac_call, r=compiler-errors

Don't use `maybe_unwrap_block` when checking for macro calls in a block expr

Fixes #131915

Using `maybe_unwrap_block` to determine if we are looking at a `{ mac_call!{} }` will fail sometimes as `mac_call!{}` could be a `StmtKind::MacCall` not a `StmtKind::Expr`. This caused the def collector to think that `{ mac_call!{} }` was a non-trivial const argument and create a definition for it even though it should not.

r? `@compiler-errors`  cc `@camelid`
This commit is contained in:
Matthias Krüger 2024-11-12 06:27:17 +01:00 committed by GitHub
commit b7dc4813a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 466 additions and 36 deletions

View file

@ -130,18 +130,16 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
&self,
anon_const: &'a AnonConst,
) -> Option<(PendingAnonConstInfo, NodeId)> {
let (block_was_stripped, expr) = anon_const.value.maybe_unwrap_block();
match expr {
Expr { kind: ExprKind::MacCall(..), id, .. } => Some((
anon_const.value.optionally_braced_mac_call(false).map(|(block_was_stripped, id)| {
(
PendingAnonConstInfo {
id: anon_const.id,
span: anon_const.value.span,
block_was_stripped,
},
*id,
)),
_ => None,
}
id,
)
})
}
/// Determines whether the expression `const_arg_sub_expr` is a simple macro call, sometimes
@ -161,18 +159,11 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
panic!("Checking expr is trivial macro call without having entered anon const: `{const_arg_sub_expr:?}`"),
);
let (block_was_stripped, expr) = if pending_anon.block_was_stripped {
(true, const_arg_sub_expr)
} else {
const_arg_sub_expr.maybe_unwrap_block()
};
match expr {
Expr { kind: ExprKind::MacCall(..), id, .. } => {
Some((PendingAnonConstInfo { block_was_stripped, ..pending_anon }, *id))
}
_ => None,
}
const_arg_sub_expr.optionally_braced_mac_call(pending_anon.block_was_stripped).map(
|(block_was_stripped, id)| {
(PendingAnonConstInfo { block_was_stripped, ..pending_anon }, id)
},
)
}
}