]> git.lizzy.rs Git - rust.git/commitdiff
Initial changes to librustc to support const trait fns.
authorAlexander Regueiro <alexreg@me.com>
Sat, 6 Jan 2018 03:36:39 +0000 (03:36 +0000)
committerOliver Schneider <git-spam-no-reply9815368754983@oli-obk.de>
Thu, 8 Mar 2018 07:08:14 +0000 (08:08 +0100)
src/librustc/hir/def_id.rs
src/librustc_metadata/decoder.rs
src/librustc_metadata/encoder.rs
src/librustdoc/clean/mod.rs

index 637b156ceef5d998ddedb5969a52b4bb4e2988ac..34b3aa53d6bcf807e0e818ad4eef538128942bfb 100644 (file)
@@ -220,7 +220,6 @@ impl serialize::UseSpecializedDecodable for DefId {}
 pub struct LocalDefId(DefIndex);
 
 impl LocalDefId {
-
     #[inline]
     pub fn from_def_id(def_id: DefId) -> LocalDefId {
         assert!(def_id.is_local());
index 77c3eed9e44d21c069b47186dd66c48279c0fe23..d991fb0f67b11350d8139bb08faac6c74b9f9fea 100644 (file)
@@ -21,7 +21,7 @@
 use rustc::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel};
 use rustc::hir::def::{self, Def, CtorKind};
 use rustc::hir::def_id::{CrateNum, DefId, DefIndex,
-                         CRATE_DEF_INDEX, LOCAL_CRATE};
+                         CRATE_DEF_INDEX, LOCAL_CRATE, LocalDefId};
 use rustc::ich::Fingerprint;
 use rustc::middle::lang_items;
 use rustc::mir::{self, interpret};
@@ -273,6 +273,13 @@ fn specialized_decode(&mut self) -> Result<DefIndex, Self::Error> {
     }
 }
 
+impl<'a, 'tcx> SpecializedDecoder<LocalDefId> for DecodeContext<'a, 'tcx> {
+    #[inline]
+    fn specialized_decode(&mut self) -> Result<LocalDefId, Self::Error> {
+        self.specialized_decode().map(|i| LocalDefId::from_def_id(i))
+    }
+}
+
 impl<'a, 'tcx> SpecializedDecoder<interpret::AllocId> for DecodeContext<'a, 'tcx> {
     fn specialized_decode(&mut self) -> Result<interpret::AllocId, Self::Error> {
         const MAX1: usize = usize::max_value() - 1;
index f5631f5fab91f5988c79873a6856d717021a70a9..04ac32af7ccb848add6bd9bcd6576a23ef8bd3d0 100644 (file)
@@ -16,7 +16,7 @@
 use rustc::middle::cstore::{LinkMeta, LinkagePreference, NativeLibrary,
                             EncodedMetadata};
 use rustc::hir::def::CtorKind;
-use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LOCAL_CRATE};
+use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, DefIndex, DefId, LocalDefId, LOCAL_CRATE};
 use rustc::hir::map::definitions::DefPathTable;
 use rustc::ich::Fingerprint;
 use rustc::middle::dependency_format::Linkage;
@@ -181,6 +181,13 @@ fn specialized_encode(&mut self, span: &Span) -> Result<(), Self::Error> {
     }
 }
 
+impl<'a, 'tcx> SpecializedEncoder<LocalDefId> for EncodeContext<'a, 'tcx> {
+    #[inline]
+    fn specialized_encode(&mut self, def_id: &LocalDefId) -> Result<(), Self::Error> {
+        self.specialized_encode(&def_id.to_def_id())
+    }
+}
+
 impl<'a, 'tcx> SpecializedEncoder<Ty<'tcx>> for EncodeContext<'a, 'tcx> {
     fn specialized_encode(&mut self, ty: &Ty<'tcx>) -> Result<(), Self::Error> {
         ty_codec::encode_with_shorthand(self, ty, |ecx| &mut ecx.type_shorthands)
index d0230a69374d48167f11aa87f5c97d7aa82f2efe..d1e6f27069c0d2a0f860b9b5ac686ca0bcc26aef 100644 (file)
@@ -51,7 +51,6 @@
 use std::collections::VecDeque;
 use std::fmt;
 
-use rustc_const_math::ConstInt;
 use std::default::Default;
 use std::{mem, slice, vec};
 use std::iter::{FromIterator, once};
@@ -2507,9 +2506,7 @@ fn clean(&self, cx: &DocContext) -> Type {
                         ty: cx.tcx.types.usize
                     })
                 });
-                let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
-                    n.to_string()
-                } else if let ConstVal::Unevaluated(def_id, _) = n.val {
+                let n = if let ConstVal::Unevaluated(def_id, _) = n.val {
                     if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
                         print_const_expr(cx, cx.tcx.hir.body_owned_by(node_id))
                     } else {
@@ -2640,9 +2637,7 @@ fn clean(&self, cx: &DocContext) -> Type {
                         n = new_n;
                     }
                 };
-                let n = if let ConstVal::Integral(ConstInt::Usize(n)) = n.val {
-                    n.to_string()
-                } else if let ConstVal::Unevaluated(def_id, _) = n.val {
+                let n = if let ConstVal::Unevaluated(def_id, _) = n.val {
                     if let Some(node_id) = cx.tcx.hir.as_local_node_id(def_id) {
                         print_const_expr(cx, cx.tcx.hir.body_owned_by(node_id))
                     } else {