Skip to content

struct constructors are some kind of weird type/path hybrid #41740

Closed
@durka

Description

@durka

Is this a known issue?

Consider the following setup:

mod foo {
    pub struct Bar<T>(pub T);
}

You can construct a Bar:

let _ = foo::Bar::<i32>(42);

Now I want to try it with a macro.

macro_rules! construct {
    ($strukt:path, $val:expr) => {
        $strukt($val)
    }
}

The obvious thing doesn't parse at all:

let _ = construct!(foo::Bar::<i32>, 42); // ERROR
//                         ^ unexpected token `::`

We need to remove the second ::, which makes things inconsistent with the macro-less syntax:

let _ = construct!(foo::Bar<i32>, 42); // ok

Why this inconsistency? It seems like a struct constructor isn't really a path. But that's the only macro fragment that can be used in that position (besides ident and tt).

Metadata

Metadata

Assignees

Labels

A-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-parserArea: The lexing & parsing of Rust source code to an ASTC-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions