# Request: dummy\_impl macro

**URL:** <https://internals.rust-lang.org/t/request-dummy-impl-macro/15091>\
**Category:** Uncategorized\
**Created:** [July 27, 2021, 10:57am UTC](https://internals.rust-lang.org/t/request-dummy-impl-macro/15091 "2021-07-27T10:57:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dhardy](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dhardy/32/2399_2.png) [@dhardy](https://internals.rust-lang.org/u/dhardy)\
**Post date:** [July 27, 2021, 10:57am UTC](https://internals.rust-lang.org/t/request-dummy-impl-macro/15091/1 "2021-07-27T10:57:03Z")

</div>

We can already use macros for a "dummy implementation" of an expression:

```rust
fn do_something_complex() -> T {
    todo!()
}

```

Now and again I've wanted a "dummy trait object". So:

```rust
trait T {
    type Q;
    fn ask(q: &Q) -> bool;
}

struct S;
dummy_impl!(T<Q = ()> for S);
// generates:
// impl T for S {
// type Q = ();
// fn ask(q: &Q) -> bool { todo!() }
// }

```

Here we specify `Q = ()`; in this example it is not strictly necessary but in cases where the associated type has trait bounds it may be.

The biggest issue: **macros can't do this** due to lack of introspection for the trait `T` (even with proc-macros).

So, questions:

- is such a thing possible with compiler built-ins?
- is it desirable enough to be worth it?
- should it be exposed in `std`?

Motivation:

- writing tests on bounded generic functions may require a concrete type
- writing the impl by hand can be tedious, especially if the trait is frequently modified

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [July 27, 2021, 11:07am UTC](https://internals.rust-lang.org/t/request-dummy-impl-macro/15091/2 "2021-07-27T11:07:53Z")

</div>

While I don't usually suggest "just use an IDE", it seems like, in this case, this might be the right solution?

![impl](https://us1.discourse-cdn.com/flex002/uploads/rustlang/original/2X/7/7e405bd96da01ecf9cd0db78f1bc600894ae4f68.gif)

---

<div class="post-metadata">

**Author:** ![H2CO3](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/h2co3/32/2849_2.png) [@H2CO3](https://internals.rust-lang.org/u/H2CO3)\
**Post date:** [July 27, 2021, 12:35pm UTC](https://internals.rust-lang.org/t/request-dummy-impl-macro/15091/3 "2021-07-27T12:35:16Z")

</div>

> [@dhardy](#):
>
> is such a thing possible with compiler built-ins?

Yes, probably.

> [@dhardy](#):
>
> is it desirable enough to be worth it?

No, probably.

Doesn't copy-pasting solve this, even if you don't use an IDE?

---

<div class="post-metadata">

**Author:** ![dhardy](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dhardy/32/2399_2.png) [@dhardy](https://internals.rust-lang.org/u/dhardy)\
**Post date:** [July 27, 2021, 12:39pm UTC](https://internals.rust-lang.org/t/request-dummy-impl-macro/15091/4 "2021-07-27T12:39:19Z")

</div>

In this particular case, I wanted to generate a dummy trait object for use in a doc test demonstrating usage that would be completely unrelated if not for a type bound. Wasting (hidden) lines on the doc-test and having to update them should the underlying trait change (likely) is undesirable.

Not a _big_ use-case, but copy+paste / IDE auto-complete don't actually solve it.

---

<div class="post-metadata">

**Author:** ![matklad](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/matklad/32/12266_2.png) [@matklad](https://internals.rust-lang.org/u/matklad)\
**Post date:** [July 27, 2021, 2:55pm UTC](https://internals.rust-lang.org/t/request-dummy-impl-macro/15091/5 "2021-07-27T14:55:35Z")

</div>

For that sepecific case, the following works

````rust
/// ```
/// # fn give_me_T<S: T>(S: S) {
/// your docs here
/// # }
/// ```

````

---

<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:** [October 25, 2021, 2:55pm UTC](https://internals.rust-lang.org/t/request-dummy-impl-macro/15091/6 "2021-10-25T14:55:49Z")

</div>

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