3 use utils::{get_trait_def_id, paths, span_lint};
5 /// **What it does:** Checks for mis-uses of the serde API.
7 /// **Why is this bad?** Serde is very finnicky about how its API should be
8 /// used, but the type system can't be used to enforce it (yet).
10 /// **Known problems:** None.
12 /// **Example:** Implementing `Visitor::visit_string` but not
13 /// `Visitor::visit_str`.
17 "various things that will negatively affect your serde experience"
21 #[derive(Copy, Clone)]
24 impl LintPass for Serde {
25 fn get_lints(&self) -> LintArray {
26 lint_array!(SERDE_API_MISUSE)
30 impl<'a, 'tcx> LateLintPass<'a, 'tcx> for Serde {
31 fn check_item(&mut self, cx: &LateContext<'a, 'tcx>, item: &'tcx Item) {
32 if let ItemImpl(_, _, _, _, Some(ref trait_ref), _, ref items) = item.node {
33 let did = trait_ref.path.def.def_id();
34 if let Some(visit_did) = get_trait_def_id(cx, &paths::SERDE_DE_VISITOR) {
36 let mut seen_str = None;
37 let mut seen_string = None;
39 match &*item.name.as_str() {
40 "visit_str" => seen_str = Some(item.span),
41 "visit_string" => seen_string = Some(item.span),
45 if let Some(span) = seen_string {
46 if seen_str.is_none() {
51 "you should not implement `visit_string` without also implementing `visit_str`",