Skip to content

Commit

Permalink
Mac calls
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Jan 30, 2022
1 parent 47f92a5 commit 858d6a0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 5 additions & 3 deletions compiler/rustc_builtin_macros/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1237,15 +1237,17 @@ fn may_contain_yield_point(e: &ast::Expr) -> bool {

impl Visitor<'_> for MayContainYieldPoint {
fn visit_expr(&mut self, e: &ast::Expr) {
if let ast::ExprKind::Await(_) | ast::ExprKind::Yield(_) | ast::ExprKind::MacCall(_) =
e.kind
{
if let ast::ExprKind::Await(_) | ast::ExprKind::Yield(_) = e.kind {
self.0 = true;
} else {
visit::walk_expr(self, e);
}
}

fn visit_mac_call(&mut self, _: &ast::MacCall) {
self.0 = true;
}

fn visit_attribute(&mut self, _: &ast::Attribute) {
// Conservatively assume this may be a proc macro attribute in
// expression position.
Expand Down
14 changes: 12 additions & 2 deletions src/test/ui/fmt/format-with-yield-point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,23 @@ async fn with_await() {
println!("{} {:?}", "", async {}.await);
}

async fn with_macro_call() {
async fn with_macro_call_expr() {
println!("{} {:?}", "", m!());
}

async fn with_macro_call_stmt_semi() {
println!("{} {:?}", "", { m!(); });
}

async fn with_macro_call_stmt_braced() {
println!("{} {:?}", "", { m!{} });
}

fn assert_send(_: impl Send) {}

fn main() {
assert_send(with_await());
assert_send(with_macro_call());
assert_send(with_macro_call_expr());
assert_send(with_macro_call_stmt_semi());
assert_send(with_macro_call_stmt_braced());
}

0 comments on commit 858d6a0

Please sign in to comment.