// `a == b` with a non-primitive left operand: the right operand is checked against a fresh // type (rustc op.rs check_overloaded_binop), so an instance does not make it the left type. // `x == &W(y.as_ref())` with x: &W compares W with W<&str> through // `impl PartialEq> for W` (unicase's Unicode / Ascii comparison, reached by // Scope through pulldown-cmark's UniCase). struct W(S); impl, S2: AsRef> PartialEq> for W { fn eq(&self, other: &W) -> bool { self.0.as_ref() == other.0.as_ref() } } struct Name(String); impl AsRef for Name { fn as_ref(&self) -> &str { &self.0 } } fn cmp_ref>(x: &W, y: &S) -> bool { x == &W(y.as_ref()) } fn cmp_val>(x: W, y: &S) -> bool { x == W(y.as_ref()) } #[test] fn rhs_is_not_the_left_type() { assert!(cmp_ref(&W(Name("a".into())), &Name("a".into()))); assert!(cmp_val(W(Name("a".into())), &Name("a".into()))); assert!(!cmp_ref(&W(Name("a".into())), &Name("b".into()))); } #[test] fn single_impl_still_types_literals() { let o: Option = Some(10); assert!(o == Some(10)); let v: Vec = vec![5, 6]; assert!(v == [5, 6]); let s = String::from("x"); assert!(s == "x"); }