Allow `use` to import declarations into the current namespace, like in Rust
Artic introduced module support a couple years ago, unfortunately it has not seen much adoption.
The oft-cited reason by would-be users is that this module support lacks the ability to import definitions into a namespace, which makes using declarations from others prohibitively verbose (at a minimum you must use a single-letter import like A::).
This PR changes the use syntax to be closer to Rust's, which allow:
- Importing non-module declarations into the current namespace by providing a full path to them
- Wildcard imports:
use A::* - (TODO) Multi-imports:
use A::{b, c}
Is the parent scope/module visible by default or do we have to use super still?
E.g.,
fn foo() = 42;
mod bar {
fn sup() {
let v = foo();
v
}
}
No, but this is also the behavior of Rust actually...
https://godbolt.org/z/MxqP15sEn
I nonetheless have a patch that allows for this. I'm tempted to allow ourselves to diverge from Rust here, and allow for that, but we should probably discuss this on call or on Discord at least.
Typically in rust you would just do a use super::* in the module to have access to the parent. While in a single file this seems superfluous I think it helps clarity as to where something unkown comes from when accessing a module of a parent.
Seems like it is the standard in Rust, so I would say we stick to the default.
Spamming some use super::* everywhere is a small burden to bear :D