# Allow derive macro, trait and types with the same name

**URL:** <https://internals.rust-lang.org/t/allow-derive-macro-trait-and-types-with-the-same-name/23864>\
**Category:** language design\
**Created:** [December 29, 2025, 2:41pm UTC](https://internals.rust-lang.org/t/allow-derive-macro-trait-and-types-with-the-same-name/23864 "2025-12-29T14:41:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![alrz](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/alrz/32/3907_2.png) [@alrz](https://internals.rust-lang.org/u/alrz)\
**Post date:** [December 29, 2025, 2:41pm UTC](https://internals.rust-lang.org/t/allow-derive-macro-trait-and-types-with-the-same-name/23864/1 "2025-12-29T14:41:35Z")

</div>

More often than not I encounter errors like `expected trait, found derive macro X` or `expected type but found trait` and so on which requires an explicit import. As far as I know Rust expects only a single one of these in a given context and there's nothing to disambiguate, so I think the restriction on same-name trait and types seems to be arbitrary.

For example with this the prelude could include both Hash trait and the derive macro and still remain backward compatible. Same goes for traits and types where you don't have to invent a new name if you start with a trait and then a structure to implement it, they could simply use the same name.

---

<div class="post-metadata">

**Author:** ![steffahn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/steffahn/32/13288_2.png) [@steffahn](https://internals.rust-lang.org/u/steffahn)\
**Post date:** [December 29, 2025, 3:25pm UTC](https://internals.rust-lang.org/t/allow-derive-macro-trait-and-types-with-the-same-name/23864/2 "2025-12-29T15:25:56Z")

</div>

> [@alrz](#):
>
> As far as I know Rust expects only a single one of these in a given context and there's nothing to disambiguate

It’s worth mentioning that in edition 2015 and 2018, every _trait_ also defines a _type_, the type of “trait objects”. The `dyn` keyword introduced with rustc version 1.26 made the situation more explicit so you can nowadays write `&dyn Any` instead of `&mut dyn Write` etc… instead of `&Any`, `&mut Write` etc. Rust 2015 and 2018 editions are however still supported of course; and API interfaces are supposed to work well across editions.\[1\]

Also, there’s an argument to be had, on the same grounds that motivated trait object types no longer have the same name as the corresponding trait, that instead allowing an _arbitrary_ pair of type & trait to share the same name can be equally – or maybe even more – confusing.

* * *

Derive macros on the other hand are _already_ supported to co-exist under the same name as a trait\[2\], and very often _do_.

> [@alrz](#):
>
> For example with this the prelude could include both Hash trait and the derive macro and still remain backward compatible.

I’m not completely sure where to find any existing discussion about the question of including the `Hash` trait in the prelude, but I don’t think there’s any _technical_ argument against such a step; especially I can hardly imagine any backwards-compatibility-related reasons that would be alleviated by any more forgiving rules on types and/or traits and/or macros with the same name. Feel free to be more explicit about what exactly you had in mind here though 😉\[3\]

* * *

1. Technically, there are ways around this, like one could make some re-export visibility dependent on the edition of the importing code… it may get annoying to use though. Also, probably the question more prominently arises of how to import _only_ the trait or _only_ the type of a certain name, if a user wants to do that. 

2. or a type 

3. One reason that I _can_ imagine is that “`Hash`” is such a generic name that we’d want to allow users to make use of it for their own types and/or traits more easily.  
  
And conversely, the reason for the `derive` to _be_ in the prelude is most likely entirely historic, from a time when these `derive` macros were magical compiler-builtins that were always in scope by default, anyway, and users could not even define their own ones to begin with. [You can see [this RFC](https://rust-lang.github.io/rfcs/1566-proc-macros.html) happened after Rust 1.0, but Rust 1.0 [does already support `#⁠[derive(Hash)]`](https://rust.godbolt.org/z/caroT9YKs).]

---

<div class="post-metadata">

**Author:** ![ais523](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@ais523](https://internals.rust-lang.org/u/ais523)\
**Post date:** [December 29, 2025, 3:41pm UTC](https://internals.rust-lang.org/t/allow-derive-macro-trait-and-types-with-the-same-name/23864/3 "2025-12-29T15:41:09Z")

</div>

I'm opposed to this, both because it could be confusing, and because it places constraints on the syntax for future language extensions. Rust currently uses `:` to mean all of "has type", "implements trait", or "outlives", which means that if you have a context in which you want to be able to say either of "this value has this type" or "this type implements this trait", the two have the same syntax (and although there are no such contexts at the moment, it seems plausible that some might be added). This currently would be unambiguous specifically because type and trait names can't be the same (except in the `dyn Trait` case, which can be spelled as `Trait` in Rust 2015 despite being a type, and this usually isn't a problem due to `dyn Trait` being unsized).

In retrospect it would probably have been better to use different punctuation for the "type implements trait" and "value has type" syntaxes, but it's probably too late to change now.

---

<div class="post-metadata">

**Author:** ![kpreid](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kpreid/32/8484_2.png) [@kpreid](https://internals.rust-lang.org/u/kpreid)\
**Post date:** [December 29, 2025, 5:06pm UTC](https://internals.rust-lang.org/t/allow-derive-macro-trait-and-types-with-the-same-name/23864/4 "2025-12-29T17:06:08Z")

</div>

> [@ais523](#):
>
> In retrospect it would probably have been better to use different punctuation for the "type implements trait" and "value has type" syntaxes, but it's probably too late to change now.

“The first rule of computer language design is that everybody wants the colon” — Larry Wall

It’s such a handy character for “there is some kind of relationship between these two things”, and it’s out of fashion to put an actual verb instead of punctuation in there instead.

---

<div class="post-metadata">

**Author:** ![mathstuf](https://avatars.discourse-cdn.com/v4/letter/m/958977/32.png) [@mathstuf](https://internals.rust-lang.org/u/mathstuf)\
**Post date:** [December 29, 2025, 6:11pm UTC](https://internals.rust-lang.org/t/allow-derive-macro-trait-and-types-with-the-same-name/23864/5 "2025-12-29T18:11:37Z")

</div>

> [@kpreid](#):
>
> It’s such a handy character for “there is some kind of relationship between these two things”, and it’s out of fashion to put an actual verb instead of punctuation in there instead.

If we're feeling particularly adventurous, the [Unicode Confusables](https://www.unicode.org/Public/security/revision-03/confusablesSummary.txt) page has plenty of doppelgängers to choose from:

> [@](#):
>
> ```rust
> #	:	ः	ઃ	ː	ꓽ	˸	։	׃	܃	܄	᠃	᠉	⁚	∶	꞉	︰	：
> (‎ : ‎)	003A COLON
> ←	(‎ ः ‎)	0903 DEVANAGARI SIGN VISARGA
> ←	(‎ ઃ ‎)	0A83 GUJARATI SIGN VISARGA
> ←	(‎ ː ‎)	02D0 MODIFIER LETTER TRIANGULAR COLON
> ←	(‎ ꓽ ‎)	A4FD LISU LETTER TONE MYA JEU
> ←	(‎ ˸ ‎)	02F8 MODIFIER LETTER RAISED COLON
> ←	(‎ ։ ‎)	0589 ARMENIAN FULL STOP
> ←	(‎ ׃ ‎)	05C3 HEBREW PUNCTUATION SOF PASUQ
> ←	(‎ ܃ ‎)	0703 SYRIAC SUPRALINEAR COLON
> ←	(‎ ܄ ‎)	0704 SYRIAC SUBLINEAR COLON
> ←	(‎ ᠃ ‎)	1803 MONGOLIAN FULL STOP
> ←	(‎ ᠉ ‎)	1809 MONGOLIAN MANCHU FULL STOP
> ←	(‎ ⁚ ‎)	205A TWO DOT PUNCTUATION
> ←	(‎ ∶ ‎)	2236 RATIO
> ←	(‎ ꞉ ‎)	A789 MODIFIER LETTER COLON
> ←	(‎ ︰ ‎)	FE30 PRESENTATION FORM FOR VERTICAL TWO DOT LEADER
> ←	(‎ ： ‎)	FF1A FULLWIDTH COLON	# →︰→
> 
> ```

(`</s>`)
