# \[Pre-RFC\] \`trait\` & \`impl\` Blocks Without Bodies (\`impl MyTrait for usize; // semicolon\`)

**URL:** <https://internals.rust-lang.org/t/pre-rfc-trait-impl-blocks-without-bodies-impl-mytrait-for-usize-semicolon/13967>\
**Category:** language design\
**Created:** [February 2, 2021, 8:50pm UTC](https://internals.rust-lang.org/t/pre-rfc-trait-impl-blocks-without-bodies-impl-mytrait-for-usize-semicolon/13967 "2021-02-02T20:50:09Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![danii](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/danii/32/7727_2.png) [@danii](https://internals.rust-lang.org/u/danii)\
**Post date:** [February 2, 2021, 8:50pm UTC](https://internals.rust-lang.org/t/pre-rfc-trait-impl-blocks-without-bodies-impl-mytrait-for-usize-semicolon/13967/1 "2021-02-02T20:50:10Z")

</div>

I have had this small syntax change idea for a while that would make `trait` & `impl` blocks more inline with `struct`s. This change would be _purely_ a syntaxual change, and wouldn't change any semantics about the language. The motivation I have is that this change would make the language feel just a little more consistent.

The change being... accepting `trait Trait` & `impl Trait for X` blocks, _without bodies_. Here's what that would look like, with some erroneous code.

```
// -----------------
// Before change...
// -----------------

/// My trait.
pub trait MyTrait {
    fn say_hi() {
        println!("Hi!")
    }
}

/// My trait implementation.
impl MyTrait for usize {}

/// My marker trait.
trait MyMarkerTrait {}

/// My marker trait blanket implementation.
impl<T> MyMarkerTrait for T
    where T: MyTrait {}

// -----------------
// After change...
// -----------------

/// My trait.
pub trait MyTrait {
    fn say_hi() {
        println!("Hi!")
    }
}

/// My trait implementation.
impl MyTrait for usize; // Semicolon here, because this implementation inherits from the default implementation on the trait.

/// My marker trait.
trait MyMarkerTrait; // Semicolon here, because MyMarkerTrait doesn't have any associated items.

/// My marker trait blanket implementation.
impl<T> MyMarkerTrait for T
    where T: MyTrait; // Semicolon here, again, because MyMarkerTrait doesn't have any associated items.

```

Omitting a body on `impl Trait for X` & `trait Trait` items is semantically exactly like providing an empty body. For example, this code will parse, but not compile.

```
trait MyTrait {
    fn implement_me();
}

impl MyTrait for usize; // Need to implement implement_me!

impl MyTrait for u8 {} // Same story here.

```

The only situation I don't think omitting a body should not be _allowed_ is on `impl Struct`s, because those types of empty implementations don't make any sense, since they don't associate the struct (or item) being implemented on with a trait. Of course, it could be added just for consistency sake, but it probably won't ever be used.

I don't expect this to gain much traction, but if it does, I suppose I'll find out.

---

<div class="post-metadata">

**Author:** ![scottmcm](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/scottmcm/32/2355_2.png) [@scottmcm](https://internals.rust-lang.org/u/scottmcm)\
**Post date:** [February 2, 2021, 8:54pm UTC](https://internals.rust-lang.org/t/pre-rfc-trait-impl-blocks-without-bodies-impl-mytrait-for-usize-semicolon/13967/3 "2021-02-02T20:54:42Z")

</div>

I'm certainly guilty of typing this occasionally, but it's not clear that `impl Marker for Bar;` instead of `impl Marker for Bar {}` is better enough to be worth having.

Looks like rustfmt doesn't even insist on

```rust
impl Marker for Bar {
}

```

so basically meh to the change -- maybe a nice structured hint in the error message, though.

Also, `struct Foo;` is different from `struct Foo {}` (and from `struct Foo();`), which makes it more worth-while there.

---

<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 3, 2021, 8:55pm UTC](https://internals.rust-lang.org/t/pre-rfc-trait-impl-blocks-without-bodies-impl-mytrait-for-usize-semicolon/13967/4 "2021-05-03T20:55:02Z")

</div>

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