Nonobvious char matching


#1

Hi there!

In short, why the heck is '\n' == '\t'true? That makes absolutely no sense to me.

From the documentation:

Tab is escaped as \t.
Carriage return is escaped as \r.
Line feed is escaped as \n.

This is super weird behavior to me. Can someone explain?
Here’s a link to the code in question: Playground


#2

It’s not.

fn main() {
    let definitely_false = '\n' == '\t';
    println!("definitely_false is: {:?}", definitely_false);
    assert!(definitely_false, "this is a panic message");
}

Outputs:

definitely_false is: false
thread 'main' panicked at 'this is a panic message', src/main.rs:5:5
note: Run with `RUST_BACKTRACE=1` for a backtrace.

You want assert_eq!.


#3

rofl well THAT makes a big difference!

Wow, thank you! >.<