# Pre-Pre-RFC: anonymous module / namespace \["Solved" by 2526-const-wildcard\]

**URL:** https://internals.rust-lang.org/t/pre-pre-rfc-anonymous-module-namespace-solved-by-2526-const-wildcard/9378
**Category:** language design
**Created:** [February 6, 2019, 2:08pm UTC](https://internals.rust-lang.org/t/pre-pre-rfc-anonymous-module-namespace-solved-by-2526-const-wildcard/9378 "2019-02-06T14:08:53Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dhm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dhm/32/4879_2.png) [@dhm](https://internals.rust-lang.org/u/dhm)
#### Post date: [February 6, 2019, 2:08pm UTC](https://internals.rust-lang.org/t/pre-pre-rfc-anonymous-module-namespace-solved-by-2526-const-wildcard/9378/1 "2019-02-06T14:08:53Z")

</div>

The idea is to be able to write something along the lines of:

```rust
mod /* unnamed! */ {
    // ...
}

```

Why ? The main place where I find this useful is for macros defining argument-specific custom items.

### Example:

#### Imagine you have somewhere:

```rust
pub use self::my_type_implementation::MyType;
mod my_type_implementation;

```

### and would like to check that the implemented `MyType` satisfies a given contract:

```rust
for<...> // all type/lifetime trait bounds parameters (optional)
    MyType
<...> // type/lifetime parameters for MyType (optional)
:
    Trait1 +
    Trait2<...> /* idem */ +
    ... +

```

For instance, let’s say `MyType` is parametric over `T` and want

```rust
for<T : Debug> MyType<T> : Debug

```

there are two ways to get that:

1. A function (and thus, `dead_code` !) :

2. a trait:

### Both solutions can be generalized with a macro, but they pollute the current namespace

by defining a new item (a function or a trait). Thus, for the macro to be used, it must either: only be safe to call within an empty `mod`ule that the caller sets up (horrible!); take a free identifier `$ident:ident` and then expand to

```rust
mod $ident {
    use super::*;
    // actual contents go here
}

```

(better, but remains the problem of the fresh/available identifier);

or use something like the [`::paste`](https://crates.io/crates/paste) crate to forge your own (hopefully unique!) identifier from the arguments of the macro (hacky + adds a dependency)

## The solution

Since we are not exporting any of the defined items, we don’t actually need to have a usable name for the `mod`ule / namespace : in the same way that closure types are anonymous, it would be great to be able to have an anonymous module construct allowing to define the contents of the aforementioned macro as:

```rust
mod /*unnamed !*/ {
    use super::*;
    // actual contents go here
}

```

with the given property, of course, that multiple anonymous modules can live next to another:

```rust
//! The following would be valid:

// 1st anonymous module,
mod {}

// 2nd anonymous module,
mod {}

```

---

<div class="post-metadata">

### Author: ![Nemo157](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/nemo157/32/11585_2.png) [@Nemo157](https://internals.rust-lang.org/u/Nemo157)
#### Post date: [February 6, 2019, 2:20pm UTC](https://internals.rust-lang.org/t/pre-pre-rfc-anonymous-module-namespace-solved-by-2526-const-wildcard/9378/2 "2019-02-06T14:20:09Z")

</div>

The accepted (and implemented) `const _: () = { /* items */ };` RFC [allows this usecase](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=b0cfb41741a7b20a596871e4a2491339) with minimal extra ovehead.

> <https://github.com/rust-lang/rfcs/pull/2526>

---

<div class="post-metadata">

### Author: ![dhm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dhm/32/4879_2.png) [@dhm](https://internals.rust-lang.org/u/dhm)
#### Post date: [February 6, 2019, 2:39pm UTC](https://internals.rust-lang.org/t/pre-pre-rfc-anonymous-module-namespace-solved-by-2526-const-wildcard/9378/3 "2019-02-06T14:39:10Z")

</div>

Awesome!!

I didn’t know of `underscore_const_names` but it is exactly what I was looking for (sometimes I don’t need a whole namespace but just some const typecheck and this also fits that need). Looking forward for an early stabilization then 🙂

---

<div class="post-metadata">

### Author: ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)
#### Post date: [May 7, 2019, 2:39pm UTC](https://internals.rust-lang.org/t/pre-pre-rfc-anonymous-module-namespace-solved-by-2526-const-wildcard/9378/4 "2019-05-07T14:39:10Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
