Open
Description
I tried this code:
#[derive(PartialEq, Eq, Debug)]
struct SortedEdge {
a: usize,
b: usize,
}
impl SortedEdge {
fn new(a: usize, b: usize) -> SortedEdge {
if b > a {
SortedEdge { a, b }
} else {
// uh oh!
// We really want:
// SortedEdge { a: b, b: a }
SortedEdge { b, a }
}
}
}
fn main() {
let x = SortedEdge::new(1, 2);
let y = SortedEdge::new(2, 1);
// The points should be equal after sorting indicies
assert_eq!(x, y);
}
I expected to see this happen:
A compiler warning/diagnostic that both of my branches were equivalent.
Instead, this happened:
No warning was emitted
Meta
This happens on Rust 1.47.0 stable and Rust nightly 2020-11-18
CC @estebank, and the related discussion on twitter