diff options
| author | Dylan DPC <99973273+Dylan-DPC@users.noreply.github.com> | 2023-05-20 12:21:02 +0530 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-05-20 12:21:02 +0530 |
| commit | 94ca44a50ad6a76743eac7828d8c5f199b0042fd (patch) | |
| tree | 24a324e6b7a1114d0f5f50996eff087e6f8bfb12 | |
| parent | 9074769dc520c6b5ac92f491add4b2f5dbbca08e (diff) | |
| parent | 990b2899ad8f7c59bfb83b5468a61b383b9617b8 (diff) | |
| download | rust-94ca44a50ad6a76743eac7828d8c5f199b0042fd.tar.gz rust-94ca44a50ad6a76743eac7828d8c5f199b0042fd.zip | |
Rollup merge of #111762 - bvanjoi:fix-111749, r=compiler-errors
fix: emit error when fragment is `MethodReceiverExpr` and items is empty Fixes https://github.com/rust-lang/rust/issues/111749
| -rw-r--r-- | compiler/rustc_expand/src/expand.rs | 6 | ||||
| -rw-r--r-- | tests/ui/macros/issue-111749.rs | 12 | ||||
| -rw-r--r-- | tests/ui/macros/issue-111749.stderr | 18 |
3 files changed, 35 insertions, 1 deletions
diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 1f77e687bb1..5d369a1879a 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -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 { diff --git a/tests/ui/macros/issue-111749.rs b/tests/ui/macros/issue-111749.rs new file mode 100644 index 00000000000..6c45e4e8cd7 --- /dev/null +++ b/tests/ui/macros/issue-111749.rs @@ -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 +} diff --git a/tests/ui/macros/issue-111749.stderr b/tests/ui/macros/issue-111749.stderr new file mode 100644 index 00000000000..7db2b8e6ad1 --- /dev/null +++ b/tests/ui/macros/issue-111749.stderr @@ -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 + |
