# Feature request: trait support #\[refuse\_impl\] attribute, refuse outside implement

**URL:** <https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328>\
**Category:** traits working group\
**Created:** [August 14, 2023, 1:25am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328 "2023-08-14T01:25:14Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![tu6ge](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tu6ge/32/10222_2.png) [@tu6ge](https://internals.rust-lang.org/u/tu6ge)\
**Post date:** [August 14, 2023, 1:25am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/1 "2023-08-14T01:25:14Z")

</div>

When we release some traits, due to lack of consideration, the structure may change in the future. In this case, a break change will occur, and we usually need to make it inherit a private trait to prevent other users from implementing it. I think it is necessary to give users a prompt before that, just like # [deprecated], Next, when a user tries to implement it, compiler give out a warning

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jhpratt/32/11640_2.png) [@jhpratt](https://internals.rust-lang.org/u/jhpratt)\
**Post date:** [August 14, 2023, 1:48am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/2 "2023-08-14T01:48:16Z")

</div>

This has been [accepted by an RFC](https://github.com/rust-lang/rfcs/pull/3323). It's a hard error, not a warning.

---

<div class="post-metadata">

**Author:** ![tu6ge](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tu6ge/32/10222_2.png) [@tu6ge](https://internals.rust-lang.org/u/tu6ge)\
**Post date:** [August 14, 2023, 2:04am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/3 "2023-08-14T02:04:52Z")

</div>

before change it, It is better to give users a prompt.

---

<div class="post-metadata">

**Author:** ![jhpratt](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/jhpratt/32/11640_2.png) [@jhpratt](https://internals.rust-lang.org/u/jhpratt)\
**Post date:** [August 14, 2023, 3:31am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/4 "2023-08-14T03:31:54Z")

</div>

Please read the RFC. It answers a number of questions you likely have.

---

<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:** [August 14, 2023, 3:35am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/5 "2023-08-14T03:35:44Z")

</div>

I think OP might be suggesting some kind of "user implementations on this trait are deprecated" annotation, to facilitate eventually turning a trait sealed in a next major version of their crate - or generally to mark a trait as "this was never intended to be user-implementable". The intended effect would be a warning when the user tries to implement the trait. Note "sealing" vs "sealed".

---

<div class="post-metadata">

**Author:** ![tu6ge](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tu6ge/32/10222_2.png) [@tu6ge](https://internals.rust-lang.org/u/tu6ge)\
**Post date:** [August 14, 2023, 3:39am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/6 "2023-08-14T03:39:16Z")

</div>

Yeah

---

<div class="post-metadata">

**Author:** ![quinedot](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/quinedot/32/7294_2.png) [@quinedot](https://internals.rust-lang.org/u/quinedot)\
**Post date:** [August 14, 2023, 5:35am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/7 "2023-08-14T05:35:51Z")

</div>

Sounds like something that could be a more general attribute ("going to break this soon even though it's not deprecated").

- Visibility changes
- Meant to make this `non_exhaustive`
- Taking away a visible field or variant
- Need to change some variance, auto trait, or other leakage
- Removing a default trait method body
- Changing a blanket implementation
- Etc

* * *

Incidentally, feature requests that are just thrown out there and not championed rarely go anywhere.

---

<div class="post-metadata">

**Author:** ![tu6ge](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tu6ge/32/10222_2.png) [@tu6ge](https://internals.rust-lang.org/u/tu6ge)\
**Post date:** [August 14, 2023, 6:43am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/8 "2023-08-14T06:43:45Z")

</div>

mybe, the name should be change to `#[refuse_impl]`.

---

<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:** [February 4, 2025, 6:44am UTC](https://internals.rust-lang.org/t/feature-request-trait-support-refuse-impl-attribute-refuse-outside-implement/19328/10 "2025-02-04T06:44:25Z")

</div>

Closed on February 4, 2025, 6:44am UTC

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