Skip to content

Allow use to import declarations into the current namespace, like in Rust#25

Open
Hugobros3 wants to merge 23 commits intomasterfrom
rust-like-use
Open

Allow use to import declarations into the current namespace, like in Rust#25
Hugobros3 wants to merge 23 commits intomasterfrom
rust-like-use

Conversation

@Hugobros3
Copy link
Copy Markdown
Contributor

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}

@PearCoding
Copy link
Copy Markdown
Contributor

PearCoding commented Jul 4, 2024

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
  }
}

@Hugobros3
Copy link
Copy Markdown
Contributor Author

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.

@WeiPhil
Copy link
Copy Markdown

WeiPhil commented Jul 4, 2024

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.

@PearCoding
Copy link
Copy Markdown
Contributor

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

@Hugobros3 Hugobros3 marked this pull request as ready for review January 6, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants