]> git.lizzy.rs Git - rust.git/blob - src/librustc/middle/cstore.rs
Auto merge of #38712 - clarcharr:duration_sum, r=sfackler
[rust.git] / src / librustc / middle / cstore.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
12 // file at the top-level directory of this distribution and at
13 // http://rust-lang.org/COPYRIGHT.
14 //
15 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
16 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
17 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
18 // option. This file may not be copied, modified, or distributed
19 // except according to those terms.
20
21 // the rustc crate store interface. This also includes types that
22 // are *mostly* used as a part of that interface, but these should
23 // probably get a better home if someone can find one.
24
25 use hir::def::{self, Def};
26 use hir::def_id::{CrateNum, DefId, DefIndex};
27 use hir::map as hir_map;
28 use hir::map::definitions::{Definitions, DefKey, DisambiguatedDefPathData};
29 use hir::svh::Svh;
30 use middle::lang_items;
31 use ty::{self, Ty, TyCtxt};
32 use mir::Mir;
33 use session::Session;
34 use session::search_paths::PathKind;
35 use util::nodemap::{NodeSet, DefIdMap};
36
37 use std::collections::BTreeMap;
38 use std::path::PathBuf;
39 use std::rc::Rc;
40 use syntax::ast;
41 use syntax::attr;
42 use syntax::ext::base::SyntaxExtension;
43 use syntax::symbol::Symbol;
44 use syntax_pos::Span;
45 use rustc_back::target::Target;
46 use hir;
47 use rustc_back::PanicStrategy;
48
49 pub use self::NativeLibraryKind::{NativeStatic, NativeFramework, NativeUnknown};
50
51 // lonely orphan structs and enums looking for a better home
52
53 #[derive(Clone, Debug)]
54 pub struct LinkMeta {
55     pub crate_name: Symbol,
56     pub crate_hash: Svh,
57 }
58
59 // Where a crate came from on the local filesystem. One of these three options
60 // must be non-None.
61 #[derive(PartialEq, Clone, Debug)]
62 pub struct CrateSource {
63     pub dylib: Option<(PathBuf, PathKind)>,
64     pub rlib: Option<(PathBuf, PathKind)>,
65     pub rmeta: Option<(PathBuf, PathKind)>,
66 }
67
68 #[derive(RustcEncodable, RustcDecodable, Copy, Clone, Ord, PartialOrd, Eq, PartialEq, Debug)]
69 pub enum DepKind {
70     /// A dependency that is only used for its macros, none of which are visible from other crates.
71     /// These are included in the metadata only as placeholders and are ignored when decoding.
72     UnexportedMacrosOnly,
73     /// A dependency that is only used for its macros.
74     MacrosOnly,
75     /// A dependency that is always injected into the dependency list and so
76     /// doesn't need to be linked to an rlib, e.g. the injected allocator.
77     Implicit,
78     /// A dependency that is required by an rlib version of this crate.
79     /// Ordinary `extern crate`s result in `Explicit` dependencies.
80     Explicit,
81 }
82
83 impl DepKind {
84     pub fn macros_only(self) -> bool {
85         match self {
86             DepKind::UnexportedMacrosOnly | DepKind::MacrosOnly => true,
87             DepKind::Implicit | DepKind::Explicit => false,
88         }
89     }
90 }
91
92 #[derive(PartialEq, Clone, Debug)]
93 pub enum LibSource {
94     Some(PathBuf),
95     MetadataOnly,
96     None,
97 }
98
99 impl LibSource {
100     pub fn is_some(&self) -> bool {
101         if let LibSource::Some(_) = *self {
102             true
103         } else {
104             false
105         }
106     }
107
108     pub fn option(&self) -> Option<PathBuf> {
109         match *self {
110             LibSource::Some(ref p) => Some(p.clone()),
111             LibSource::MetadataOnly | LibSource::None => None,
112         }
113     }
114 }
115
116 #[derive(Copy, Debug, PartialEq, Clone, RustcEncodable, RustcDecodable)]
117 pub enum LinkagePreference {
118     RequireDynamic,
119     RequireStatic,
120 }
121
122 #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
123 pub enum NativeLibraryKind {
124     NativeStatic,    // native static library (.a archive)
125     NativeFramework, // OSX-specific
126     NativeUnknown,   // default way to specify a dynamic library
127 }
128
129 #[derive(Clone, Hash, RustcEncodable, RustcDecodable)]
130 pub struct NativeLibrary {
131     pub kind: NativeLibraryKind,
132     pub name: Symbol,
133     pub cfg: Option<ast::MetaItem>,
134     pub foreign_items: Vec<DefIndex>,
135 }
136
137 pub enum LoadedMacro {
138     MacroRules(ast::MacroDef),
139     ProcMacro(Rc<SyntaxExtension>),
140 }
141
142 #[derive(Copy, Clone, Debug)]
143 pub struct ExternCrate {
144     /// def_id of an `extern crate` in the current crate that caused
145     /// this crate to be loaded; note that there could be multiple
146     /// such ids
147     pub def_id: DefId,
148
149     /// span of the extern crate that caused this to be loaded
150     pub span: Span,
151
152     /// If true, then this crate is the crate named by the extern
153     /// crate referenced above. If false, then this crate is a dep
154     /// of the crate.
155     pub direct: bool,
156
157     /// Number of links to reach the extern crate `def_id`
158     /// declaration; used to select the extern crate with the shortest
159     /// path
160     pub path_len: usize,
161 }
162
163 /// A store of Rust crates, through with their metadata
164 /// can be accessed.
165 pub trait CrateStore<'tcx> {
166     // item info
167     fn describe_def(&self, def: DefId) -> Option<Def>;
168     fn def_span(&self, sess: &Session, def: DefId) -> Span;
169     fn stability(&self, def: DefId) -> Option<attr::Stability>;
170     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation>;
171     fn visibility(&self, def: DefId) -> ty::Visibility;
172     fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind;
173     fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
174                       -> ty::ClosureTy<'tcx>;
175     fn item_variances(&self, def: DefId) -> Vec<ty::Variance>;
176     fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
177                      -> Ty<'tcx>;
178     fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>>;
179     fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
180                            -> ty::GenericPredicates<'tcx>;
181     fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
182                                  -> ty::GenericPredicates<'tcx>;
183     fn item_generics<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
184                          -> ty::Generics<'tcx>;
185     fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute>;
186     fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef;
187     fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef;
188     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name>;
189     fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId>;
190
191     // trait info
192     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId>;
193
194     // impl info
195     fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId>;
196     fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
197                           -> Option<ty::TraitRef<'tcx>>;
198     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity;
199     fn custom_coerce_unsized_kind(&self, def: DefId)
200                                   -> Option<ty::adjustment::CustomCoerceUnsized>;
201     fn impl_parent(&self, impl_def_id: DefId) -> Option<DefId>;
202
203     // trait/impl-item info
204     fn trait_of_item(&self, def_id: DefId) -> Option<DefId>;
205     fn associated_item(&self, def: DefId) -> Option<ty::AssociatedItem>;
206
207     // flags
208     fn is_const_fn(&self, did: DefId) -> bool;
209     fn is_defaulted_trait(&self, did: DefId) -> bool;
210     fn is_default_impl(&self, impl_did: DefId) -> bool;
211     fn is_foreign_item(&self, did: DefId) -> bool;
212     fn is_dllimport_foreign_item(&self, def: DefId) -> bool;
213     fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool;
214     fn is_exported_symbol(&self, def_id: DefId) -> bool;
215
216     // crate metadata
217     fn dylib_dependency_formats(&self, cnum: CrateNum)
218                                     -> Vec<(CrateNum, LinkagePreference)>;
219     fn dep_kind(&self, cnum: CrateNum) -> DepKind;
220     fn export_macros(&self, cnum: CrateNum);
221     fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>;
222     fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>;
223     fn is_staged_api(&self, cnum: CrateNum) -> bool;
224     fn is_allocator(&self, cnum: CrateNum) -> bool;
225     fn is_panic_runtime(&self, cnum: CrateNum) -> bool;
226     fn is_compiler_builtins(&self, cnum: CrateNum) -> bool;
227     fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy;
228     fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate>;
229     /// The name of the crate as it is referred to in source code of the current
230     /// crate.
231     fn crate_name(&self, cnum: CrateNum) -> Symbol;
232     /// The name of the crate as it is stored in the crate's metadata.
233     fn original_crate_name(&self, cnum: CrateNum) -> Symbol;
234     fn crate_hash(&self, cnum: CrateNum) -> Svh;
235     fn crate_disambiguator(&self, cnum: CrateNum) -> Symbol;
236     fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
237     fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>;
238     fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>;
239     fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId>;
240     fn is_no_builtins(&self, cnum: CrateNum) -> bool;
241
242     // resolve
243     fn retrace_path(&self,
244                     cnum: CrateNum,
245                     path_data: &[DisambiguatedDefPathData])
246                     -> Option<DefId>;
247     fn def_key(&self, def: DefId) -> DefKey;
248     fn def_path(&self, def: DefId) -> hir_map::DefPath;
249     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name>;
250     fn item_children(&self, did: DefId) -> Vec<def::Export>;
251     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro;
252
253     // misc. metadata
254     fn maybe_get_item_body<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
255                                -> Option<&'tcx hir::Body>;
256     fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body>;
257     fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool;
258
259     fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> Mir<'tcx>;
260     fn is_item_mir_available(&self, def: DefId) -> bool;
261
262     // This is basically a 1-based range of ints, which is a little
263     // silly - I may fix that.
264     fn crates(&self) -> Vec<CrateNum>;
265     fn used_libraries(&self) -> Vec<NativeLibrary>;
266     fn used_link_args(&self) -> Vec<String>;
267
268     // utility functions
269     fn metadata_filename(&self) -> &str;
270     fn metadata_section_name(&self, target: &Target) -> &str;
271     fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>;
272     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource;
273     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum>;
274     fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
275                            reexports: &def::ExportMap,
276                            link_meta: &LinkMeta,
277                            reachable: &NodeSet) -> Vec<u8>;
278     fn metadata_encoding_version(&self) -> &[u8];
279 }
280
281 // FIXME: find a better place for this?
282 pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option<Span>) {
283     let mut err_count = 0;
284     {
285         let mut say = |s: &str| {
286             match (sp, sess) {
287                 (_, None) => bug!("{}", s),
288                 (Some(sp), Some(sess)) => sess.span_err(sp, s),
289                 (None, Some(sess)) => sess.err(s),
290             }
291             err_count += 1;
292         };
293         if s.is_empty() {
294             say("crate name must not be empty");
295         }
296         for c in s.chars() {
297             if c.is_alphanumeric() { continue }
298             if c == '_'  { continue }
299             say(&format!("invalid character `{}` in crate name: `{}`", c, s));
300         }
301     }
302
303     if err_count > 0 {
304         sess.unwrap().abort_if_errors();
305     }
306 }
307
308 /// A dummy crate store that does not support any non-local crates,
309 /// for test purposes.
310 pub struct DummyCrateStore;
311 #[allow(unused_variables)]
312 impl<'tcx> CrateStore<'tcx> for DummyCrateStore {
313     // item info
314     fn describe_def(&self, def: DefId) -> Option<Def> { bug!("describe_def") }
315     fn def_span(&self, sess: &Session, def: DefId) -> Span { bug!("def_span") }
316     fn stability(&self, def: DefId) -> Option<attr::Stability> { bug!("stability") }
317     fn deprecation(&self, def: DefId) -> Option<attr::Deprecation> { bug!("deprecation") }
318     fn visibility(&self, def: DefId) -> ty::Visibility { bug!("visibility") }
319     fn closure_kind(&self, def_id: DefId) -> ty::ClosureKind { bug!("closure_kind") }
320     fn closure_ty<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def_id: DefId)
321                       -> ty::ClosureTy<'tcx>  { bug!("closure_ty") }
322     fn item_variances(&self, def: DefId) -> Vec<ty::Variance> { bug!("item_variances") }
323     fn item_type<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
324                      -> Ty<'tcx> { bug!("item_type") }
325     fn visible_parent_map<'a>(&'a self) -> ::std::cell::RefMut<'a, DefIdMap<DefId>> {
326         bug!("visible_parent_map")
327     }
328     fn item_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
329                            -> ty::GenericPredicates<'tcx> { bug!("item_predicates") }
330     fn item_super_predicates<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
331                                  -> ty::GenericPredicates<'tcx> { bug!("item_super_predicates") }
332     fn item_generics<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
333                          -> ty::Generics<'tcx> { bug!("item_generics") }
334     fn item_attrs(&self, def_id: DefId) -> Vec<ast::Attribute> { bug!("item_attrs") }
335     fn trait_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)-> ty::TraitDef
336         { bug!("trait_def") }
337     fn adt_def<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId) -> &'tcx ty::AdtDef
338         { bug!("adt_def") }
339     fn fn_arg_names(&self, did: DefId) -> Vec<ast::Name> { bug!("fn_arg_names") }
340     fn inherent_implementations_for_type(&self, def_id: DefId) -> Vec<DefId> { vec![] }
341
342     // trait info
343     fn implementations_of_trait(&self, filter: Option<DefId>) -> Vec<DefId> { vec![] }
344
345     // impl info
346     fn associated_item_def_ids(&self, def_id: DefId) -> Vec<DefId>
347         { bug!("associated_items") }
348     fn impl_trait_ref<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
349                           -> Option<ty::TraitRef<'tcx>> { bug!("impl_trait_ref") }
350     fn impl_polarity(&self, def: DefId) -> hir::ImplPolarity { bug!("impl_polarity") }
351     fn custom_coerce_unsized_kind(&self, def: DefId)
352                                   -> Option<ty::adjustment::CustomCoerceUnsized>
353         { bug!("custom_coerce_unsized_kind") }
354     fn impl_parent(&self, def: DefId) -> Option<DefId> { bug!("impl_parent") }
355
356     // trait/impl-item info
357     fn trait_of_item(&self, def_id: DefId) -> Option<DefId> { bug!("trait_of_item") }
358     fn associated_item(&self, def: DefId) -> Option<ty::AssociatedItem> { bug!("associated_item") }
359
360     // flags
361     fn is_const_fn(&self, did: DefId) -> bool { bug!("is_const_fn") }
362     fn is_defaulted_trait(&self, did: DefId) -> bool { bug!("is_defaulted_trait") }
363     fn is_default_impl(&self, impl_did: DefId) -> bool { bug!("is_default_impl") }
364     fn is_foreign_item(&self, did: DefId) -> bool { bug!("is_foreign_item") }
365     fn is_dllimport_foreign_item(&self, id: DefId) -> bool { false }
366     fn is_statically_included_foreign_item(&self, def_id: DefId) -> bool { false }
367     fn is_exported_symbol(&self, def_id: DefId) -> bool { false }
368
369     // crate metadata
370     fn dylib_dependency_formats(&self, cnum: CrateNum)
371                                     -> Vec<(CrateNum, LinkagePreference)>
372         { bug!("dylib_dependency_formats") }
373     fn lang_items(&self, cnum: CrateNum) -> Vec<(DefIndex, usize)>
374         { bug!("lang_items") }
375     fn missing_lang_items(&self, cnum: CrateNum) -> Vec<lang_items::LangItem>
376         { bug!("missing_lang_items") }
377     fn is_staged_api(&self, cnum: CrateNum) -> bool { bug!("is_staged_api") }
378     fn dep_kind(&self, cnum: CrateNum) -> DepKind { bug!("is_explicitly_linked") }
379     fn export_macros(&self, cnum: CrateNum) { bug!("export_macros") }
380     fn is_allocator(&self, cnum: CrateNum) -> bool { bug!("is_allocator") }
381     fn is_panic_runtime(&self, cnum: CrateNum) -> bool { bug!("is_panic_runtime") }
382     fn is_compiler_builtins(&self, cnum: CrateNum) -> bool { bug!("is_compiler_builtins") }
383     fn panic_strategy(&self, cnum: CrateNum) -> PanicStrategy {
384         bug!("panic_strategy")
385     }
386     fn extern_crate(&self, cnum: CrateNum) -> Option<ExternCrate> { bug!("extern_crate") }
387     fn crate_name(&self, cnum: CrateNum) -> Symbol { bug!("crate_name") }
388     fn original_crate_name(&self, cnum: CrateNum) -> Symbol {
389         bug!("original_crate_name")
390     }
391     fn crate_hash(&self, cnum: CrateNum) -> Svh { bug!("crate_hash") }
392     fn crate_disambiguator(&self, cnum: CrateNum)
393                            -> Symbol { bug!("crate_disambiguator") }
394     fn plugin_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
395         { bug!("plugin_registrar_fn") }
396     fn derive_registrar_fn(&self, cnum: CrateNum) -> Option<DefId>
397         { bug!("derive_registrar_fn") }
398     fn native_libraries(&self, cnum: CrateNum) -> Vec<NativeLibrary>
399         { bug!("native_libraries") }
400     fn exported_symbols(&self, cnum: CrateNum) -> Vec<DefId> { bug!("exported_symbols") }
401     fn is_no_builtins(&self, cnum: CrateNum) -> bool { bug!("is_no_builtins") }
402
403     // resolve
404     fn retrace_path(&self,
405                     cnum: CrateNum,
406                     path_data: &[DisambiguatedDefPathData])
407                     -> Option<DefId> {
408         None
409     }
410
411     fn def_key(&self, def: DefId) -> DefKey { bug!("def_key") }
412     fn def_path(&self, def: DefId) -> hir_map::DefPath {
413         bug!("relative_def_path")
414     }
415     fn struct_field_names(&self, def: DefId) -> Vec<ast::Name> { bug!("struct_field_names") }
416     fn item_children(&self, did: DefId) -> Vec<def::Export> { bug!("item_children") }
417     fn load_macro(&self, did: DefId, sess: &Session) -> LoadedMacro { bug!("load_macro") }
418
419     // misc. metadata
420     fn maybe_get_item_body<'a>(&'tcx self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
421                                -> Option<&'tcx hir::Body> {
422         bug!("maybe_get_item_body")
423     }
424     fn item_body_nested_bodies(&self, def: DefId) -> BTreeMap<hir::BodyId, hir::Body> {
425         bug!("item_body_nested_bodies")
426     }
427     fn const_is_rvalue_promotable_to_static(&self, def: DefId) -> bool {
428         bug!("const_is_rvalue_promotable_to_static")
429     }
430
431     fn get_item_mir<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, def: DefId)
432                         -> Mir<'tcx> { bug!("get_item_mir") }
433     fn is_item_mir_available(&self, def: DefId) -> bool {
434         bug!("is_item_mir_available")
435     }
436
437     // This is basically a 1-based range of ints, which is a little
438     // silly - I may fix that.
439     fn crates(&self) -> Vec<CrateNum> { vec![] }
440     fn used_libraries(&self) -> Vec<NativeLibrary> { vec![] }
441     fn used_link_args(&self) -> Vec<String> { vec![] }
442
443     // utility functions
444     fn metadata_filename(&self) -> &str { bug!("metadata_filename") }
445     fn metadata_section_name(&self, target: &Target) -> &str { bug!("metadata_section_name") }
446     fn used_crates(&self, prefer: LinkagePreference) -> Vec<(CrateNum, LibSource)>
447         { vec![] }
448     fn used_crate_source(&self, cnum: CrateNum) -> CrateSource { bug!("used_crate_source") }
449     fn extern_mod_stmt_cnum(&self, emod_id: ast::NodeId) -> Option<CrateNum> { None }
450     fn encode_metadata<'a>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>,
451                            reexports: &def::ExportMap,
452                            link_meta: &LinkMeta,
453                            reachable: &NodeSet) -> Vec<u8> { vec![] }
454     fn metadata_encoding_version(&self) -> &[u8] { bug!("metadata_encoding_version") }
455 }
456
457 pub trait CrateLoader {
458     fn process_item(&mut self, item: &ast::Item, defs: &Definitions);
459     fn postprocess(&mut self, krate: &ast::Crate);
460 }