1 //! Validates all used crates and extern libraries and loads their metadata
3 use crate::cstore::CStore;
4 use crate::locator::{CrateLocator, CratePaths};
5 use crate::rmeta::{CrateMetadata, CrateNumMap, CrateRoot, CrateDep, MetadataBlob};
7 use rustc::hir::def_id::CrateNum;
8 use rustc_data_structures::svh::Svh;
9 use rustc::middle::cstore::DepKind;
10 use rustc::session::{Session, CrateDisambiguator};
11 use rustc::session::config::{Sanitizer, self};
12 use rustc_target::spec::{PanicStrategy, TargetTriple};
13 use rustc::session::search_paths::PathKind;
14 use rustc::middle::cstore::{CrateSource, ExternCrate, ExternCrateSource, MetadataLoaderDyn};
15 use rustc::util::nodemap::FxHashSet;
16 use rustc::hir::map::Definitions;
17 use rustc::hir::def_id::LOCAL_CRATE;
24 use syntax::expand::allocator::{global_allocator_spans, AllocatorKind};
25 use syntax::symbol::{Symbol, sym};
26 use syntax::span_fatal;
27 use syntax_pos::{Span, DUMMY_SP};
28 use log::{debug, info, log_enabled};
29 use proc_macro::bridge::client::ProcMacro;
31 use rustc_error_codes::*;
33 crate struct Library {
34 pub source: CrateSource,
35 pub metadata: MetadataBlob,
38 pub struct CrateLoader<'a> {
39 // Immutable configuration.
41 metadata_loader: &'a MetadataLoaderDyn,
42 local_crate_name: Symbol,
47 fn dump_crates(cstore: &CStore) {
48 info!("resolved crates:");
49 cstore.iter_crate_data(|cnum, data| {
50 info!(" name: {}", data.root.name);
51 info!(" cnum: {}", cnum);
52 info!(" hash: {}", data.root.hash);
53 info!(" reqd: {:?}", *data.dep_kind.lock());
54 let CrateSource { dylib, rlib, rmeta } = data.source.clone();
55 dylib.map(|dl| info!(" dylib: {}", dl.0.display()));
56 rlib.map(|rl| info!(" rlib: {}", rl.0.display()));
57 rmeta.map(|rl| info!(" rmeta: {}", rl.0.display()));
67 LocatorError(CrateLocator<'a>),
70 impl<'a> LoadError<'a> {
71 fn report(self) -> ! {
73 LoadError::LocatorError(locator) => locator.report_errs(),
78 impl<'a> CrateLoader<'a> {
81 metadata_loader: &'a MetadataLoaderDyn,
82 local_crate_name: &str,
87 local_crate_name: Symbol::intern(local_crate_name),
88 cstore: Default::default(),
92 pub fn cstore(&self) -> &CStore {
96 pub fn into_cstore(self) -> CStore {
100 fn existing_match(&self, name: Symbol, hash: Option<&Svh>, kind: PathKind)
101 -> Option<CrateNum> {
103 self.cstore.iter_crate_data(|cnum, data| {
104 if data.root.name != name { return }
107 Some(hash) if *hash == data.root.hash => { ret = Some(cnum); return }
112 // When the hash is None we're dealing with a top-level dependency
113 // in which case we may have a specification on the command line for
114 // this library. Even though an upstream library may have loaded
115 // something of the same name, we have to make sure it was loaded
116 // from the exact same location as well.
118 // We're also sure to compare *paths*, not actual byte slices. The
119 // `source` stores paths which are normalized which may be different
120 // from the strings on the command line.
121 let source = &self.cstore.get_crate_data(cnum).source;
122 if let Some(entry) = self.sess.opts.externs.get(&name.as_str()) {
123 // Only use `--extern crate_name=path` here, not `--extern crate_name`.
124 let found = entry.locations.iter().filter_map(|l| l.as_ref()).any(|l| {
125 let l = fs::canonicalize(l).ok();
126 source.dylib.as_ref().map(|p| &p.0) == l.as_ref() ||
127 source.rlib.as_ref().map(|p| &p.0) == l.as_ref()
135 // Alright, so we've gotten this far which means that `data` has the
136 // right name, we don't have a hash, and we don't have a --extern
137 // pointing for ourselves. We're still not quite yet done because we
138 // have to make sure that this crate was found in the crate lookup
139 // path (this is a top-level dependency) as we don't want to
140 // implicitly load anything inside the dependency lookup path.
141 let prev_kind = source.dylib.as_ref().or(source.rlib.as_ref())
142 .or(source.rmeta.as_ref())
143 .expect("No sources for crate").1;
144 if kind.matches(prev_kind) {
151 fn verify_no_symbol_conflicts(&self,
153 root: &CrateRoot<'_>) {
154 // Check for (potential) conflicts with the local crate
155 if self.local_crate_name == root.name &&
156 self.sess.local_crate_disambiguator() == root.disambiguator {
157 span_fatal!(self.sess, span, E0519,
158 "the current crate is indistinguishable from one of its \
159 dependencies: it has the same crate-name `{}` and was \
160 compiled with the same `-C metadata` arguments. This \
161 will result in symbol conflicts between the two.",
165 // Check for conflicts with any crate loaded so far
166 self.cstore.iter_crate_data(|_, other| {
167 if other.root.name == root.name && // same crate-name
168 other.root.disambiguator == root.disambiguator && // same crate-disambiguator
169 other.root.hash != root.hash { // but different SVH
170 span_fatal!(self.sess, span, E0523,
171 "found two different crates with name `{}` that are \
172 not distinguished by differing `-C metadata`. This \
173 will result in symbol conflicts between the two.",
181 host_lib: Option<Library>,
182 root: Option<&CratePaths>,
188 let _prof_timer = self.sess.prof.generic_activity("metadata_register_crate");
190 let Library { source, metadata } = lib;
191 let crate_root = metadata.get_root();
192 let host_hash = host_lib.as_ref().map(|lib| lib.metadata.get_root().hash);
193 self.verify_no_symbol_conflicts(span, &crate_root);
195 let private_dep = self.sess.opts.externs.get(&name.as_str())
196 .map(|e| e.is_private_dep)
199 info!("register crate `{}` (private_dep = {})", crate_root.name, private_dep);
201 // Claim this crate number and cache it
202 let cnum = self.cstore.alloc_new_crate_num();
204 // Maintain a reference to the top most crate.
205 // Stash paths for top-most crate locally if necessary.
207 let root = if let Some(root) = root {
210 crate_paths = CratePaths::new(crate_root.name, source.clone());
214 let cnum_map = self.resolve_crate_deps(root, &crate_root, &metadata, cnum, span, dep_kind);
216 let raw_proc_macros = if crate_root.is_proc_macro_crate() {
218 let (dlsym_source, dlsym_root) = match &host_lib {
220 (&host_lib.source, { temp_root = host_lib.metadata.get_root(); &temp_root }),
221 None => (&source, &crate_root),
223 let dlsym_dylib = dlsym_source.dylib.as_ref().expect("no dylib for a proc-macro crate");
224 Some(self.dlsym_proc_macros(&dlsym_dylib.0, dlsym_root.disambiguator, span))
229 self.cstore.set_crate_data(cnum, CrateMetadata::new(
245 fn load_proc_macro<'b>(
247 locator: &mut CrateLocator<'b>,
249 ) -> Option<(LoadResult, Option<Library>)>
253 // Use a new crate locator so trying to load a proc macro doesn't affect the error
255 let mut proc_macro_locator = locator.clone();
257 // Try to load a proc macro
258 proc_macro_locator.is_proc_macro = Some(true);
260 // Load the proc macro crate for the target
261 let (locator, target_result) = if self.sess.opts.debugging_opts.dual_proc_macros {
262 proc_macro_locator.reset();
263 let result = match self.load(&mut proc_macro_locator)? {
264 LoadResult::Previous(cnum) => return Some((LoadResult::Previous(cnum), None)),
265 LoadResult::Loaded(library) => Some(LoadResult::Loaded(library))
267 locator.hash = locator.host_hash;
268 // Use the locator when looking for the host proc macro crate, as that is required
269 // so we want it to affect the error message
272 (&mut proc_macro_locator, None)
275 // Load the proc macro crate for the host
278 locator.is_proc_macro = Some(true);
279 locator.target = &self.sess.host;
280 locator.triple = TargetTriple::from_triple(config::host_triple());
281 locator.filesearch = self.sess.host_filesearch(path_kind);
283 let host_result = self.load(locator)?;
285 Some(if self.sess.opts.debugging_opts.dual_proc_macros {
286 let host_result = match host_result {
287 LoadResult::Previous(..) => {
288 panic!("host and target proc macros must be loaded in lock-step")
290 LoadResult::Loaded(library) => library
292 (target_result.unwrap(), Some(host_result))
298 fn resolve_crate<'b>(
303 dep: Option<(&'b CratePaths, &'b CrateDep)>,
305 self.maybe_resolve_crate(name, span, dep_kind, dep).unwrap_or_else(|err| err.report())
308 fn maybe_resolve_crate<'b>(
312 mut dep_kind: DepKind,
313 dep: Option<(&'b CratePaths, &'b CrateDep)>,
314 ) -> Result<CrateNum, LoadError<'b>> {
315 info!("resolving crate `{}`", name);
316 let (root, hash, host_hash, extra_filename, path_kind) = match dep {
317 Some((root, dep)) => (
320 dep.host_hash.as_ref(),
321 Some(&dep.extra_filename[..]),
324 None => (None, None, None, None, PathKind::Crate),
326 let result = if let Some(cnum) = self.existing_match(name, hash, path_kind) {
327 (LoadResult::Previous(cnum), None)
329 info!("falling back to a load");
330 let mut locator = CrateLocator::new(
332 self.metadata_loader,
341 Some(false), // is_proc_macro
344 self.load(&mut locator).map(|r| (r, None)).or_else(|| {
345 dep_kind = DepKind::UnexportedMacrosOnly;
346 self.load_proc_macro(&mut locator, path_kind)
347 }).ok_or_else(move || LoadError::LocatorError(locator))?
351 (LoadResult::Previous(cnum), None) => {
352 let data = self.cstore.get_crate_data(cnum);
353 if data.root.is_proc_macro_crate() {
354 dep_kind = DepKind::UnexportedMacrosOnly;
356 data.dep_kind.with_lock(|data_dep_kind| {
357 *data_dep_kind = cmp::max(*data_dep_kind, dep_kind);
361 (LoadResult::Loaded(library), host_library) => {
362 Ok(self.register_crate(host_library, root, span, library, dep_kind, name))
368 fn load(&self, locator: &mut CrateLocator<'_>) -> Option<LoadResult> {
369 let library = locator.maybe_load_library_crate()?;
371 // In the case that we're loading a crate, but not matching
372 // against a hash, we could load a crate which has the same hash
373 // as an already loaded crate. If this is the case prevent
374 // duplicates by just using the first crate.
376 // Note that we only do this for target triple crates, though, as we
377 // don't want to match a host crate against an equivalent target one
379 let root = library.metadata.get_root();
380 if locator.triple == self.sess.opts.target_triple {
381 let mut result = LoadResult::Loaded(library);
382 self.cstore.iter_crate_data(|cnum, data| {
383 if data.root.name == root.name && root.hash == data.root.hash {
384 assert!(locator.hash.is_none());
385 info!("load success, going to previous cnum: {}", cnum);
386 result = LoadResult::Previous(cnum);
391 Some(LoadResult::Loaded(library))
395 fn update_extern_crate(&self,
397 mut extern_crate: ExternCrate,
398 visited: &mut FxHashSet<(CrateNum, bool)>)
400 if !visited.insert((cnum, extern_crate.is_direct())) { return }
402 let cmeta = self.cstore.get_crate_data(cnum);
403 if cmeta.update_extern_crate(extern_crate) {
404 // Propagate the extern crate info to dependencies.
405 extern_crate.dependency_of = cnum;
406 for &dep_cnum in cmeta.dependencies().iter() {
407 self.update_extern_crate(dep_cnum, extern_crate, visited);
412 // Go through the crate metadata and load any crates that it references
413 fn resolve_crate_deps(&mut self,
415 crate_root: &CrateRoot<'_>,
416 metadata: &MetadataBlob,
421 debug!("resolving deps of external crate");
422 if crate_root.is_proc_macro_crate() {
423 return CrateNumMap::new();
426 // The map from crate numbers in the crate we're resolving to local crate numbers.
427 // We map 0 and all other holes in the map to our parent crate. The "additional"
428 // self-dependencies should be harmless.
429 std::iter::once(krate).chain(crate_root.decode_crate_deps(metadata).map(|dep| {
430 info!("resolving dep crate {} hash: `{}` extra filename: `{}`", dep.name, dep.hash,
432 if dep.kind == DepKind::UnexportedMacrosOnly {
435 let dep_kind = match dep_kind {
436 DepKind::MacrosOnly => DepKind::MacrosOnly,
439 self.resolve_crate(dep.name, span, dep_kind, Some((root, &dep)))
443 fn dlsym_proc_macros(&self,
445 disambiguator: CrateDisambiguator,
447 ) -> &'static [ProcMacro] {
449 use crate::dynamic_lib::DynamicLibrary;
451 // Make sure the path contains a / or the linker will search for it.
452 let path = env::current_dir().unwrap().join(path);
453 let lib = match DynamicLibrary::open(Some(&path)) {
455 Err(err) => self.sess.span_fatal(span, &err),
458 let sym = self.sess.generate_proc_macro_decls_symbol(disambiguator);
460 let sym = match lib.symbol(&sym) {
462 Err(err) => self.sess.span_fatal(span, &err),
464 *(sym as *const &[ProcMacro])
467 // Intentionally leak the dynamic library. We can't ever unload it
468 // since the library can make things that will live arbitrarily long.
469 std::mem::forget(lib);
474 fn inject_panic_runtime(&mut self, krate: &ast::Crate) {
475 // If we're only compiling an rlib, then there's no need to select a
476 // panic runtime, so we just skip this section entirely.
477 let any_non_rlib = self.sess.crate_types.borrow().iter().any(|ct| {
478 *ct != config::CrateType::Rlib
481 info!("panic runtime injection skipped, only generating rlib");
482 self.cstore.injected_panic_runtime = None;
486 // If we need a panic runtime, we try to find an existing one here. At
487 // the same time we perform some general validation of the DAG we've got
488 // going such as ensuring everything has a compatible panic strategy.
490 // The logic for finding the panic runtime here is pretty much the same
491 // as the allocator case with the only addition that the panic strategy
492 // compilation mode also comes into play.
493 let desired_strategy = self.sess.panic_strategy();
494 let mut runtime_found = false;
495 let mut needs_panic_runtime = attr::contains_name(&krate.attrs,
496 sym::needs_panic_runtime);
498 self.cstore.iter_crate_data(|cnum, data| {
499 needs_panic_runtime = needs_panic_runtime ||
500 data.root.needs_panic_runtime;
501 if data.root.panic_runtime {
502 // Inject a dependency from all #![needs_panic_runtime] to this
503 // #![panic_runtime] crate.
504 self.inject_dependency_if(cnum, "a panic runtime",
505 &|data| data.root.needs_panic_runtime);
506 runtime_found = runtime_found || *data.dep_kind.lock() == DepKind::Explicit;
510 // If an explicitly linked and matching panic runtime was found, or if
511 // we just don't need one at all, then we're done here and there's
512 // nothing else to do.
513 if !needs_panic_runtime || runtime_found {
514 self.cstore.injected_panic_runtime = None;
518 // By this point we know that we (a) need a panic runtime and (b) no
519 // panic runtime was explicitly linked. Here we just load an appropriate
520 // default runtime for our panic strategy and then inject the
523 // We may resolve to an already loaded crate (as the crate may not have
524 // been explicitly linked prior to this) and we may re-inject
525 // dependencies again, but both of those situations are fine.
527 // Also note that we have yet to perform validation of the crate graph
528 // in terms of everyone has a compatible panic runtime format, that's
529 // performed later as part of the `dependency_format` module.
530 let name = match desired_strategy {
531 PanicStrategy::Unwind => Symbol::intern("panic_unwind"),
532 PanicStrategy::Abort => Symbol::intern("panic_abort"),
534 info!("panic runtime not found -- loading {}", name);
536 let cnum = self.resolve_crate(name, DUMMY_SP, DepKind::Implicit, None);
537 let data = self.cstore.get_crate_data(cnum);
539 // Sanity check the loaded crate to ensure it is indeed a panic runtime
540 // and the panic strategy is indeed what we thought it was.
541 if !data.root.panic_runtime {
542 self.sess.err(&format!("the crate `{}` is not a panic runtime",
545 if data.root.panic_strategy != desired_strategy {
546 self.sess.err(&format!("the crate `{}` does not have the panic \
548 name, desired_strategy.desc()));
551 self.cstore.injected_panic_runtime = Some(cnum);
552 self.inject_dependency_if(cnum, "a panic runtime",
553 &|data| data.root.needs_panic_runtime);
556 fn inject_sanitizer_runtime(&mut self) {
557 if let Some(ref sanitizer) = self.sess.opts.debugging_opts.sanitizer {
558 // Sanitizers can only be used on some tested platforms with
559 // executables linked to `std`
560 const ASAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu",
561 "x86_64-apple-darwin"];
562 const TSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu",
563 "x86_64-apple-darwin"];
564 const LSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"];
565 const MSAN_SUPPORTED_TARGETS: &[&str] = &["x86_64-unknown-linux-gnu"];
567 let supported_targets = match *sanitizer {
568 Sanitizer::Address => ASAN_SUPPORTED_TARGETS,
569 Sanitizer::Thread => TSAN_SUPPORTED_TARGETS,
570 Sanitizer::Leak => LSAN_SUPPORTED_TARGETS,
571 Sanitizer::Memory => MSAN_SUPPORTED_TARGETS,
573 if !supported_targets.contains(&&*self.sess.opts.target_triple.triple()) {
574 self.sess.err(&format!("{:?}Sanitizer only works with the `{}` target",
576 supported_targets.join("` or `")
581 // firstyear 2017 - during testing I was unable to access an OSX machine
582 // to make this work on different crate types. As a result, today I have
583 // only been able to test and support linux as a target.
584 if self.sess.opts.target_triple.triple() == "x86_64-unknown-linux-gnu" {
585 if !self.sess.crate_types.borrow().iter().all(|ct| {
588 config::CrateType::Executable => true,
589 // This crate will be compiled with the required
590 // instrumentation pass
591 config::CrateType::Staticlib |
592 config::CrateType::Rlib |
593 config::CrateType::Dylib |
594 config::CrateType::Cdylib =>
597 self.sess.err(&format!("Only executables, staticlibs, \
598 cdylibs, dylibs and rlibs can be compiled with \
607 if !self.sess.crate_types.borrow().iter().all(|ct| {
610 config::CrateType::Executable => true,
611 // This crate will be compiled with the required
612 // instrumentation pass
613 config::CrateType::Rlib => false,
615 self.sess.err(&format!("Only executables and rlibs can be \
616 compiled with `-Z sanitizer`"));
625 let mut uses_std = false;
626 self.cstore.iter_crate_data(|_, data| {
627 if data.root.name == sym::std {
633 let name = Symbol::intern(match sanitizer {
634 Sanitizer::Address => "rustc_asan",
635 Sanitizer::Leak => "rustc_lsan",
636 Sanitizer::Memory => "rustc_msan",
637 Sanitizer::Thread => "rustc_tsan",
639 info!("loading sanitizer: {}", name);
641 let cnum = self.resolve_crate(name, DUMMY_SP, DepKind::Explicit, None);
642 let data = self.cstore.get_crate_data(cnum);
644 // Sanity check the loaded crate to ensure it is indeed a sanitizer runtime
645 if !data.root.sanitizer_runtime {
646 self.sess.err(&format!("the crate `{}` is not a sanitizer runtime",
650 self.sess.err("Must link std to be compiled with `-Z sanitizer`");
655 fn inject_profiler_runtime(&mut self) {
656 if self.sess.opts.debugging_opts.profile ||
657 self.sess.opts.cg.profile_generate.enabled()
659 info!("loading profiler");
661 let name = Symbol::intern("profiler_builtins");
662 let cnum = self.resolve_crate(name, DUMMY_SP, DepKind::Implicit, None);
663 let data = self.cstore.get_crate_data(cnum);
665 // Sanity check the loaded crate to ensure it is indeed a profiler runtime
666 if !data.root.profiler_runtime {
667 self.sess.err(&format!("the crate `profiler_builtins` is not \
668 a profiler runtime"));
673 fn inject_allocator_crate(&mut self, krate: &ast::Crate) {
674 let has_global_allocator = match &*global_allocator_spans(krate) {
675 [span1, span2, ..] => {
676 self.sess.struct_span_err(*span2, "cannot define multiple global allocators")
677 .span_label(*span2, "cannot define a new global allocator")
678 .span_label(*span1, "previous global allocator is defined here")
682 spans => !spans.is_empty()
684 self.sess.has_global_allocator.set(has_global_allocator);
686 // Check to see if we actually need an allocator. This desire comes
687 // about through the `#![needs_allocator]` attribute and is typically
688 // written down in liballoc.
689 let mut needs_allocator = attr::contains_name(&krate.attrs,
690 sym::needs_allocator);
691 self.cstore.iter_crate_data(|_, data| {
692 needs_allocator = needs_allocator || data.root.needs_allocator;
694 if !needs_allocator {
695 self.cstore.allocator_kind = None;
699 // At this point we've determined that we need an allocator. Let's see
700 // if our compilation session actually needs an allocator based on what
702 let all_rlib = self.sess.crate_types.borrow()
706 config::CrateType::Rlib => true,
711 self.cstore.allocator_kind = None;
715 // Ok, we need an allocator. Not only that but we're actually going to
716 // create an artifact that needs one linked in. Let's go find the one
717 // that we're going to link in.
719 // First up we check for global allocators. Look at the crate graph here
720 // and see what's a global allocator, including if we ourselves are a
722 let mut global_allocator = if has_global_allocator {
727 self.cstore.iter_crate_data(|_, data| {
728 if !data.root.has_global_allocator {
731 match global_allocator {
732 Some(Some(other_crate)) => {
733 self.sess.err(&format!("the `#[global_allocator]` in {} \
734 conflicts with this global \
740 self.sess.err(&format!("the `#[global_allocator]` in this \
741 crate conflicts with global \
742 allocator in: {}", data.root.name));
744 None => global_allocator = Some(Some(data.root.name)),
747 if global_allocator.is_some() {
748 self.cstore.allocator_kind = Some(AllocatorKind::Global);
752 // Ok we haven't found a global allocator but we still need an
753 // allocator. At this point our allocator request is typically fulfilled
754 // by the standard library, denoted by the `#![default_lib_allocator]`
756 let mut has_default = attr::contains_name(&krate.attrs, sym::default_lib_allocator);
757 self.cstore.iter_crate_data(|_, data| {
758 if data.root.has_default_lib_allocator {
764 self.sess.err("no global memory allocator found but one is \
765 required; link to std or \
766 add `#[global_allocator]` to a static item \
767 that implements the GlobalAlloc trait.");
769 self.cstore.allocator_kind = Some(AllocatorKind::DefaultLib);
772 fn inject_dependency_if(&self,
775 needs_dep: &dyn Fn(&CrateMetadata) -> bool) {
776 // don't perform this validation if the session has errors, as one of
777 // those errors may indicate a circular dependency which could cause
778 // this to stack overflow.
779 if self.sess.has_errors() {
783 // Before we inject any dependencies, make sure we don't inject a
784 // circular dependency by validating that this crate doesn't
785 // transitively depend on any crates satisfying `needs_dep`.
786 for dep in self.cstore.crate_dependencies_in_reverse_postorder(krate) {
787 let data = self.cstore.get_crate_data(dep);
788 if needs_dep(&data) {
789 self.sess.err(&format!("the crate `{}` cannot depend \
790 on a crate that needs {}, but \
792 self.cstore.get_crate_data(krate).root.name,
798 // All crates satisfying `needs_dep` do not explicitly depend on the
799 // crate provided for this compile, but in order for this compilation to
800 // be successfully linked we need to inject a dependency (to order the
801 // crates on the command line correctly).
802 self.cstore.iter_crate_data(|cnum, data| {
803 if !needs_dep(data) {
807 info!("injecting a dep from {} to {}", cnum, krate);
808 data.add_dependency(krate);
812 pub fn postprocess(&mut self, krate: &ast::Crate) {
813 self.inject_sanitizer_runtime();
814 self.inject_profiler_runtime();
815 self.inject_allocator_crate(krate);
816 self.inject_panic_runtime(krate);
818 if log_enabled!(log::Level::Info) {
819 dump_crates(&self.cstore);
823 pub fn process_extern_crate(
826 definitions: &Definitions,
829 ast::ItemKind::ExternCrate(orig_name) => {
830 debug!("resolving extern crate stmt. ident: {} orig_name: {:?}",
831 item.ident, orig_name);
832 let name = match orig_name {
834 crate::validate_crate_name(Some(self.sess), &orig_name.as_str(),
838 None => item.ident.name,
840 let dep_kind = if attr::contains_name(&item.attrs, sym::no_link) {
841 DepKind::UnexportedMacrosOnly
846 let cnum = self.resolve_crate(name, item.span, dep_kind, None);
848 let def_id = definitions.opt_local_def_id(item.id).unwrap();
849 let path_len = definitions.def_path(def_id.index).data.len();
850 self.update_extern_crate(
853 src: ExternCrateSource::Extern(def_id),
856 dependency_of: LOCAL_CRATE,
858 &mut FxHashSet::default(),
866 pub fn process_path_extern(&mut self, name: Symbol, span: Span) -> CrateNum {
867 let cnum = self.resolve_crate(name, span, DepKind::Explicit, None);
869 self.update_extern_crate(
872 src: ExternCrateSource::Path,
874 // to have the least priority in `update_extern_crate`
875 path_len: usize::max_value(),
876 dependency_of: LOCAL_CRATE,
878 &mut FxHashSet::default(),
884 pub fn maybe_process_path_extern(&mut self, name: Symbol, span: Span) -> Option<CrateNum> {
885 let cnum = self.maybe_resolve_crate(name, span, DepKind::Explicit, None).ok()?;
887 self.update_extern_crate(
890 src: ExternCrateSource::Path,
892 // to have the least priority in `update_extern_crate`
893 path_len: usize::max_value(),
894 dependency_of: LOCAL_CRATE,
896 &mut FxHashSet::default(),