--- a/src/yaml.rs
+++ b/src/yaml.rs
@@ -328,6 +328,7 @@
     Call(YAMLDecodingTrapFn),
 }
 
+#[cfg(feature = "encoding")]
 impl PartialEq for YAMLDecodingTrap {
     fn eq(&self, other: &YAMLDecodingTrap) -> bool {
         match (self, other) {
@@ -339,6 +340,7 @@
     }
 }
 
+#[cfg(feature = "encoding")]
 impl Eq for YAMLDecodingTrap {}
 
 /// `YamlDecoder` is a `YamlLoader` builder that allows you to supply your own encoding error trap.
@@ -855,8 +857,11 @@
 
 #[cfg(test)]
 mod test {
-    use super::{YAMLDecodingTrap, Yaml, YamlDecoder};
+    #[cfg(feature = "encoding")]
+    use super::{YAMLDecodingTrap, YamlDecoder};
+    use super::Yaml;
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_bom() {
         let s = b"\xef\xbb\xbf---
@@ -872,6 +877,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_utf16le() {
         let s = b"\xff\xfe-\x00-\x00-\x00
@@ -888,6 +894,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_utf16be() {
         let s = b"\xfe\xff\x00-\x00-\x00-\x00
@@ -904,6 +911,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_utf16le_nobom() {
         let s = b"-\x00-\x00-\x00
@@ -920,6 +928,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_trap() {
         let s = b"---
