Consider this code (playground):
mod a {
pub trait Foo {
fn bar(&self);
}
}
impl a::Foo for () {
fn bar(&self) {
mod hide { // We're in a new module...
pub fn baz() {
// ...so why is `Foo` in scope here?
().bar()
}
}
hide::baz();
}
}
impl a::Trait for ()
implicitly brings Foo
into scope. Weirdly enough, it stays in scope even when we’re in a nested module inside of a trait function. I have a few questions related to this snippet:
- Is this behaviour (implicit use leaking through a module) expected? Is it desired? Edition 2024 is coming, so we could change it if it’s accidental.
- Is it documented anywhere?
- In fact, is the implicit use itself documented anywhere?
- If I were to make PR into reference + book, where do you think it should be documented? Reference’s section on scopes is currently just a stub, and I don’t feel like I’m able to write a whole section.