Kaynağa Gözat

Disambiguate Display::fmt calls for error types

David Kellum 7 yıl önce
ebeveyn
işleme
8cc477f5d3
2 değiştirilmiş dosya ile 5 ekleme ve 4 silme
  1. 4 4
      src/parser.rs
  2. 1 0
      tests/unit.rs

+ 4 - 4
src/parser.rs

@@ -91,8 +91,8 @@ simple_enum_error! {
 }
 
 impl fmt::Display for ParseError {
-    fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
-        self.description().fmt(fmt)
+    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+        fmt::Display::fmt(self.description(), f)
     }
 }
 
@@ -151,8 +151,8 @@ syntax_violation_enum! {
 }
 
 impl fmt::Display for SyntaxViolation {
-    fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
-        self.description().fmt(fmt)
+    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+        fmt::Display::fmt(self.description(), f)
     }
 }
 

+ 1 - 0
tests/unit.rs

@@ -512,6 +512,7 @@ fn test_syntax_violation_callback() {
     let v = violation.take().unwrap();
     assert_eq!(v, ExpectedDoubleSlash);
     assert_eq!(v.description(), "expected //");
+    assert_eq!(v.to_string(), "expected //");
 }
 
 #[test]