# Generic trait auto distiguish

**URL:** <https://internals.rust-lang.org/t/generic-trait-auto-distiguish/15454>\
**Category:** language design\
**Created:** [October 16, 2021, 3:49pm UTC](https://internals.rust-lang.org/t/generic-trait-auto-distiguish/15454 "2021-10-16T15:49:12Z")\
**Posts on this page:** 1\
**Showing post:** 2

<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:** [October 16, 2021, 3:53pm UTC](https://internals.rust-lang.org/t/generic-trait-auto-distiguish/15454/2 "2021-10-16T15:53:26Z")

</div>

No, the `~const` does not mean `!const`. Instead it’s an (unstable, not finalized) syntax used in trait bounds on `const fn` where something like

```rust
const fn foo<T: ~const Bar>(…) {…} 

```

means

- when calling `foo` normally, you’ll need to ensure `T: Bar`
- when calling `foo` in a `const` context (e.g. as an initializer to a `static` or in the definition of a `const`), you’ll have to ensure `T: const Bar`
  - note, that `T: const Bar` means that there’s not only an `impl Bar for T` but an `impl const Bar for T`, the latter containing all the same methods of `Bar`, but as `const fn`s, instead of ordinary `fn`s.

More information: [Pre-RFC: Revamped const\_trait\_impl aka RFC 2632](https://internals.rust-lang.org/t/pre-rfc-revamped-const-trait-impl-aka-rfc-2632/15192)

So the `~` is _not_ negation, instead it’s deliberately new (and, as mentioned, WIP/unstable/nonfinal) syntax with a very specific meaning.

* * *

The related question of whether something like

```rust
struct Foo<T> {
  val: T,
}

impl<T: Copy> Foo<T> {
  fn foo(&self) {
    println!("copy");
  }
}

impl<T: !Copy> Foo<T> {
  fn foo(&self) {
    println!("no copy");
  }
}

```

might ever work: answer is, yes probably at some point in the (possibly distant) future for certain traits and/or types negative trait bounds will be supported in rust; but not like this particular example for the trait `Copy` and generically over all types. The reason is: It’s currently an accepted change to add an implementation of `Copy` to a type over a minor semver-change. Anything that relies on `T: !Copy` would _break_ over such a change. Of course, this particular example does not _just_ have an `impl` based on `T: !Copy`, so it doesn’t _fully_ break; changing behavior based on trait implementations is something that the WIP language feature “[specialization](https://rust-lang.github.io/rfcs/1210-impl-specialization.html)” tackles – it does use different syntax and has lots of unresolved problems, but can essentially [achieve the same thing](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=9dad3121db7356fe9f40b09bb43dddbd).

---

_[View the full topic](https://internals.rust-lang.org/t/generic-trait-auto-distiguish/15454)._
