Skip to content

Item inner preludes #3443

@crlf0710

Description

@crlf0710

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions