X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=src%2Flibrustc%2Fmiddle%2Fcstore.rs;h=27745a85935abf00d8c6668ca8da7b61754c81b3;hb=03b4bf20f6fa922d7a1cfa5d270ce763ceca09bf;hp=22a4ddd2f687b54db5ba18fcaef85f42e0429cd9;hpb=89ec45ced42a37a77ff1b71be5b903eb313a77e7;p=rust.git diff --git a/src/librustc/middle/cstore.rs b/src/librustc/middle/cstore.rs index 22a4ddd2f68..27745a85935 100644 --- a/src/librustc/middle/cstore.rs +++ b/src/librustc/middle/cstore.rs @@ -24,9 +24,9 @@ use back::svh::Svh; use front::map as hir_map; -use middle::def; +use middle::def::{self, Def}; use middle::lang_items; -use middle::ty::{self, Ty}; +use middle::ty::{self, Ty, VariantKind}; use middle::def_id::{DefId, DefIndex}; use mir::repr::Mir; use session::Session; @@ -84,7 +84,7 @@ pub enum NativeLibraryKind { // Something that a name can resolve to. #[derive(Copy, Clone, Debug)] pub enum DefLike { - DlDef(def::Def), + DlDef(Def), DlImpl(DefId), DlField } @@ -135,6 +135,7 @@ pub enum FoundAst<'ast> { pub trait CrateStore<'tcx> : Any { // item info fn stability(&self, def: DefId) -> Option; + fn deprecation(&self, def: DefId) -> Option; fn closure_kind(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureKind; fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) @@ -210,6 +211,8 @@ fn crate_struct_field_attrs(&self, cnum: ast::CrateNum) // resolve fn def_path(&self, def: DefId) -> hir_map::DefPath; + fn variant_kind(&self, def_id: DefId) -> Option; + fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option; fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option; fn struct_field_names(&self, def: DefId) -> Vec; fn item_children(&self, did: DefId) -> Vec; @@ -292,6 +295,7 @@ pub fn validate_crate_name(sess: Option<&Session>, s: &str, sp: Option) { impl<'tcx> CrateStore<'tcx> for DummyCrateStore { // item info fn stability(&self, def: DefId) -> Option { unimplemented!() } + fn deprecation(&self, def: DefId) -> Option { unimplemented!() } fn closure_kind(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) -> ty::ClosureKind { unimplemented!() } fn closure_ty(&self, tcx: &ty::ctxt<'tcx>, def_id: DefId) @@ -378,6 +382,9 @@ fn reachable_ids(&self, cnum: ast::CrateNum) -> Vec { unimplemented!() } // resolve fn def_path(&self, def: DefId) -> hir_map::DefPath { unimplemented!() } + fn variant_kind(&self, def_id: DefId) -> Option { unimplemented!() } + fn struct_ctor_def_id(&self, struct_def_id: DefId) -> Option + { unimplemented!() } fn tuple_struct_definition_if_ctor(&self, did: DefId) -> Option { unimplemented!() } fn struct_field_names(&self, def: DefId) -> Vec { unimplemented!() } @@ -430,8 +437,8 @@ fn metadata_encoding_version(&self) -> &[u8] { unimplemented!() } /// Note, however, that this only works for RBML-based encoding and decoding at /// the moment. pub mod tls { - use rbml::writer::Encoder as RbmlEncoder; - use rbml::reader::Decoder as RbmlDecoder; + use rbml::opaque::Encoder as OpaqueEncoder; + use rbml::opaque::Decoder as OpaqueDecoder; use serialize; use std::mem; use middle::ty::{self, Ty}; @@ -440,8 +447,8 @@ pub mod tls { pub trait EncodingContext<'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; - fn encode_ty(&self, rbml_w: &mut RbmlEncoder, t: Ty<'tcx>); - fn encode_substs(&self, rbml_w: &mut RbmlEncoder, substs: &Substs<'tcx>); + fn encode_ty(&self, encoder: &mut OpaqueEncoder, t: Ty<'tcx>); + fn encode_substs(&self, encoder: &mut OpaqueEncoder, substs: &Substs<'tcx>); } /// Marker type used for the scoped TLS slot. @@ -453,13 +460,13 @@ pub trait EncodingContext<'tcx> { /// Execute f after pushing the given EncodingContext onto the TLS stack. pub fn enter_encoding_context<'tcx, F, R>(ecx: &EncodingContext<'tcx>, - rbml_w: &mut RbmlEncoder, + encoder: &mut OpaqueEncoder, f: F) -> R - where F: FnOnce(&EncodingContext<'tcx>, &mut RbmlEncoder) -> R + where F: FnOnce(&EncodingContext<'tcx>, &mut OpaqueEncoder) -> R { - let tls_payload = (ecx as *const _, rbml_w as *mut _); + let tls_payload = (ecx as *const _, encoder as *mut _); let tls_ptr = &tls_payload as *const _ as *const TlsPayload; - TLS_ENCODING.set(unsafe { &*tls_ptr }, || f(ecx, rbml_w)) + TLS_ENCODING.set(unsafe { &*tls_ptr }, || f(ecx, encoder)) } /// Execute f with access to the thread-local encoding context and @@ -471,16 +478,16 @@ pub fn enter_encoding_context<'tcx, F, R>(ecx: &EncodingContext<'tcx>, /// possible to construct cases where the EncodingContext is exchanged /// while the same encoder is used, thus working with a wrong context. pub fn with_encoding_context<'tcx, E, F, R>(encoder: &mut E, f: F) -> R - where F: FnOnce(&EncodingContext<'tcx>, &mut RbmlEncoder) -> R, + where F: FnOnce(&EncodingContext<'tcx>, &mut OpaqueEncoder) -> R, E: serialize::Encoder { unsafe { - unsafe_with_encoding_context(|ecx, rbml_w| { - assert!(encoder as *mut _ as usize == rbml_w as *mut _ as usize); + unsafe_with_encoding_context(|ecx, tls_encoder| { + assert!(encoder as *mut _ as usize == tls_encoder as *mut _ as usize); let ecx: &EncodingContext<'tcx> = mem::transmute(ecx); - f(ecx, rbml_w) + f(ecx, tls_encoder) }) } } @@ -488,19 +495,19 @@ pub fn with_encoding_context<'tcx, E, F, R>(encoder: &mut E, f: F) -> R /// Execute f with access to the thread-local encoding context and /// rbml encoder. pub unsafe fn unsafe_with_encoding_context(f: F) -> R - where F: FnOnce(&EncodingContext, &mut RbmlEncoder) -> R + where F: FnOnce(&EncodingContext, &mut OpaqueEncoder) -> R { TLS_ENCODING.with(|tls| { let tls_payload = (tls as *const TlsPayload) - as *mut (&EncodingContext, &mut RbmlEncoder); + as *mut (&EncodingContext, &mut OpaqueEncoder); f((*tls_payload).0, (*tls_payload).1) }) } pub trait DecodingContext<'tcx> { fn tcx<'a>(&'a self) -> &'a ty::ctxt<'tcx>; - fn decode_ty(&self, rbml_r: &mut RbmlDecoder) -> ty::Ty<'tcx>; - fn decode_substs(&self, rbml_r: &mut RbmlDecoder) -> Substs<'tcx>; + fn decode_ty(&self, decoder: &mut OpaqueDecoder) -> ty::Ty<'tcx>; + fn decode_substs(&self, decoder: &mut OpaqueDecoder) -> Substs<'tcx>; fn translate_def_id(&self, def_id: DefId) -> DefId; } @@ -508,13 +515,13 @@ pub trait DecodingContext<'tcx> { /// Execute f after pushing the given DecodingContext onto the TLS stack. pub fn enter_decoding_context<'tcx, F, R>(dcx: &DecodingContext<'tcx>, - rbml_r: &mut RbmlDecoder, + decoder: &mut OpaqueDecoder, f: F) -> R - where F: FnOnce(&DecodingContext<'tcx>, &mut RbmlDecoder) -> R + where F: FnOnce(&DecodingContext<'tcx>, &mut OpaqueDecoder) -> R { - let tls_payload = (dcx as *const _, rbml_r as *mut _); + let tls_payload = (dcx as *const _, decoder as *mut _); let tls_ptr = &tls_payload as *const _ as *const TlsPayload; - TLS_DECODING.set(unsafe { &*tls_ptr }, || f(dcx, rbml_r)) + TLS_DECODING.set(unsafe { &*tls_ptr }, || f(dcx, decoder)) } /// Execute f with access to the thread-local decoding context and @@ -528,16 +535,16 @@ pub fn enter_decoding_context<'tcx, F, R>(dcx: &DecodingContext<'tcx>, pub fn with_decoding_context<'decoder, 'tcx, D, F, R>(d: &'decoder mut D, f: F) -> R where D: serialize::Decoder, F: FnOnce(&DecodingContext<'tcx>, - &mut RbmlDecoder) -> R, + &mut OpaqueDecoder) -> R, 'tcx: 'decoder { unsafe { - unsafe_with_decoding_context(|dcx, rbml_r| { - assert!((d as *mut _ as usize) == (rbml_r as *mut _ as usize)); + unsafe_with_decoding_context(|dcx, decoder| { + assert!((d as *mut _ as usize) == (decoder as *mut _ as usize)); let dcx: &DecodingContext<'tcx> = mem::transmute(dcx); - f(dcx, rbml_r) + f(dcx, decoder) }) } } @@ -545,11 +552,11 @@ pub fn with_decoding_context<'decoder, 'tcx, D, F, R>(d: &'decoder mut D, f: F) /// Execute f with access to the thread-local decoding context and /// rbml decoder. pub unsafe fn unsafe_with_decoding_context(f: F) -> R - where F: FnOnce(&DecodingContext, &mut RbmlDecoder) -> R + where F: FnOnce(&DecodingContext, &mut OpaqueDecoder) -> R { TLS_DECODING.with(|tls| { let tls_payload = (tls as *const TlsPayload) - as *mut (&DecodingContext, &mut RbmlDecoder); + as *mut (&DecodingContext, &mut OpaqueDecoder); f((*tls_payload).0, (*tls_payload).1) }) }