2019-02-08 20:50:17 +09:00
|
|
|
use crate::index;
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
use rustc::hir;
|
2016-09-15 00:51:46 +03:00
|
|
|
use rustc::hir::def::{self, CtorKind};
|
2019-05-22 12:16:48 +03:00
|
|
|
use rustc::hir::def_id::{DefIndex, DefId};
|
2019-04-11 10:22:02 +03:00
|
|
|
use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
|
2018-02-10 14:28:17 -08:00
|
|
|
use rustc::middle::cstore::{DepKind, LinkagePreference, NativeLibrary, ForeignModule};
|
2016-09-16 17:25:54 +03:00
|
|
|
use rustc::middle::lang_items;
|
|
|
|
use rustc::mir;
|
2017-10-24 17:49:58 +02:00
|
|
|
use rustc::session::CrateDisambiguator;
|
2017-02-06 15:26:32 -05:00
|
|
|
use rustc::ty::{self, Ty, ReprOptions};
|
2017-12-08 21:18:21 +02:00
|
|
|
use rustc_target::spec::{PanicStrategy, TargetTriple};
|
2018-08-03 12:22:22 -06:00
|
|
|
use rustc_data_structures::svh::Svh;
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
use rustc_serialize as serialize;
|
|
|
|
use syntax::{ast, attr};
|
2018-05-13 03:50:39 +03:00
|
|
|
use syntax::edition::Edition;
|
2016-11-16 10:52:37 +00:00
|
|
|
use syntax::symbol::Symbol;
|
2016-09-16 17:25:54 +03:00
|
|
|
use syntax_pos::{self, Span};
|
|
|
|
|
|
|
|
use std::marker::PhantomData;
|
2017-04-05 13:00:17 +02:00
|
|
|
|
2016-09-30 16:24:50 -06:00
|
|
|
pub fn rustc_version() -> String {
|
2016-10-22 18:44:32 +05:30
|
|
|
format!("rustc {}",
|
|
|
|
option_env!("CFG_VERSION").unwrap_or("unknown version"))
|
2016-09-30 16:24:50 -06:00
|
|
|
}
|
2016-09-18 14:05:49 +03:00
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
/// Metadata encoding version.
|
2018-11-27 02:59:49 +00:00
|
|
|
/// N.B., increment this if you change the format of metadata such that
|
2016-11-22 14:51:55 +02:00
|
|
|
/// the rustc version can't be found to compare with `rustc_version()`.
|
|
|
|
pub const METADATA_VERSION: u8 = 4;
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
/// Metadata header which includes `METADATA_VERSION`.
|
|
|
|
/// To get older versions of rustc to ignore this metadata,
|
|
|
|
/// there are 4 zero bytes at the start, which are treated
|
|
|
|
/// as a length of 0 by old compilers.
|
|
|
|
///
|
2016-11-22 14:51:55 +02:00
|
|
|
/// This header is followed by the position of the `CrateRoot`,
|
|
|
|
/// which is encoded as a 32-bit big-endian unsigned integer,
|
|
|
|
/// and further followed by the rustc version string.
|
2018-12-04 12:46:10 +01:00
|
|
|
pub const METADATA_HEADER: &[u8; 12] =
|
2016-10-22 18:44:32 +05:30
|
|
|
&[0, 0, 0, 0, b'r', b'u', b's', b't', 0, 0, 0, METADATA_VERSION];
|
2016-09-16 17:25:54 +03:00
|
|
|
|
|
|
|
/// A value of type T referred to by its absolute position
|
|
|
|
/// in the metadata, and which can be decoded lazily.
|
2016-09-17 10:33:47 +03:00
|
|
|
///
|
|
|
|
/// Metadata is effective a tree, encoded in post-order,
|
|
|
|
/// and with the root's position written next to the header.
|
|
|
|
/// That means every single `Lazy` points to some previous
|
|
|
|
/// location in the metadata and is part of a larger node.
|
|
|
|
///
|
|
|
|
/// The first `Lazy` in a node is encoded as the backwards
|
|
|
|
/// distance from the position where the containing node
|
|
|
|
/// starts and where the `Lazy` points to, while the rest
|
|
|
|
/// use the forward distance from the previous `Lazy`.
|
|
|
|
/// Distances start at 1, as 0-byte nodes are invalid.
|
|
|
|
/// Also invalid are nodes being referred in a different
|
|
|
|
/// order than they were encoded in.
|
2016-09-16 17:25:54 +03:00
|
|
|
#[must_use]
|
|
|
|
pub struct Lazy<T> {
|
|
|
|
pub position: usize,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData<T>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Lazy<T> {
|
|
|
|
pub fn with_position(position: usize) -> Lazy<T> {
|
|
|
|
Lazy {
|
2017-08-06 22:54:09 -07:00
|
|
|
position,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-17 10:33:47 +03:00
|
|
|
|
|
|
|
/// Returns the minimum encoded size of a value of type `T`.
|
|
|
|
// FIXME(eddyb) Give better estimates for certain types.
|
|
|
|
pub fn min_size() -> usize {
|
|
|
|
1
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Copy for Lazy<T> {}
|
|
|
|
impl<T> Clone for Lazy<T> {
|
2016-10-22 18:44:32 +05:30
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> serialize::UseSpecializedEncodable for Lazy<T> {}
|
|
|
|
impl<T> serialize::UseSpecializedDecodable for Lazy<T> {}
|
|
|
|
|
|
|
|
/// A sequence of type T referred to by its absolute position
|
|
|
|
/// in the metadata and length, and which can be decoded lazily.
|
2016-09-17 10:33:47 +03:00
|
|
|
/// The sequence is a single node for the purposes of `Lazy`.
|
2016-09-16 17:25:54 +03:00
|
|
|
///
|
|
|
|
/// Unlike `Lazy<Vec<T>>`, the length is encoded next to the
|
|
|
|
/// position, not at the position, which means that the length
|
|
|
|
/// doesn't need to be known before encoding all the elements.
|
2016-09-17 10:33:47 +03:00
|
|
|
///
|
|
|
|
/// If the length is 0, no position is encoded, but otherwise,
|
|
|
|
/// the encoding is that of `Lazy`, with the distinction that
|
|
|
|
/// the minimal distance the length of the sequence, i.e.
|
|
|
|
/// it's assumed there's no 0-byte element in the sequence.
|
2016-09-16 17:25:54 +03:00
|
|
|
#[must_use]
|
|
|
|
pub struct LazySeq<T> {
|
|
|
|
pub len: usize,
|
|
|
|
pub position: usize,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData<T>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> LazySeq<T> {
|
|
|
|
pub fn empty() -> LazySeq<T> {
|
|
|
|
LazySeq::with_position_and_length(0, 0)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn with_position_and_length(position: usize, len: usize) -> LazySeq<T> {
|
|
|
|
LazySeq {
|
2017-08-06 22:54:09 -07:00
|
|
|
len,
|
|
|
|
position,
|
2016-10-22 18:44:32 +05:30
|
|
|
_marker: PhantomData,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
2016-09-17 10:33:47 +03:00
|
|
|
|
|
|
|
/// Returns the minimum encoded size of `length` values of type `T`.
|
|
|
|
pub fn min_size(length: usize) -> usize {
|
|
|
|
length
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> Copy for LazySeq<T> {}
|
|
|
|
impl<T> Clone for LazySeq<T> {
|
2016-10-22 18:44:32 +05:30
|
|
|
fn clone(&self) -> Self {
|
|
|
|
*self
|
|
|
|
}
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<T> serialize::UseSpecializedEncodable for LazySeq<T> {}
|
|
|
|
impl<T> serialize::UseSpecializedDecodable for LazySeq<T> {}
|
|
|
|
|
2016-09-17 10:33:47 +03:00
|
|
|
/// Encoding / decoding state for `Lazy` and `LazySeq`.
|
|
|
|
#[derive(Copy, Clone, PartialEq, Eq, Debug)]
|
|
|
|
pub enum LazyState {
|
|
|
|
/// Outside of a metadata node.
|
|
|
|
NoNode,
|
|
|
|
|
|
|
|
/// Inside a metadata node, and before any `Lazy` or `LazySeq`.
|
|
|
|
/// The position is that of the node itself.
|
|
|
|
NodeStart(usize),
|
|
|
|
|
|
|
|
/// Inside a metadata node, with a previous `Lazy` or `LazySeq`.
|
|
|
|
/// The position is a conservative estimate of where that
|
|
|
|
/// previous `Lazy` / `LazySeq` would end (see their comments).
|
2016-10-22 18:44:32 +05:30
|
|
|
Previous(usize),
|
2016-09-17 10:33:47 +03:00
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2019-04-11 10:22:02 +03:00
|
|
|
pub struct CrateRoot<'tcx> {
|
2016-11-16 10:52:37 +00:00
|
|
|
pub name: Symbol,
|
2018-03-14 15:27:06 +01:00
|
|
|
pub triple: TargetTriple,
|
2018-03-13 11:58:53 -07:00
|
|
|
pub extra_filename: String,
|
2018-08-03 12:22:22 -06:00
|
|
|
pub hash: Svh,
|
2017-10-24 17:49:58 +02:00
|
|
|
pub disambiguator: CrateDisambiguator,
|
2017-09-07 12:35:21 -07:00
|
|
|
pub panic_strategy: PanicStrategy,
|
2018-05-13 03:50:39 +03:00
|
|
|
pub edition: Edition,
|
2017-09-07 12:35:21 -07:00
|
|
|
pub has_global_allocator: bool,
|
2018-09-06 21:24:33 +02:00
|
|
|
pub has_panic_handler: bool,
|
2017-09-07 12:35:21 -07:00
|
|
|
pub has_default_lib_allocator: bool,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub plugin_registrar_fn: Option<DefIndex>,
|
2018-03-16 01:09:22 +02:00
|
|
|
pub proc_macro_decls_static: Option<DefIndex>,
|
2019-01-28 23:40:14 +01:00
|
|
|
pub proc_macro_stability: Option<attr::Stability>,
|
2016-09-16 17:25:54 +03:00
|
|
|
|
2017-09-07 12:35:21 -07:00
|
|
|
pub crate_deps: LazySeq<CrateDep>,
|
|
|
|
pub dylib_dependency_formats: LazySeq<Option<LinkagePreference>>,
|
2018-07-23 01:20:33 +01:00
|
|
|
pub lib_features: LazySeq<(Symbol, Option<Symbol>)>,
|
2017-09-07 12:35:21 -07:00
|
|
|
pub lang_items: LazySeq<(DefIndex, usize)>,
|
|
|
|
pub lang_items_missing: LazySeq<lang_items::LangItem>,
|
|
|
|
pub native_libraries: LazySeq<NativeLibrary>,
|
2018-02-10 14:28:17 -08:00
|
|
|
pub foreign_modules: LazySeq<ForeignModule>,
|
2018-08-18 12:14:14 +02:00
|
|
|
pub source_map: LazySeq<syntax_pos::SourceFile>,
|
2016-12-16 12:51:36 -05:00
|
|
|
pub def_path_table: Lazy<hir::map::definitions::DefPathTable>,
|
2017-09-07 12:35:21 -07:00
|
|
|
pub impls: LazySeq<TraitImpls>,
|
2019-04-11 10:22:02 +03:00
|
|
|
pub exported_symbols: LazySeq<(ExportedSymbol<'tcx>, SymbolExportLevel)>,
|
2018-04-11 10:47:52 +02:00
|
|
|
pub interpret_alloc_index: LazySeq<u32>,
|
2018-02-27 19:28:21 +01:00
|
|
|
|
2019-05-22 12:16:48 +03:00
|
|
|
pub entries_index: LazySeq<index::Index<'tcx>>,
|
2018-05-12 10:20:53 -07:00
|
|
|
|
|
|
|
pub compiler_builtins: bool,
|
|
|
|
pub needs_allocator: bool,
|
|
|
|
pub needs_panic_runtime: bool,
|
|
|
|
pub no_builtins: bool,
|
|
|
|
pub panic_runtime: bool,
|
|
|
|
pub profiler_runtime: bool,
|
|
|
|
pub sanitizer_runtime: bool,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct CrateDep {
|
|
|
|
pub name: ast::Name,
|
2018-08-03 12:22:22 -06:00
|
|
|
pub hash: Svh,
|
2016-10-27 09:18:45 +00:00
|
|
|
pub kind: DepKind,
|
2018-03-13 11:58:53 -07:00
|
|
|
pub extra_filename: String,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct TraitImpls {
|
|
|
|
pub trait_id: (u32, DefIndex),
|
2016-10-22 18:44:32 +05:30
|
|
|
pub impls: LazySeq<DefIndex>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct Entry<'tcx> {
|
|
|
|
pub kind: EntryKind<'tcx>,
|
2016-12-20 08:32:15 +00:00
|
|
|
pub visibility: Lazy<ty::Visibility>,
|
2016-11-24 01:39:13 +02:00
|
|
|
pub span: Lazy<Span>,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub attributes: LazySeq<ast::Attribute>,
|
|
|
|
pub children: LazySeq<DefIndex>,
|
|
|
|
pub stability: Option<Lazy<attr::Stability>>,
|
|
|
|
pub deprecation: Option<Lazy<attr::Deprecation>>,
|
|
|
|
|
|
|
|
pub ty: Option<Lazy<Ty<'tcx>>>,
|
|
|
|
pub inherent_impls: LazySeq<DefIndex>,
|
|
|
|
pub variances: LazySeq<ty::Variance>,
|
2017-01-25 22:01:11 +02:00
|
|
|
pub generics: Option<Lazy<ty::Generics>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub predicates: Option<Lazy<ty::GenericPredicates<'tcx>>>,
|
2018-07-02 10:35:30 -04:00
|
|
|
pub predicates_defined_on: Option<Lazy<ty::GenericPredicates<'tcx>>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
|
2016-09-19 23:50:00 +03:00
|
|
|
pub mir: Option<Lazy<mir::Mir<'tcx>>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
|
|
|
pub enum EntryKind<'tcx> {
|
2018-04-15 19:41:33 -04:00
|
|
|
Const(ConstQualif, Lazy<RenderedConst>),
|
2016-09-16 17:25:54 +03:00
|
|
|
ImmStatic,
|
|
|
|
MutStatic,
|
|
|
|
ForeignImmStatic,
|
|
|
|
ForeignMutStatic,
|
|
|
|
ForeignMod,
|
2017-09-03 19:53:58 +01:00
|
|
|
ForeignType,
|
2017-03-15 21:27:40 -05:00
|
|
|
GlobalAsm,
|
2016-09-16 17:25:54 +03:00
|
|
|
Type,
|
2019-03-14 00:14:33 +00:00
|
|
|
TypeParam,
|
|
|
|
ConstParam,
|
2018-05-22 14:31:56 +02:00
|
|
|
Existential,
|
2017-02-05 07:01:48 +02:00
|
|
|
Enum(ReprOptions),
|
2016-09-16 17:25:54 +03:00
|
|
|
Field,
|
2017-05-13 17:11:52 +03:00
|
|
|
Variant(Lazy<VariantData<'tcx>>),
|
|
|
|
Struct(Lazy<VariantData<'tcx>>, ReprOptions),
|
|
|
|
Union(Lazy<VariantData<'tcx>>, ReprOptions),
|
|
|
|
Fn(Lazy<FnData<'tcx>>),
|
|
|
|
ForeignFn(Lazy<FnData<'tcx>>),
|
2016-09-16 17:25:54 +03:00
|
|
|
Mod(Lazy<ModData>),
|
2016-10-28 06:52:45 +00:00
|
|
|
MacroDef(Lazy<MacroDef>),
|
2016-09-16 17:25:54 +03:00
|
|
|
Closure(Lazy<ClosureData<'tcx>>),
|
2016-12-26 14:34:03 +01:00
|
|
|
Generator(Lazy<GeneratorData<'tcx>>),
|
2016-09-16 17:25:54 +03:00
|
|
|
Trait(Lazy<TraitData<'tcx>>),
|
|
|
|
Impl(Lazy<ImplData<'tcx>>),
|
2017-05-13 17:11:52 +03:00
|
|
|
Method(Lazy<MethodData<'tcx>>),
|
2019-05-19 16:26:08 +08:00
|
|
|
AssocType(AssocContainer),
|
|
|
|
AssocExistential(AssocContainer),
|
|
|
|
AssocConst(AssocContainer, ConstQualif, Lazy<RenderedConst>),
|
2019-01-08 10:55:18 -05:00
|
|
|
TraitAlias(Lazy<TraitAliasData<'tcx>>),
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:26:08 +08:00
|
|
|
/// Additional data for EntryKind::Const and EntryKind::AssocConst
|
2018-04-15 19:41:33 -04:00
|
|
|
#[derive(Clone, Copy, RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct ConstQualif {
|
|
|
|
pub mir: u8,
|
|
|
|
pub ast_promotable: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Contains a constant which has been rendered to a String.
|
|
|
|
/// Used by rustdoc.
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct RenderedConst(pub String);
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct ModData {
|
2019-04-03 09:07:45 +02:00
|
|
|
pub reexports: LazySeq<def::Export<hir::HirId>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2016-11-24 01:39:13 +02:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct MacroDef {
|
|
|
|
pub body: String,
|
2017-03-22 08:39:51 +00:00
|
|
|
pub legacy: bool,
|
2016-11-24 01:39:13 +02:00
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2017-05-13 17:11:52 +03:00
|
|
|
pub struct FnData<'tcx> {
|
2016-09-16 17:25:54 +03:00
|
|
|
pub constness: hir::Constness,
|
2016-10-22 18:44:32 +05:30
|
|
|
pub arg_names: LazySeq<ast::Name>,
|
2017-05-13 17:11:52 +03:00
|
|
|
pub sig: Lazy<ty::PolyFnSig<'tcx>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2017-05-13 17:11:52 +03:00
|
|
|
pub struct VariantData<'tcx> {
|
2016-09-15 00:51:46 +03:00
|
|
|
pub ctor_kind: CtorKind,
|
2017-02-05 07:01:48 +02:00
|
|
|
pub discr: ty::VariantDiscr,
|
2019-03-21 23:38:50 +01:00
|
|
|
/// If this is unit or tuple-variant/struct, then this is the index of the ctor id.
|
|
|
|
pub ctor: Option<DefIndex>,
|
2017-05-13 17:11:52 +03:00
|
|
|
/// If this is a tuple struct or variant
|
|
|
|
/// ctor, this is its "function" signature.
|
|
|
|
pub ctor_sig: Option<Lazy<ty::PolyFnSig<'tcx>>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct TraitData<'tcx> {
|
|
|
|
pub unsafety: hir::Unsafety,
|
|
|
|
pub paren_sugar: bool,
|
2017-10-09 13:59:20 -03:00
|
|
|
pub has_auto_impl: bool,
|
2018-08-24 23:13:31 -07:00
|
|
|
pub is_marker: bool,
|
2016-10-22 18:44:32 +05:30
|
|
|
pub super_predicates: Lazy<ty::GenericPredicates<'tcx>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2019-01-08 10:55:18 -05:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct TraitAliasData<'tcx> {
|
|
|
|
pub super_predicates: Lazy<ty::GenericPredicates<'tcx>>,
|
|
|
|
}
|
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct ImplData<'tcx> {
|
|
|
|
pub polarity: hir::ImplPolarity,
|
2016-11-18 17:14:42 +01:00
|
|
|
pub defaultness: hir::Defaultness,
|
2016-09-16 17:25:54 +03:00
|
|
|
pub parent_impl: Option<DefId>,
|
2017-03-17 16:17:45 -04:00
|
|
|
|
|
|
|
/// This is `Some` only for impls of `CoerceUnsized`.
|
|
|
|
pub coerce_unsized_info: Option<ty::adjustment::CoerceUnsizedInfo>,
|
2016-10-22 18:44:32 +05:30
|
|
|
pub trait_ref: Option<Lazy<ty::TraitRef<'tcx>>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2017-04-05 13:00:17 +02:00
|
|
|
|
2016-09-16 17:25:54 +03:00
|
|
|
/// Describes whether the container of an associated item
|
|
|
|
/// is a trait or an impl and whether, in a trait, it has
|
|
|
|
/// a default, or an in impl, whether it's marked "default".
|
|
|
|
#[derive(Copy, Clone, RustcEncodable, RustcDecodable)]
|
2019-05-19 16:26:08 +08:00
|
|
|
pub enum AssocContainer {
|
2016-09-16 17:25:54 +03:00
|
|
|
TraitRequired,
|
|
|
|
TraitWithDefault,
|
|
|
|
ImplDefault,
|
2016-10-22 18:44:32 +05:30
|
|
|
ImplFinal,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
2019-05-19 16:26:08 +08:00
|
|
|
impl AssocContainer {
|
|
|
|
pub fn with_def_id(&self, def_id: DefId) -> ty::AssocItemContainer {
|
2016-09-16 17:25:54 +03:00
|
|
|
match *self {
|
2019-05-19 16:26:08 +08:00
|
|
|
AssocContainer::TraitRequired |
|
|
|
|
AssocContainer::TraitWithDefault => ty::TraitContainer(def_id),
|
2016-09-16 17:25:54 +03:00
|
|
|
|
2019-05-19 16:26:08 +08:00
|
|
|
AssocContainer::ImplDefault |
|
|
|
|
AssocContainer::ImplFinal => ty::ImplContainer(def_id),
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn defaultness(&self) -> hir::Defaultness {
|
|
|
|
match *self {
|
2019-05-19 16:26:08 +08:00
|
|
|
AssocContainer::TraitRequired => hir::Defaultness::Default {
|
2016-11-14 11:00:02 -05:00
|
|
|
has_value: false,
|
|
|
|
},
|
|
|
|
|
2019-05-19 16:26:08 +08:00
|
|
|
AssocContainer::TraitWithDefault |
|
|
|
|
AssocContainer::ImplDefault => hir::Defaultness::Default {
|
2016-11-14 11:00:02 -05:00
|
|
|
has_value: true,
|
|
|
|
},
|
2016-09-16 17:25:54 +03:00
|
|
|
|
2019-05-19 16:26:08 +08:00
|
|
|
AssocContainer::ImplFinal => hir::Defaultness::Final,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
2017-05-13 17:11:52 +03:00
|
|
|
pub struct MethodData<'tcx> {
|
|
|
|
pub fn_data: FnData<'tcx>,
|
2019-05-19 16:26:08 +08:00
|
|
|
pub container: AssocContainer,
|
2016-11-10 02:06:34 +02:00
|
|
|
pub has_self: bool,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct ClosureData<'tcx> {
|
2017-05-13 13:12:29 +03:00
|
|
|
pub sig: Lazy<ty::PolyFnSig<'tcx>>,
|
2016-09-16 17:25:54 +03:00
|
|
|
}
|
2016-12-26 14:34:03 +01:00
|
|
|
|
|
|
|
#[derive(RustcEncodable, RustcDecodable)]
|
|
|
|
pub struct GeneratorData<'tcx> {
|
|
|
|
pub layout: mir::GeneratorLayout<'tcx>,
|
|
|
|
}
|
2018-01-04 11:26:47 +01:00
|
|
|
|
|
|
|
// Tags used for encoding Spans:
|
|
|
|
pub const TAG_VALID_SPAN: u8 = 0;
|
|
|
|
pub const TAG_INVALID_SPAN: u8 = 1;
|