rust-lang / rust-lang/rfcs

Item inner preludes

Open
#3,443 2 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Markdown
Stars
6.6k
Forks
1.7k
Avg merge
16h 14m
Merged PRs (30d)
1

Description

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

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the proposed Rust examples and compare the motivation with RFC 890. Determine whether the item-level prelude behavior and its possible future extensions have enough design detail for an RFC; done means reaching a documented decision on the proposal, rather than implementing code in this repository.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.