Skip to content

make type modifiers usable for macro substitution #5748

@metajack

Description

@metajack
Contributor

Currently you can not pass @ or ~ or @mut to a macro by itself, but this would be useful in a few cases. I tried doing this to add Clone trait implementations without copying the code:

macro_rules! ptr_clone_impl(
    ($p:something) => {
        impl<T:Clone> Clone for $p T {
            #[inline(always)]
            fn clone(&self) -> $p T { $p (**self).clone() }
        }
    }
)

ptr_clone_impl!(~)
ptr_clone_impl!(@)
ptr_clone_impl!(@mut)

But as far as I can tell there is no fragment specifier that will work for those tokens.

Activity

bstrie

bstrie commented on May 28, 2013

@bstrie
Contributor

I know that @pcwalton has been interested in making ~ and @ act just like any other type, so perhaps this is worth supporting (assuming that user-defined types would normally be valid in this context).

pnkfelix

pnkfelix commented on May 28, 2013

@pnkfelix
Member

~ and @ are type-constructors, not types, no? (Still, it might be sense to add support for them to the macro-system. I.e. have some way to pass around these type -> type operators.)

catamorphism

catamorphism commented on Aug 5, 2013

@catamorphism
Contributor

Bug triage: doesn't look like a release blocker to me.

emberian

emberian commented on Jan 6, 2014

@emberian
Member

cc @jbclements

I feel like this is tricky, although it shouldn't be too hard for just the sigils.

emberian

emberian commented on Jul 29, 2014

@emberian
Member

Now that we have box and have removed those other types, this doesn't make quite as much sense. Once box itself infers the boxed-type this shouldn't be necessary. What's missing is to be able to have something like type level functions... I have Box, I want to apply it to T to get Box<T>, but our syntax doesn't really make that convenient.

Just some scattered thoughts..

rust-highfive

rust-highfive commented on Sep 24, 2014

@rust-highfive
Contributor

This issue has been moved to the RFCs repo: rust-lang/rfcs#285

added a commit that references this issue on Jul 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-syntaxextArea: Syntax extensions

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @metajack@pnkfelix@catamorphism@emberian@bstrie

        Issue actions

          make type modifiers usable for macro substitution · Issue #5748 · rust-lang/rust