Skip to content

Commit

Permalink
Rollup merge of #111762 - bvanjoi:fix-111749, r=compiler-errors
Browse files Browse the repository at this point in the history
fix: emit error when fragment is `MethodReceiverExpr` and items is empty

Fixes #111749
  • Loading branch information
Dylan-DPC authored May 20, 2023
2 parents 9074769 + 990b289 commit 94ca44a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion compiler/rustc_expand/src/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,11 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
});
}
};
if fragment_kind == AstFragmentKind::Expr && items.is_empty() {
if matches!(
fragment_kind,
AstFragmentKind::Expr | AstFragmentKind::MethodReceiverExpr
) && items.is_empty()
{
self.cx.emit_err(RemoveExprNotSupported { span });
fragment_kind.dummy(span)
} else {
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/macros/issue-111749.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
macro_rules! cbor_map {
($key:expr) => {
$key.signum();
};
}

fn main() {
cbor_map! { #[test(test)] 4};
//~^ ERROR removing an expression is not supported in this position
//~| ERROR attribute must be of the form `#[test]`
//~| WARNING this was previously accepted by the compiler but is being phased out
}
18 changes: 18 additions & 0 deletions tests/ui/macros/issue-111749.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: removing an expression is not supported in this position
--> $DIR/issue-111749.rs:8:17
|
LL | cbor_map! { #[test(test)] 4};
| ^^^^^^^^^^^^^

error: attribute must be of the form `#[test]`
--> $DIR/issue-111749.rs:8:17
|
LL | cbor_map! { #[test(test)] 4};
| ^^^^^^^^^^^^^
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #57571 <https://github.com/rust-lang/rust/issues/57571>
= note: `#[deny(ill_formed_attribute_input)]` on by default

error: aborting due to 2 previous errors

0 comments on commit 94ca44a

Please sign in to comment.