--- a/src/yaml.rs
+++ b/src/yaml.rs
@@ -332,6 +332,7 @@
         Call(YAMLDecodingTrapFn),
     }
 
+    #[cfg(feature = "encoding")]
     impl PartialEq for YAMLDecodingTrap {
         fn eq(&self, other: &YAMLDecodingTrap) -> bool {
             match (self, other) {
@@ -343,6 +344,7 @@
         }
     }
 
+    #[cfg(feature = "encoding")]
     impl Eq for YAMLDecodingTrap {}
 
     /// `YamlDecoder` is a `YamlLoader` builder that allows you to supply your own encoding error trap.
@@ -865,8 +867,11 @@
 
 #[cfg(all(test, feature = "encoding"))]
 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---
@@ -882,6 +887,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_utf16le() {
         let s = b"\xff\xfe-\x00-\x00-\x00
@@ -898,6 +904,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_utf16be() {
         let s = b"\xfe\xff\x00-\x00-\x00-\x00
@@ -914,6 +921,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_utf16le_nobom() {
         let s = b"-\x00-\x00-\x00
@@ -930,6 +938,7 @@
         assert!(doc["d"][0].is_badvalue());
     }
 
+    #[cfg(feature = "encoding")]
     #[test]
     fn test_read_trap() {
         let s = b"---
