File tree Expand file tree Collapse file tree 4 files changed +145
-0
lines changed
src/test/ui/underscore-imports Expand file tree Collapse file tree 4 files changed +145
-0
lines changed Original file line number Diff line number Diff line change 1+ // Make sure that underscore imports with different contexts can exist in the
2+ // 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+ }
Original file line number Diff line number Diff line change 1+ // Make sure that underscore imports have the same hygiene considerations as
2+ // other imports.
3+
4+ #![ feature( decl_macro) ]
5+
6+ mod x {
7+ pub use std:: ops:: Deref as _;
8+ }
9+
10+
11+ macro glob_import ( ) {
12+ pub use crate :: x:: * ;
13+ }
14+
15+ macro underscore_import ( ) {
16+ use std:: ops:: DerefMut as _;
17+ }
18+
19+ mod y {
20+ crate :: glob_import!( ) ;
21+ crate :: underscore_import!( ) ;
22+ }
23+
24+ macro create_module ( $y: ident) {
25+ mod $y {
26+ crate :: glob_import!( ) ;
27+ crate :: underscore_import!( ) ;
28+ }
29+ }
30+
31+ create_module ! ( z) ;
32+
33+ fn main ( ) {
34+ use crate :: y:: * ;
35+ use crate :: z:: * ;
36+ glob_import ! ( ) ;
37+ underscore_import ! ( ) ;
38+ ( & ( ) ) . deref ( ) ; //~ ERROR no method named `deref`
39+ ( & mut ( ) ) . deref_mut ( ) ; //~ ERROR no method named `deref_mut`
40+ }
Original file line number Diff line number Diff line change 1+ error[E0599]: no method named `deref` found for type `&()` in the current scope
2+ --> $DIR/hygiene.rs:38:11
3+ |
4+ LL | (&()).deref();
5+ | ^^^^^ method not found in `&()`
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:39:15
15+ |
16+ LL | (&mut ()).deref_mut();
17+ | ^^^^^^^^^ method not found in `&mut ()`
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`.
Original file line number Diff line number Diff line change 1+ // Check that macro expanded underscore imports behave as expected
2+
3+ // check-pass
4+
5+ #![ feature( decl_macro, rustc_attrs) ]
6+
7+ mod x {
8+ pub use std:: ops:: Not as _;
9+ }
10+
11+ macro m( ) {
12+ mod w {
13+ mod y {
14+ pub use std:: ops:: Deref as _;
15+ }
16+ use crate :: x:: * ;
17+ use self :: y:: * ;
18+ use std:: ops:: DerefMut as _;
19+ fn f ( ) {
20+ false . not ( ) ;
21+ ( & ( ) ) . deref ( ) ;
22+ ( & mut ( ) ) . deref_mut ( ) ;
23+ }
24+ }
25+ }
26+
27+ #[ rustc_macro_transparency = "transparent" ]
28+ macro n( ) {
29+ mod z {
30+ pub use std:: ops:: Deref as _;
31+ }
32+ use crate :: x:: * ;
33+ use crate :: z:: * ;
34+ use std:: ops:: DerefMut as _;
35+ fn f ( ) {
36+ false . not ( ) ;
37+ ( & ( ) ) . deref ( ) ;
38+ ( & mut ( ) ) . deref_mut ( ) ;
39+ }
40+ }
41+
42+ m ! ( ) ;
43+ n ! ( ) ;
44+
45+ fn main ( ) { }
You can’t perform that action at this time.
0 commit comments