Make use of hygiene in AST passes
This commit is contained in:
parent
4082cd95a8
commit
6fcdb36ccb
15 changed files with 297 additions and 256 deletions
1
src/test/ui/hygiene/auxiliary/not-libstd.rs
Normal file
1
src/test/ui/hygiene/auxiliary/not-libstd.rs
Normal file
|
|
@ -0,0 +1 @@
|
|||
pub fn not_in_lib_std() {}
|
||||
29
src/test/ui/hygiene/prelude-import-hygiene.rs
Normal file
29
src/test/ui/hygiene/prelude-import-hygiene.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
// Make sure that attribute used when injecting the prelude are resolved
|
||||
// hygienically.
|
||||
|
||||
// check-pass
|
||||
// aux-build:not-libstd.rs
|
||||
|
||||
//revisions: rust2015 rust2018
|
||||
//[rust2018] edition:2018
|
||||
|
||||
// The prelude import shouldn't see these as candidates for when it's trying to
|
||||
// use the built-in macros.
|
||||
extern crate core;
|
||||
use core::prelude::v1::test as prelude_import;
|
||||
use core::prelude::v1::test as macro_use;
|
||||
|
||||
// Should not be used for the prelude import - not a concern in the 2015 edition
|
||||
// because `std` is already declared in the crate root.
|
||||
#[cfg(rust2018)]
|
||||
extern crate not_libstd as std;
|
||||
|
||||
#[cfg(rust2018)]
|
||||
mod x {
|
||||
// The extern crate item should override `std` in the extern prelude.
|
||||
fn f() {
|
||||
std::not_in_lib_std();
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
// build-pass (FIXME(62277): could be check-pass?)
|
||||
// check-pass
|
||||
// edition:2018
|
||||
// aux-build:gensymed.rs
|
||||
|
||||
extern crate gensymed;
|
||||
|
||||
use gensymed::*;
|
||||
|
||||
fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,21 +0,0 @@
|
|||
error[E0432]: unresolved import `__test`
|
||||
--> $DIR/inaccessible-test-modules.rs:5:5
|
||||
|
|
||||
LL | use __test as x;
|
||||
| ------^^^^^
|
||||
| |
|
||||
| no `__test` in the root
|
||||
| help: a similar name exists in the module: `test`
|
||||
|
||||
error[E0432]: unresolved import `__test_reexports`
|
||||
--> $DIR/inaccessible-test-modules.rs:6:5
|
||||
|
|
||||
LL | use __test_reexports as y;
|
||||
| ----------------^^^^^
|
||||
| |
|
||||
| no `__test_reexports` in the root
|
||||
| help: a similar name exists in the module: `__test_reexports`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0432`.
|
||||
22
src/test/ui/test-attrs/decl-macro-test.rs
Normal file
22
src/test/ui/test-attrs/decl-macro-test.rs
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
// Check that declarative macros can declare tests
|
||||
|
||||
// check-pass
|
||||
// compile-flags: --test
|
||||
|
||||
#![feature(decl_macro)]
|
||||
|
||||
macro create_test() {
|
||||
#[test]
|
||||
fn test() {}
|
||||
}
|
||||
|
||||
macro create_module_test() {
|
||||
mod x {
|
||||
#[test]
|
||||
fn test() {}
|
||||
}
|
||||
}
|
||||
|
||||
create_test!();
|
||||
create_test!();
|
||||
create_module_test!();
|
||||
|
|
@ -2,8 +2,8 @@
|
|||
|
||||
// the `--test` harness creates modules with these textual names, but
|
||||
// they should be inaccessible from normal code.
|
||||
use __test as x; //~ ERROR unresolved import `__test`
|
||||
use __test_reexports as y; //~ ERROR unresolved import `__test_reexports`
|
||||
use main as x; //~ ERROR unresolved import `main`
|
||||
use test as y; //~ ERROR unresolved import `test`
|
||||
|
||||
#[test]
|
||||
fn baz() {}
|
||||
21
src/test/ui/test-attrs/inaccessible-test-modules.stderr
Normal file
21
src/test/ui/test-attrs/inaccessible-test-modules.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error[E0432]: unresolved import `main`
|
||||
--> $DIR/inaccessible-test-modules.rs:5:5
|
||||
|
|
||||
LL | use main as x;
|
||||
| ----^^^^^
|
||||
| |
|
||||
| no `main` in the root
|
||||
| help: a similar name exists in the module: `main`
|
||||
|
||||
error[E0432]: unresolved import `test`
|
||||
--> $DIR/inaccessible-test-modules.rs:6:5
|
||||
|
|
||||
LL | use test as y;
|
||||
| ----^^^^^
|
||||
| |
|
||||
| no `test` in the root
|
||||
| help: a similar name exists in the module: `test`
|
||||
|
||||
error: aborting due to 2 previous errors
|
||||
|
||||
For more information about this error, try `rustc --explain E0432`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue