1use super::*;
2
3pub fn verify(reader: &metadata::Reader) -> crate::Result<()> {
4 let unused: Vec<&str> = reader.unused().collect();
5
6 if !unused.is_empty() {
7 let mut message = "unused filters".to_string();
8
9 for unused in unused {
10 message.push_str(&format!("\n {unused}"));
11 }
12
13 return Err(crate::Error::new(&message));
14 }
15
16 for item in reader.items() {
17 // TODO: cover all variants
18 let metadata::Item::Type(def) = item else {
19 continue;
20 };
21
22 let generics = &metadata::type_def_generics(def);
23
24 def.fields().try_for_each(|field| not_type_ref(&field.ty(Some(def))))?;
25
26 def.methods().try_for_each(|method| {
27 let sig = method.signature(generics);
28 not_type_ref(&sig.return_type)?;
29
30 sig.params.iter().try_for_each(not_type_ref)
31 })?;
32 }
33
34 Ok(())
35}
36
37fn not_type_ref(ty: &metadata::Type) -> crate::Result<()> {
38 if let metadata::Type::TypeRef(ty: &TypeName) = ty {
39 return Err(crate::Error::new(&format!("missing type definition `{}`", ty)));
40 }
41 Ok(())
42}
43