diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-17 12:19:13 +0000 |
commit | 218caa410aa38c29984be31a5229b9fa717560ee (patch) | |
tree | c54bd55eeb6e4c508940a30e94c0032fbd45d677 /tests/ui/imports/extern-crate-self | |
parent | Releasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff) | |
download | rustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip |
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/imports/extern-crate-self')
6 files changed, 82 insertions, 0 deletions
diff --git a/tests/ui/imports/extern-crate-self/extern-crate-self-fail.rs b/tests/ui/imports/extern-crate-self/extern-crate-self-fail.rs new file mode 100644 index 000000000..1c0d3b4b9 --- /dev/null +++ b/tests/ui/imports/extern-crate-self/extern-crate-self-fail.rs @@ -0,0 +1,6 @@ +extern crate self; //~ ERROR `extern crate self;` requires renaming + +#[macro_use] //~ ERROR `#[macro_use]` is not supported on `extern crate self` +extern crate self as foo; + +fn main() {} diff --git a/tests/ui/imports/extern-crate-self/extern-crate-self-fail.stderr b/tests/ui/imports/extern-crate-self/extern-crate-self-fail.stderr new file mode 100644 index 000000000..127765727 --- /dev/null +++ b/tests/ui/imports/extern-crate-self/extern-crate-self-fail.stderr @@ -0,0 +1,19 @@ +error: `extern crate self;` requires renaming + --> $DIR/extern-crate-self-fail.rs:1:1 + | +LL | extern crate self; + | ^^^^^^^^^^^^^^^^^^ + | +help: rename the `self` crate to be able to import it + | +LL | extern crate self as name; + | ~~~~~~~~~~~~~~~~~~~~~~~~~~ + +error: `#[macro_use]` is not supported on `extern crate self` + --> $DIR/extern-crate-self-fail.rs:3:1 + | +LL | #[macro_use] + | ^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/imports/extern-crate-self/extern-crate-self-macro-alias.rs b/tests/ui/imports/extern-crate-self/extern-crate-self-macro-alias.rs new file mode 100644 index 000000000..796835228 --- /dev/null +++ b/tests/ui/imports/extern-crate-self/extern-crate-self-macro-alias.rs @@ -0,0 +1,16 @@ +// run-pass + +// Test that a macro can correctly expand the alias +// in an `extern crate self as ALIAS` item. + +fn the_answer() -> usize { 42 } + +macro_rules! alias_self { + ($alias:ident) => { extern crate self as $alias; } +} + +alias_self!(the_alias); + +fn main() { + assert_eq!(the_alias::the_answer(), 42); +} diff --git a/tests/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs b/tests/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs new file mode 100644 index 000000000..244293be7 --- /dev/null +++ b/tests/ui/imports/extern-crate-self/extern-crate-self-macro-item.rs @@ -0,0 +1,12 @@ +// build-pass (FIXME(62277): could be check-pass?) + +// Test that `extern crate self;` is accepted +// syntactically as an item for use in a macro. + +macro_rules! accept_item { ($x:item) => {} } + +accept_item! { + extern crate self; +} + +fn main() {} diff --git a/tests/ui/imports/extern-crate-self/extern-crate-self-macro-self.rs b/tests/ui/imports/extern-crate-self/extern-crate-self-macro-self.rs new file mode 100644 index 000000000..009a92e87 --- /dev/null +++ b/tests/ui/imports/extern-crate-self/extern-crate-self-macro-self.rs @@ -0,0 +1,16 @@ +// run-pass + +// Test that a macro can correctly expand `self` in +// an `extern crate self as ALIAS` item. + +fn the_answer() -> usize { 42 } + +macro_rules! extern_something { + ($alias:ident) => { extern crate $alias as the_alias; } +} + +extern_something!(self); + +fn main() { + assert_eq!(the_alias::the_answer(), 42); +} diff --git a/tests/ui/imports/extern-crate-self/extern-crate-self-pass.rs b/tests/ui/imports/extern-crate-self/extern-crate-self-pass.rs new file mode 100644 index 000000000..9cebb622e --- /dev/null +++ b/tests/ui/imports/extern-crate-self/extern-crate-self-pass.rs @@ -0,0 +1,13 @@ +// build-pass (FIXME(62277): could be check-pass?) + +extern crate self as foo; + +struct S; + +mod m { + fn check() { + foo::S; // OK + } +} + +fn main() {} |