+/// If the given def ID describes an item belonging to a trait,
+/// return the ID of the trait that the trait item belongs to.
+/// Otherwise, return `None`.
+fn trait_of_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId) -> Option<DefId> {
+ if def_id.krate != LOCAL_CRATE {
+ return None
+ }
+ tcx.opt_associated_item(def_id)
+ .and_then(|associated_item| {
+ match associated_item.container {
+ TraitContainer(def_id) => Some(def_id),
+ ImplContainer(_) => None
+ }
+ })
+}
+
+