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

Item inner preludes #3443

Open
crlf0710 opened this issue Jun 3, 2023 · 2 comments
Open

Item inner preludes #3443

crlf0710 opened this issue Jun 3, 2023 · 2 comments

Comments

@crlf0710
Copy link
Member

crlf0710 commented Jun 3, 2023

TL;DR : This allows this code with the new prelude keyword:

mod bar {
     #[derive(Default)]
     pub(crate) struct Bar(pub(crate) usize);
     #[derive(Default)]
     pub(crate) struct Baz(pub(crate) usize);
}
struct Foo {
    bar: Bar,
    prelude {
          use bar::*;
    },
    baz: Baz,
}

impl Foo {
    fn new() -> Self {
        Foo {
             bar: Default::default(),
             baz: Default::default(),
        }
    }
   fn into_baz(self) -> Baz {
        self.baz
    }
    prelude {
          use bar::*;
    }
}

Although the similar names, the motivation is quite different from RFC 890, in that this tries to address these issues:

  • Allowing use items in more cases, bringing more ergonomics

Possible Future extensions:

  • Allowing nested ADT definitions, in a way not affecting the typesystem.
  • Generalize this to the mod levels, to actually cover the original custom prelude use case
@crlf0710 crlf0710 changed the title Local preludes Item inner preludes Jun 3, 2023
@SOF3
Copy link

SOF3 commented Jun 12, 2023

Is this already possible to implement with an attribute macro?

impl Xxx {
    #![prelude(
        bar::*,
    )]

    // ...
}

expands to

mod _random {
    use super::*;
    use bar::*;

    impl Xxx {
        // ...
    }
}

use _random::*;

@Nilstrieb
Copy link
Member

this seems like a solution without a problem

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

No branches or pull requests

4 participants
@crlf0710 @SOF3 @Nilstrieb and others