Rollup merge of #83814 - petrochenkov:emptyexpr, r=davidtwco

expand: Do not ICE when a legacy AST-based macro attribute produces and empty expression

Fixes https://github.com/rust-lang/rust/issues/80251

The reported error is the same as for `let _ = #[cfg(FALSE)] EXPR;`
This commit is contained in:
Yuki Okushi 2021-04-06 06:24:12 +09:00 committed by GitHub
commit 67ffbedada
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

View file

@ -735,7 +735,14 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
});
}
};
fragment_kind.expect_from_annotatables(items)
if fragment_kind == AstFragmentKind::Expr && items.is_empty() {
let msg =
"removing an expression is not supported in this position";
self.cx.span_err(span, msg);
fragment_kind.dummy(span)
} else {
fragment_kind.expect_from_annotatables(items)
}
}
Err(mut err) => {
err.emit();