diff options
| author | Esteban Küber <esteban@kuber.com.ar> | 2021-02-11 10:37:31 -0800 |
|---|---|---|
| committer | Esteban Küber <esteban@kuber.com.ar> | 2021-02-11 11:30:05 -0800 |
| commit | 49310cee30510170946561814c0a87b4dc8e667d (patch) | |
| tree | 52ea4998ae4bc4afe7f097975330aa067eedac9b | |
| parent | 19806e451476d9a97175d2ca0c095545e8894421 (diff) | |
| download | rust-49310cee30510170946561814c0a87b4dc8e667d.tar.gz rust-49310cee30510170946561814c0a87b4dc8e667d.zip | |
Add test for "const stability on macro"
| -rw-r--r-- | compiler/rustc_expand/src/base.rs | 7 | ||||
| -rw-r--r-- | src/test/ui/attributes/const-stability-on-macro.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/attributes/const-stability-on-macro.stderr | 20 |
3 files changed, 38 insertions, 2 deletions
diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index bd93e34af68..5652d779908 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -774,8 +774,11 @@ impl SyntaxExtension { sess.parse_sess .span_diagnostic .struct_span_err(sp, "macros cannot have const stability attributes") - .span_label(sp, "invalid stability attribute") - .span_label(span, "in this macro") + .span_label(sp, "invalid const stability attribute") + .span_label( + sess.source_map().guess_head_span(span), + "const stability attribute affects this macro", + ) .emit(); } diff --git a/src/test/ui/attributes/const-stability-on-macro.rs b/src/test/ui/attributes/const-stability-on-macro.rs new file mode 100644 index 00000000000..3fc60f7ce48 --- /dev/null +++ b/src/test/ui/attributes/const-stability-on-macro.rs @@ -0,0 +1,13 @@ +#[rustc_const_stable(feature = "foo", since = "0")] +//~^ ERROR macros cannot have const stability attributes +macro_rules! foo { + () => {}; +} + +#[rustc_const_unstable(feature = "bar", issue="none")] +//~^ ERROR macros cannot have const stability attributes +macro_rules! bar { + () => {}; +} + +fn main() {} diff --git a/src/test/ui/attributes/const-stability-on-macro.stderr b/src/test/ui/attributes/const-stability-on-macro.stderr new file mode 100644 index 00000000000..ef24e44d190 --- /dev/null +++ b/src/test/ui/attributes/const-stability-on-macro.stderr @@ -0,0 +1,20 @@ +error: macros cannot have const stability attributes + --> $DIR/const-stability-on-macro.rs:1:1 + | +LL | #[rustc_const_stable(feature = "foo", since = "0")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid const stability attribute +LL | +LL | macro_rules! foo { + | ---------------- const stability attribute affects this macro + +error: macros cannot have const stability attributes + --> $DIR/const-stability-on-macro.rs:7:1 + | +LL | #[rustc_const_unstable(feature = "bar", issue="none")] + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ invalid const stability attribute +LL | +LL | macro_rules! bar { + | ---------------- const stability attribute affects this macro + +error: aborting due to 2 previous errors + |
