Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Draft
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

Hugobros3
Copy link
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
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
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

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

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