# Allow "(" and "!" to follow path fragment in macro

**URL:** https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796
**Category:** language design
**Created:** [June 24, 2018, 11:55pm UTC](https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796 "2018-06-24T23:55:30Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![tmccombs](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tmccombs/32/1845_2.png) [@tmccombs](https://internals.rust-lang.org/u/tmccombs)
#### Post date: [June 24, 2018, 11:55pm UTC](https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796/1 "2018-06-24T23:55:30Z")

</div>

I recently tried to write a pipe macro that looked something like this:

```rust
macro_rules! pipe {
    ($it:expr,) => { $it };
    ($it:expr) => { $it };
    ($it:expr, $f:path($args:tt) $rest:tt) => {
        pipe!($f($it, $args), $rest)
    };
    ($it:expr, $m:path!($args:tt) $rest:tt) => {
        let it = $it;
        pipe!($m!:(it, $args), $rest)
    };
}

```

which would allow you to write something like:

```rust
pipe!(item, foo(1,2) bar!("hi") a::b::baz())

```

that would expand to

```rust
a::b::baz(bar!(foo(item, 1, 2), "hi"))

```

but to my chagrin I discovered that neither “(” nor “!” are allowed to follow a path. I either have to use `ident` instead, which would require the user to `use` any functions (and macros in 2018 edition), and could possibly not work at all for some situations involving generics, or add one of the legal tokens between the path and the argument list, which isn’t very natural from the user’s point of view.

ex:

```rust
pipe!(item, foo|(1,2) bar|!("hi") a::b::baz|())

```

Is there a compelling reason not to allow ! or ( after a path? As far as I know, those aren’t legal characters in a path fragment.

---

<div class="post-metadata">

### Author: ![dtolnay](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/dtolnay/32/1447_2.png) [@dtolnay](https://internals.rust-lang.org/u/dtolnay)
#### Post date: [June 25, 2018, 12:06am UTC](https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796/2 "2018-06-25T00:06:12Z")

</div>

A path can contain parentheses and exclamation marks.

```rust
macro_rules! path {
    ($p:path) => {};
}

fn main() {
    path!(Fn(A) -> !);
}

```

---

<div class="post-metadata">

### Author: ![tmccombs](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/tmccombs/32/1845_2.png) [@tmccombs](https://internals.rust-lang.org/u/tmccombs)
#### Post date: [June 25, 2018, 5:48am UTC](https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796/3 "2018-06-25T05:48:46Z")

</div>

oh. It seems rather surprising to me that `Fn(A) -> !` is a `path`. It seems like there should be a way to match against the name of a function in a function-call-like expression, if `path` isn’t the right typ for that what is?

---

<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: [June 26, 2018, 2:38am UTC](https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796/4 "2018-06-26T02:38:25Z")

</div>

Well `Fn(A)->!` is a path because it’s actually sugar for (the unstable) `std::ops::Fn<(A,), Output=!>`.

---

<div class="post-metadata">

### Author: ![ExpHP](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/exphp/32/6208_2.png) [@ExpHP](https://internals.rust-lang.org/u/ExpHP)
#### Post date: [June 26, 2018, 11:08pm UTC](https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796/5 "2018-06-26T23:08:56Z")

</div>

> [@tmccombs](#):
>
> if `path` isn’t the right typ for that what is?

I'm afraid it's spelled

```toml
proc-macro = true

[dependencies]
syn = { version = "0.14", features = ["full"] }

```

where I believe the best equivalent is [`ExprPath`](https://docs.rs/syn/0.14.2/syn/struct.ExprPath.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: [March 25, 2019, 8:30am UTC](https://internals.rust-lang.org/t/allow-and-to-follow-path-fragment-in-macro/7796/6 "2019-03-25T08:30:25Z")

</div>

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