(true, false) but 1 2 3 4?

What is going on here?

fn main(){
    println!("{:?}", (1<2,3>(4)))


1 is less than 2, 3 is not larger than 4.


If you run clippy (Rust's lintern), it will let you know about the unnecessary parentheses in your code, which would improve its readability.


Perhaps the missing piece here for the OP is that (a, b) creates a two-element tuple.


1 Like

When confused by something, it helps to explain specifically what you find confusing, as well as what you expected to happen instead. Otherwise, people are left to guess what you mean by "What is going on here?"

Looking at this question, I genuinely don't know what aspect of this code you're asking about.


This code looks like a simplification of the bastion-of-the-turbofish. It's not useful for anything.


That's an utterly useless question to ask. What is going on here is some logical expressions are getting printed.

What did you expect?

1<2 is an expression that evaluates to the boolean value true. So we have:


3>(4) is the same as 3>4 as the brackets are redundant. Which is a expression which evaluates to the boolean value false. So we have:


Which is a "tuple". That might be tricky if you have never used a language that had tuples. See: tuple - Rust.

Perhaps it's just me but I find such expressions easier to read if suitable spacing is used:

(1 < 2, 3 > (4))

Suggest using "rust fmt" or have your editor do the formatting.


This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.