Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Macros: Add a 'literal' fragment specifier #49835

Merged
merged 1 commit into from
May 13, 2018

Commits on May 13, 2018

  1. Macros: Add a 'literal' fragment specifier

    Implements RFC 1576.
    
    See: https://github.com/rust-lang/rfcs/blob/master/text/1576-macros-literal-matcher.md
    
    Changes are mostly in libsyntax, docs, and tests. Feature gate is
    enabled for 1.27.0.
    
    Many thanks to Vadim Petrochenkov for following through code reviews
    and suggestions.
    
    Example:
    
    ````rust
    
    macro_rules! test_literal {
        ($l:literal) => {
            println!("literal: {}", $l);
        };
        ($e:expr) => {
            println!("expr: {}", $e);
        };
    }
    
    fn main() {
        let a = 1;
        test_literal!(a);
        test_literal!(2);
        test_literal!(-3);
    }
    ```
    
    Output:
    
    ```
    expr: 1
    literal: 2
    literal: -3
    ```
    da-x committed May 13, 2018
    Configuration menu
    Copy the full SHA
    37ed2ab View commit details
    Browse the repository at this point in the history