Add more tests for underscore imports

This commit is contained in:
Matthew Jasper 2019-09-07 21:22:36 +01:00
parent aa2ae564d3
commit a9752596d3
4 changed files with 145 additions and 0 deletions

View file

@ -0,0 +1,33 @@
// Make sure that underscore imports with different contexts can exist in the
// same scope.
// check-pass
#![feature(decl_macro)]
mod x {
pub use std::ops::Deref as _;
}
macro n() {
pub use crate::x::*;
}
#[macro_export]
macro_rules! p {
() => { pub use crate::x::*; }
}
macro m($y:ident) {
mod $y {
crate::n!(); // Reexport of `Deref` should not be imported in `main`
crate::p!(); // Reexport of `Deref` should be imported into `main`
}
}
m!(y);
fn main() {
use crate::y::*;
(&()).deref();
}

View file

@ -0,0 +1,40 @@
// Make sure that underscore imports have the same hygiene considerations as
// other imports.
#![feature(decl_macro)]
mod x {
pub use std::ops::Deref as _;
}
macro glob_import() {
pub use crate::x::*;
}
macro underscore_import() {
use std::ops::DerefMut as _;
}
mod y {
crate::glob_import!();
crate::underscore_import!();
}
macro create_module($y:ident) {
mod $y {
crate::glob_import!();
crate::underscore_import!();
}
}
create_module!(z);
fn main() {
use crate::y::*;
use crate::z::*;
glob_import!();
underscore_import!();
(&()).deref(); //~ ERROR no method named `deref`
(&mut ()).deref_mut(); //~ ERROR no method named `deref_mut`
}

View file

@ -0,0 +1,27 @@
error[E0599]: no method named `deref` found for type `&()` in the current scope
--> $DIR/hygiene.rs:38:11
|
LL | (&()).deref();
| ^^^^^ method not found in `&()`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
LL | use std::ops::Deref;
|
error[E0599]: no method named `deref_mut` found for type `&mut ()` in the current scope
--> $DIR/hygiene.rs:39:15
|
LL | (&mut ()).deref_mut();
| ^^^^^^^^^ method not found in `&mut ()`
|
= help: items from traits can only be used if the trait is in scope
help: the following trait is implemented but not in scope; perhaps add a `use` for it:
|
LL | use std::ops::DerefMut;
|
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0599`.

View file

@ -0,0 +1,45 @@
// Check that macro expanded underscore imports behave as expected
// check-pass
#![feature(decl_macro, rustc_attrs)]
mod x {
pub use std::ops::Not as _;
}
macro m() {
mod w {
mod y {
pub use std::ops::Deref as _;
}
use crate::x::*;
use self::y::*;
use std::ops::DerefMut as _;
fn f() {
false.not();
(&()).deref();
(&mut ()).deref_mut();
}
}
}
#[rustc_macro_transparency = "transparent"]
macro n() {
mod z {
pub use std::ops::Deref as _;
}
use crate::x::*;
use crate::z::*;
use std::ops::DerefMut as _;
fn f() {
false.not();
(&()).deref();
(&mut ()).deref_mut();
}
}
m!();
n!();
fn main() {}