Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions tests/ui/macros/meta-item-global-path-fail-issue-53048.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// Regression test for https://github.com/rust-lang/rust/issues/53048/
// This test ensures that invalid meta item or global path
// is rejected by the compiler.

macro_rules! m { ($m:meta) => { #[derive($m)] pub struct S; }; }

m!(::);
//~^ ERROR expected identifier, found `<eof>`

// no segment after `::` to be a valid path
#[derive(::)] pub struct D;
//~^ ERROR expected unsuffixed literal, found `<eof>`

// value must be a literal, not a path
#[allow(a = ::b::c)]
//~^ ERROR expected unsuffixed literal, found `::`

fn main() {}
23 changes: 23 additions & 0 deletions tests/ui/macros/meta-item-global-path-fail-issue-53048.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
error: expected identifier, found `<eof>`
--> $DIR/meta-item-global-path-fail-issue-53048.rs:7:4
|
LL | macro_rules! m { ($m:meta) => { #[derive($m)] pub struct S; }; }
| ------- while parsing argument for this `meta` macro fragment
LL |
LL | m!(::);
| ^^ expected identifier

error: expected unsuffixed literal, found `<eof>`
--> $DIR/meta-item-global-path-fail-issue-53048.rs:11:10
|
LL | #[derive(::)] pub struct D;
| ^^

error: expected unsuffixed literal, found `::`
--> $DIR/meta-item-global-path-fail-issue-53048.rs:15:13
|
LL | #[allow(a = ::b::c)]
| ^^

error: aborting due to 3 previous errors

15 changes: 15 additions & 0 deletions tests/ui/macros/meta-item-global-path-issue-53048.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Regression test for https://github.com/rust-lang/rust/issues/53048/
// This test ensures that a global path in a meta item is accepted by the compiler.
// All examples are different ways of specifying the same path, and should all compile fine.
//@ check-pass

extern crate core;

#[derive(::core::clone::Clone)] pub struct A;
#[derive(Clone, ::core::marker::Copy)] pub struct C;
#[cfg_attr(true, derive(::core::clone::Clone))] pub struct G;

macro_rules! m { ($m:meta) => { #[derive($m)] pub struct S; }; }
m!(::core::clone::Clone);

fn main() {}
Loading