# Issue with ty in macro rules

**URL:** <https://internals.rust-lang.org/t/issue-with-ty-in-macro-rules/9367>\
**Category:** language design\
**Created:** [February 5, 2019, 1:41pm UTC](https://internals.rust-lang.org/t/issue-with-ty-in-macro-rules/9367 "2019-02-05T13:41:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Finn](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/finn/32/3841_2.png) [@Finn](https://internals.rust-lang.org/u/Finn)\
**Post date:** [February 5, 2019, 1:41pm UTC](https://internals.rust-lang.org/t/issue-with-ty-in-macro-rules/9367/1 "2019-02-05T13:41:14Z")

</div>

Consider an example where a type is to be plugged in as a part of an expression:

```rust
macro_rules! new {($t: ident) => {$t::new()};}

fn main() {
    let _: Vec<i32> = new!{Vec};
}

```

Actually we would like to use `ty` instead of `ident` or `tt`, but that is not possible. It has to be expressed this way:

```rust
macro_rules! new {($t: ty) => {<$t>::new()};}

fn main() {
    let _: Vec<i32> = new!{Vec<i32>};
}

```

But now it is not allowed to omit the type arguments altogether, i.e. it is not allowed to write `Vec` instead of `Vec<i32>` or `Vec<_>`.

Is there any specific reason why `$t::new()` should not be permitted for `$t: ty` or could we fix that?

---

<div class="post-metadata">

**Author:** ![kornel](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/kornel/32/2711_2.png) [@kornel](https://internals.rust-lang.org/u/kornel)\
**Post date:** [February 5, 2019, 2:13pm UTC](https://internals.rust-lang.org/t/issue-with-ty-in-macro-rules/9367/2 "2019-02-05T14:13:44Z")

</div>

Maybe you need `path` in this case?

I guess that if it’s a type, it has to be unambiguously representable as such in the ast, so an incomplete one isn’t?

[https://doc.rust-lang.org/1.0.0/syntax/ast/enum.Ty\_.html](https://doc.rust-lang.org/1.0.0/syntax/ast/enum.Ty_.html)

---

<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 6, 2019, 2:13pm UTC](https://internals.rust-lang.org/t/issue-with-ty-in-macro-rules/9367/3 "2019-05-06T14:13:49Z")

</div>

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