]> git.lizzy.rs Git - rust.git/commitdiff
Make `newtype_index` safe
authorOliver Scherer <github35764891676564198441@oli-obk.de>
Sat, 3 Nov 2018 14:08:27 +0000 (15:08 +0100)
committerOliver Scherer <github35764891676564198441@oli-obk.de>
Tue, 4 Dec 2018 09:17:36 +0000 (10:17 +0100)
14 files changed:
src/librustc/dep_graph/graph.rs
src/librustc/dep_graph/serialized.rs
src/librustc/lib.rs
src/librustc/middle/region.rs
src/librustc/mir/mod.rs
src/librustc/ty/mod.rs
src/librustc/ty/sty.rs
src/librustc_data_structures/indexed_vec.rs
src/librustc_mir/borrow_check/location.rs
src/librustc_mir/borrow_check/nll/constraints/mod.rs
src/librustc_mir/borrow_check/nll/region_infer/values.rs
src/librustc_mir/borrow_check/nll/type_check/liveness/liveness_map.rs
src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs
src/librustc_mir/build/mod.rs

index 4c94c993ab40595131f83168c737a4c2b5292806..06287bda63a494e84b3b725d52ad9d4d8b99bc7a 100644 (file)
@@ -18,6 +18,7 @@
 use std::hash::Hash;
 use ty::{self, TyCtxt};
 use util::common::{ProfileQueriesMsg, profq_msg};
+use serialize::{Decodable, Decoder};
 
 use ich::{StableHashingContext, StableHashingContextProvider, Fingerprint};
 
index 0c6c224fa914c9009a5b1546d0cc125301a09337..992ebd0efb15f48bcadfa76a191700a6bcd4a63c 100644 (file)
@@ -13,6 +13,7 @@
 use dep_graph::DepNode;
 use ich::Fingerprint;
 use rustc_data_structures::indexed_vec::{IndexVec, Idx};
+use serialize::{Decodable, Decoder};
 
 newtype_index! {
     pub struct SerializedDepNodeIndex { .. }
index ddb0c5bf22ab6410299a4f061c2c3f9fc9cda00b..99412c02c43a60cfe8a9251af3b7ed0fe25de8a7 100644 (file)
@@ -69,6 +69,7 @@
 #![feature(in_band_lifetimes)]
 #![feature(crate_visibility_modifier)]
 #![feature(transpose_result)]
+#![cfg_attr(not(stage0), feature(min_const_unsafe_fn))]
 
 #![recursion_limit="512"]
 
index 35d1a4dd2cb7c5e691ede2c7d72cf258cfa4c0c8..1440d91b47e639d1677d5ea447f8aaa7c1ddd477 100644 (file)
@@ -28,6 +28,7 @@
 use syntax_pos::{Span, DUMMY_SP};
 use ty::TyCtxt;
 use ty::query::Providers;
+use serialize::{Decodable, Decoder};
 
 use hir;
 use hir::Node;
index c0581121efa1c66c7aa35c6b22eae9deaf3e7348..549e13bad642afbe542540365d5791810d61cf63 100644 (file)
@@ -25,7 +25,7 @@
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use rustc_data_structures::sync::Lrc;
 use rustc_data_structures::sync::MappedReadGuard;
-use rustc_serialize as serialize;
+use rustc_serialize::{self as serialize, Decodable, Decoder};
 use smallvec::SmallVec;
 use std::borrow::Cow;
 use std::fmt::{self, Debug, Formatter, Write};
index 4633ab11663472df322e5b73b54b364889150771..8ff93cee250221191b8acf8542d808a06e622807 100644 (file)
@@ -41,7 +41,7 @@
 use arena::SyncDroplessArena;
 use session::DataTypeKind;
 
-use serialize::{self, Encodable, Encoder};
+use serialize::{self, Encodable, Encoder, Decodable, Decoder};
 use std::cell::RefCell;
 use std::cmp::{self, Ordering};
 use std::fmt;
index 1416cb17feaedf9832f70e4783a9d5ecd0f5f9a1..fa45b8c7768377f439e4023048906e21b40b153a 100644 (file)
@@ -29,7 +29,7 @@
 use syntax::ast::{self, Ident};
 use syntax::symbol::{keywords, InternedString};
 
-use serialize;
+use serialize::{self, Decodable, Decoder};
 
 use hir;
 
index a59bf9d530c4d0919001c3c81f23a33c9c0bbb40..c35490ce35b4f0488474aed6422d47e7fde34060 100644 (file)
@@ -98,12 +98,18 @@ macro_rules! newtype_index {
      @max          [$max:expr]
      @vis          [$v:vis]
      @debug_format [$debug_format:tt]) => (
-        #[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
+        #[derive(Copy, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
         #[rustc_layout_scalar_valid_range_end($max)]
         $v struct $type {
             private: u32
         }
 
+        impl Clone for $type {
+            fn clone(&self) -> Self {
+                *self
+            }
+        }
+
         impl $type {
             $v const MAX_AS_U32: u32 = $max;
 
@@ -145,7 +151,7 @@ impl $type {
 
             #[inline]
             $v const unsafe fn from_u32_unchecked(value: u32) -> Self {
-                $type { private: value }
+                unsafe { $type { private: value } }
             }
 
             /// Extract value of this index as an integer.
@@ -328,12 +334,17 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
                    derive [$($derives:ident,)+]
                    $($tokens:tt)*) => (
         newtype_index!(
-            @derives      [$($derives,)+ RustcDecodable, RustcEncodable,]
+            @derives      [$($derives,)+ RustcEncodable,]
             @type         [$type]
             @max          [$max]
             @vis          [$v]
             @debug_format [$debug_format]
                           $($tokens)*);
+        impl Decodable for $type {
+            fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
+                d.read_u32().into()
+            }
+        }
     );
 
     // The case where no derives are added, but encodable is overridden. Don't
@@ -360,12 +371,17 @@ fn fmt(&self, fmt: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
      @debug_format [$debug_format:tt]
                    $($tokens:tt)*) => (
         newtype_index!(
-            @derives      [RustcDecodable, RustcEncodable,]
+            @derives      [RustcEncodable,]
             @type         [$type]
             @max          [$max]
             @vis          [$v]
             @debug_format [$debug_format]
                           $($tokens)*);
+        impl Decodable for $type {
+            fn decode<D: Decoder>(d: &mut D) -> Result<Self, D::Error> {
+                d.read_u32().map(Self::from)
+            }
+        }
     );
 
     // Rewrite final without comma to one that includes comma
index b3e159dd84457c14b2a35ca5d7821a84024195eb..2d593d851138b1dec9ebef630127589c51aab2d5 100644 (file)
@@ -10,6 +10,7 @@
 
 use rustc::mir::{BasicBlock, Location, Mir};
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
+use rustc_serialize::{Decodable, Decoder};
 
 /// Maps between a MIR Location, which identifies a particular
 /// statement within a basic block, to a "rich location", which
index a873af8333a7fb0af867ae6423ed36645e4951d6..37b11a77184d4f018654e3388091fa83f7be2274 100644 (file)
@@ -13,6 +13,7 @@
 use rustc_data_structures::graph::scc::Sccs;
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use borrow_check::nll::type_check::Locations;
+use rustc_serialize::{Decodable, Decoder};
 
 use std::fmt;
 use std::ops::Deref;
index 69e2c896d33e515b3ce77fdcb4305f8333fc65ad..5ce80ca236dbb337fcffd9b8d6fa0cc5f6601a62 100644 (file)
@@ -16,6 +16,7 @@
 use rustc_data_structures::indexed_vec::IndexVec;
 use std::fmt::Debug;
 use std::rc::Rc;
+use rustc_serialize::{Decodable, Decoder};
 
 /// Maps between a `Location` and a `PointIndex` (and vice versa).
 crate struct RegionValueElements {
index cc176cbc40392aa733851faa605d681645fc1ee6..d1a1d2aea248a55460b890016b8f202ce6122338 100644 (file)
@@ -23,6 +23,7 @@
 use rustc_data_structures::fx::FxHashSet;
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use util::liveness::LiveVariableMap;
+use rustc_serialize::{Decodable, Decoder};
 
 /// Map between Local and LiveVar indices: the purpose of this
 /// map is to define the subset of local variables for which we need
index 4b39d58cd96a82e3c7479aa84429241bb63908f5..9e0eaf61e94a4cd6fdb649d41cf1ee1e8ef8ee24 100644 (file)
@@ -15,6 +15,7 @@
 use rustc_data_structures::indexed_vec::{Idx, IndexVec};
 use rustc_data_structures::vec_linked_list as vll;
 use util::liveness::{categorize, DefUse, LiveVariableMap};
+use rustc_serialize::{Decodable, Decoder};
 
 /// A map that cross references each local with the locations where it
 /// is defined (assigned), used, or dropped. Used during liveness
index cc927df6350bdb3cc3b93893cd8556e6c662079e..1a5a089c7aa03cb4e818312d195b457034372bfa 100644 (file)
@@ -32,6 +32,7 @@
 use syntax::attr::{self, UnwindAttr};
 use syntax::symbol::keywords;
 use syntax_pos::Span;
+use rustc_serialize::{Decodable, Decoder};
 use transform::MirSource;
 use util as mir_util;