resolve: Simplify collection of traits in scope
This commit is contained in:
parent
6526e5c772
commit
b7071b2353
7 changed files with 141 additions and 163 deletions
53
src/test/ui/hygiene/traits-in-scope.rs
Normal file
53
src/test/ui/hygiene/traits-in-scope.rs
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
// Macros with def-site hygiene still bring traits into scope.
|
||||
// It is not clear whether this is desirable behavior or not.
|
||||
// It is also not clear how to prevent it if it is not desirable.
|
||||
|
||||
// check-pass
|
||||
|
||||
#![feature(decl_macro)]
|
||||
#![feature(trait_alias)]
|
||||
|
||||
mod traits {
|
||||
pub trait Trait1 {
|
||||
fn simple_import(&self) {}
|
||||
}
|
||||
pub trait Trait2 {
|
||||
fn renamed_import(&self) {}
|
||||
}
|
||||
pub trait Trait3 {
|
||||
fn underscore_import(&self) {}
|
||||
}
|
||||
pub trait Trait4 {
|
||||
fn trait_alias(&self) {}
|
||||
}
|
||||
|
||||
impl Trait1 for () {}
|
||||
impl Trait2 for () {}
|
||||
impl Trait3 for () {}
|
||||
impl Trait4 for () {}
|
||||
}
|
||||
|
||||
macro m1() {
|
||||
use traits::Trait1;
|
||||
}
|
||||
macro m2() {
|
||||
use traits::Trait2 as Alias;
|
||||
}
|
||||
macro m3() {
|
||||
use traits::Trait3 as _;
|
||||
}
|
||||
macro m4() {
|
||||
trait Alias = traits::Trait4;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
m1!();
|
||||
m2!();
|
||||
m3!();
|
||||
m4!();
|
||||
|
||||
().simple_import();
|
||||
().renamed_import();
|
||||
().underscore_import();
|
||||
().trait_alias();
|
||||
}
|
||||
|
|
@ -1,5 +1,6 @@
|
|||
// Make sure that underscore imports have the same hygiene considerations as
|
||||
// other imports.
|
||||
// Make sure that underscore imports have the same hygiene considerations as other imports.
|
||||
|
||||
// check-pass
|
||||
|
||||
#![feature(decl_macro)]
|
||||
|
||||
|
|
@ -7,7 +8,6 @@ mod x {
|
|||
pub use std::ops::Deref as _;
|
||||
}
|
||||
|
||||
|
||||
macro glob_import() {
|
||||
pub use crate::x::*;
|
||||
}
|
||||
|
|
@ -35,6 +35,6 @@ fn main() {
|
|||
use crate::z::*;
|
||||
glob_import!();
|
||||
underscore_import!();
|
||||
(&()).deref(); //~ ERROR no method named `deref`
|
||||
(&mut ()).deref_mut(); //~ ERROR no method named `deref_mut`
|
||||
(&()).deref();
|
||||
(&mut ()).deref_mut();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +0,0 @@
|
|||
error[E0599]: no method named `deref` found for reference `&()` 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 mutable reference `&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`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue