]> git.lizzy.rs Git - rust.git/blob - src/librustc/lib.rs
rustc: move the formatter into ty::print::PrintCx.
[rust.git] / src / librustc / lib.rs
1 //! The "main crate" of the Rust compiler. This crate contains common
2 //! type definitions that are used by the other crates in the rustc
3 //! "family". Some prominent examples (note that each of these modules
4 //! has their own README with further details).
5 //!
6 //! - **HIR.** The "high-level (H) intermediate representation (IR)" is
7 //!   defined in the `hir` module.
8 //! - **MIR.** The "mid-level (M) intermediate representation (IR)" is
9 //!   defined in the `mir` module. This module contains only the
10 //!   *definition* of the MIR; the passes that transform and operate
11 //!   on MIR are found in `librustc_mir` crate.
12 //! - **Types.** The internal representation of types used in rustc is
13 //!   defined in the `ty` module. This includes the **type context**
14 //!   (or `tcx`), which is the central context during most of
15 //!   compilation, containing the interners and other things.
16 //! - **Traits.** Trait resolution is implemented in the `traits` module.
17 //! - **Type inference.** The type inference code can be found in the `infer` module;
18 //!   this code handles low-level equality and subtyping operations. The
19 //!   type check pass in the compiler is found in the `librustc_typeck` crate.
20 //!
21 //! For more information about how rustc works, see the [rustc guide].
22 //!
23 //! [rustc guide]: https://rust-lang.github.io/rustc-guide/
24 //!
25 //! # Note
26 //!
27 //! This API is completely unstable and subject to change.
28
29 #![doc(html_root_url = "https://doc.rust-lang.org/nightly/")]
30
31 #![deny(rust_2018_idioms)]
32 #![allow(explicit_outlives_requirements)]
33
34 #![feature(arbitrary_self_types)]
35 #![feature(box_patterns)]
36 #![feature(box_syntax)]
37 #![feature(core_intrinsics)]
38 #![feature(drain_filter)]
39 #![cfg_attr(windows, feature(libc))]
40 #![feature(never_type)]
41 #![feature(exhaustive_patterns)]
42 #![feature(extern_types)]
43 #![feature(nll)]
44 #![feature(non_exhaustive)]
45 #![feature(proc_macro_internals)]
46 #![feature(optin_builtin_traits)]
47 #![feature(refcell_replace_swap)]
48 #![feature(rustc_diagnostic_macros)]
49 #![feature(rustc_attrs)]
50 #![feature(slice_patterns)]
51 #![feature(specialization)]
52 #![feature(unboxed_closures)]
53 #![feature(thread_local)]
54 #![feature(trace_macros)]
55 #![feature(trusted_len)]
56 #![feature(vec_remove_item)]
57 #![feature(step_trait)]
58 #![feature(stmt_expr_attributes)]
59 #![feature(integer_atomics)]
60 #![feature(test)]
61 #![feature(in_band_lifetimes)]
62 #![feature(crate_visibility_modifier)]
63
64 #![recursion_limit="512"]
65
66 #[macro_use] extern crate bitflags;
67 extern crate getopts;
68 #[macro_use] extern crate lazy_static;
69 #[macro_use] extern crate scoped_tls;
70 #[cfg(windows)]
71 extern crate libc;
72 #[macro_use] extern crate rustc_data_structures;
73
74 #[macro_use] extern crate log;
75 #[macro_use] extern crate syntax;
76
77 // FIXME: This import is used by deriving `RustcDecodable` and `RustcEncodable`. Removing this
78 // results in a bunch of "failed to resolve" errors. Hopefully, the compiler moves to serde or
79 // something, and we can get rid of this.
80 #[allow(rust_2018_idioms)]
81 extern crate serialize as rustc_serialize;
82
83 #[macro_use] extern crate smallvec;
84
85 // Note that librustc doesn't actually depend on these crates, see the note in
86 // `Cargo.toml` for this crate about why these are here.
87 #[allow(unused_extern_crates)]
88 extern crate flate2;
89 #[allow(unused_extern_crates)]
90 extern crate test;
91
92 #[macro_use]
93 mod macros;
94
95 // N.B., this module needs to be declared first so diagnostics are
96 // registered before they are used.
97 pub mod diagnostics;
98
99 pub mod cfg;
100 pub mod dep_graph;
101 pub mod hir;
102 pub mod ich;
103 pub mod infer;
104 pub mod lint;
105
106 pub mod middle {
107     pub mod allocator;
108     pub mod borrowck;
109     pub mod expr_use_visitor;
110     pub mod cstore;
111     pub mod dead;
112     pub mod dependency_format;
113     pub mod entry;
114     pub mod exported_symbols;
115     pub mod free_region;
116     pub mod intrinsicck;
117     pub mod lib_features;
118     pub mod lang_items;
119     pub mod liveness;
120     pub mod mem_categorization;
121     pub mod privacy;
122     pub mod reachable;
123     pub mod region;
124     pub mod recursion_limit;
125     pub mod resolve_lifetime;
126     pub mod stability;
127     pub mod weak_lang_items;
128 }
129
130 pub mod mir;
131 pub mod session;
132 pub mod traits;
133 pub mod ty;
134
135 pub mod util {
136     pub mod captures;
137     pub mod common;
138     pub mod ppaux;
139     pub mod nodemap;
140     pub mod profiling;
141     pub mod bug;
142 }
143
144 // Allows macros to refer to this crate as `::rustc`
145 extern crate self as rustc;
146
147 // FIXME(#27438): right now the unit tests of librustc don't refer to any actual
148 //                functions generated in librustc_data_structures (all
149 //                references are through generic functions), but statics are
150 //                referenced from time to time. Due to this bug we won't
151 //                actually correctly link in the statics unless we also
152 //                reference a function, so be sure to reference a dummy
153 //                function.
154 #[test]
155 fn noop() {
156     rustc_data_structures::__noop_fix_for_27438();
157 }
158
159
160 // Build the diagnostics array at the end so that the metadata includes error use sites.
161 __build_diagnostic_array! { librustc, DIAGNOSTICS }