Skip to content

Commit f5d4e4c

Browse files
committed
Add more tests for underscore imports
1 parent ef54f57 commit f5d4e4c

File tree

3 files changed

+91
-0
lines changed

3 files changed

+91
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Make sure that if an underscore imports with different contexts can exist in
2+
// the same scope.
3+
4+
// check-pass
5+
6+
#![feature(decl_macro)]
7+
8+
mod x {
9+
pub use std::ops::Deref as _;
10+
}
11+
12+
macro n() {
13+
pub use crate::x::*;
14+
}
15+
16+
#[macro_export]
17+
macro_rules! p {
18+
() => { pub use crate::x::*; }
19+
}
20+
21+
macro m($y:ident) {
22+
mod $y {
23+
crate::n!(); // Reexport of `Deref` should not be imported in `main`
24+
crate::p!(); // Reexport of `Deref` should be imported into `main`
25+
}
26+
}
27+
28+
m!(y);
29+
30+
fn main() {
31+
use crate::y::*;
32+
(&()).deref();
33+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Make sure that if an underscore imports have the same hygiene considerations
2+
// as other imports.
3+
4+
#![feature(decl_macro)]
5+
6+
mod x {
7+
pub use std::ops::Deref as _;
8+
}
9+
10+
macro m($y:ident) {
11+
mod $y {
12+
crate::n!();
13+
}
14+
}
15+
16+
macro n() {
17+
pub use crate::x::*;
18+
}
19+
20+
macro p() {
21+
use std::ops::DerefMut as _;
22+
}
23+
24+
m!(y);
25+
26+
fn main() {
27+
use crate::y::*;
28+
p!();
29+
(&()).deref(); //~ ERROR no method named `deref`
30+
(&mut ()).deref_mut(); //~ ERROR no method named `deref_mut`
31+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0599]: no method named `deref` found for type `&()` in the current scope
2+
--> $DIR/hygiene.rs:29:11
3+
|
4+
LL | (&()).deref();
5+
| ^^^^^
6+
|
7+
= help: items from traits can only be used if the trait is in scope
8+
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
9+
|
10+
LL | use std::ops::Deref;
11+
|
12+
13+
error[E0599]: no method named `deref_mut` found for type `&mut ()` in the current scope
14+
--> $DIR/hygiene.rs:30:15
15+
|
16+
LL | (&mut ()).deref_mut();
17+
| ^^^^^^^^^
18+
|
19+
= help: items from traits can only be used if the trait is in scope
20+
help: the following trait is implemented but not in scope, perhaps add a `use` for it:
21+
|
22+
LL | use std::ops::DerefMut;
23+
|
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0599`.

0 commit comments

Comments
 (0)