Skip to content
This repository was archived by the owner on Oct 6, 2024. It is now read-only.
This repository was archived by the owner on Oct 6, 2024. It is now read-only.

Inconsistent expression precedence when using camel #94

Closed
@9uapaw

Description

@9uapaw

Hey! I have encountered an edge case with a surprising behavior. When using an expression in a macro along with camel and using a unary operator on the expression, the parentheses are eliminated resulting in a faulty short circuit.
Reproducible with:
paste = 1.0.12
rustc = 1.68.0

macro_rules! test {
    ($($name:ident $pred:expr),*) => {
        paste::paste! {
            $(
                if !$pred {
                    let camel = [<$name:camel>]::new();
                    println!("{}", $pred);
                }
            )*
        }
    }
}

fn main() {
    test!(String false || true);
}

Expanded to the following via cargo expand:

fn main() {
    if !false || true {
        let camel = String::new();
        {
            ::std::io::_print(format_args!("{0}\n", false || true));
        };
    }
}

Whereas without using camel it expands to:

fn main() {
    if !(false || true) {
        {
            ::std::io::_print(format_args!("{0}\n", false || true));
        };
    }
} 

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions