}
pub fn as_u32(&self) -> u32 {
- self.0
+ u32::from(*self)
}
pub fn as_def_id(&self) -> DefId { DefId { krate: *self, index: CRATE_DEF_INDEX } }
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- use rustc_data_structures::indexed_vec::Idx;
self.index().hash_stable(hcx, hasher);
}
}
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- use rustc_data_structures::indexed_vec::Idx;
self.index().hash_stable(hcx, hasher);
}
}
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- use rustc_data_structures::indexed_vec::Idx;
self.index().hash_stable(hcx, hasher);
}
}
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- use rustc_data_structures::indexed_vec::Idx;
self.index().hash_stable(hcx, hasher);
}
}
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- use rustc_data_structures::indexed_vec::Idx;
self.index().hash_stable(hcx, hasher);
}
}
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'a>,
hasher: &mut StableHasher<W>) {
- use rustc_data_structures::indexed_vec::Idx;
self.index().hash_stable(hcx, hasher);
}
}
fn hash_stable<W: StableHasherResult>(&self,
hcx: &mut StableHashingContext<'gcx>,
hasher: &mut StableHasher<W>) {
- use rustc_data_structures::indexed_vec::Idx;
self.index().hash_stable(hcx, hasher);
}
}
FnPtrAddrCast
});
-impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
impl_stable_hash_for!(struct ::middle::region::Scope { id, code });
impl<'a> ToStableHashKey<StableHashingContext<'a>> for region::Scope {
use syntax_pos::{Pos, Span};
use errors::{Applicability, DiagnosticBuilder, DiagnosticStyledString};
-use rustc_data_structures::indexed_vec::Idx;
-
mod note;
mod need_type_info;
use super::{MiscVariable, RegionVariableOrigin, SubregionOrigin};
use super::unify_key;
-use rustc_data_structures::indexed_vec::{IndexVec, Idx};
+use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_data_structures::unify as ut;
use ty::{self, Ty, TyCtxt};
impl UnifyKey for ty::RegionVid {
type Value = RegionVidKey;
- fn index(&self) -> u32 { self.0 }
- fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid(i) }
+ fn index(&self) -> u32 { u32::from(*self) }
+ fn from_index(i: u32) -> ty::RegionVid { ty::RegionVid::from(i) }
fn tag() -> &'static str { "RegionVid" }
}
newtype_index! {
pub struct FirstStatementIndex {
- pub idx
MAX = SCOPE_DATA_REMAINDER_MAX
}
}
+impl_stable_hash_for!(tuple_struct ::middle::region::FirstStatementIndex { idx });
+
impl From<ScopeData> for Scope {
#[inline]
fn from(scope_data: ScopeData) -> Self {
newtype_index! {
pub struct RegionVid {
- pub idx
DEBUG_FORMAT = custom,
}
}
}
}
-impl From<usize> for RegionVid {
- fn from(i: usize) -> RegionVid {
- RegionVid::new(i)
- }
-}
-
-impl From<RegionVid> for usize {
- fn from(vid: RegionVid) -> usize {
- Idx::index(vid)
- }
-}
-
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)]
pub enum InferTy {
TyVar(TyVid),
use std::fmt;
use std::usize;
-use rustc_data_structures::indexed_vec::Idx;
use rustc_target::spec::abi::Abi;
use syntax::ast::CRATE_NODE_ID;
use syntax::symbol::{Symbol, InternedString};
use std::iter;
use rustc_data_structures::bitvec::BitArray;
-use rustc_data_structures::indexed_vec::{IndexVec, Idx};
+use rustc_data_structures::indexed_vec::IndexVec;
pub use self::constant::codegen_static_initializer;
use rustc::mir::interpret::{ConstValue, ScalarMaybeUndef};
use rustc::ty;
use rustc::ty::layout::{self, Align, LayoutOf, TyLayout};
-use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::sync::Lrc;
use base;
use rustc::ty::layout::{self, Align, TyLayout, LayoutOf, Size};
use rustc::mir;
use rustc::mir::tcx::PlaceTy;
-use rustc_data_structures::indexed_vec::Idx;
use base;
use builder::Builder;
use common::{CodegenCx, C_undef, C_usize, C_u8, C_u32, C_uint, C_null, C_uint_big};
}
/// Creates a struct type `S` that can be used as an index with
-/// `IndexVec` and so on. This struct can be constructed via `S::new`
-/// (given a `usize`) and converted to a usize with the `index()`
-/// method (from the `Idx` trait). Internally, the index uses a u32,
-/// so the index must not exceed `u32::MAX`. You can also customize
-/// things like the `Debug` impl, what traits are derived, and so
-/// forth.
+/// `IndexVec` and so on.
+///
+/// There are two ways of interacting with these indices:
+///
+/// - The `From` impls are the preferred way. So you can do
+/// `S::from(v)` with a `usize` or `u32`. And you can convert back
+/// to an integer with `u32::from(s)`.
+///
+/// - Alternatively, you can use the methods `S::new(v)` and `s.index()`
+/// to create/return a value.
+///
+/// Internally, the index uses a u32, so the index must not exceed
+/// `u32::MAX`. You can also customize things like the `Debug` impl,
+/// what traits are derived, and so forth via the macro.
#[macro_export]
macro_rules! newtype_index {
// ---- public rules ----
// Base case, user-defined constants (if any) have already been defined
(@derives [$($derives:ident,)*]
- @pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]) => (
#[derive(Copy, Clone, PartialEq, Eq, Hash, PartialOrd, Ord, $($derives),*)]
- $v struct $type($($pub)* u32);
+ $v struct $type(u32);
+
+ impl $type {
+ /// Extract value of this index as an integer.
+ #[inline]
+ $v fn index(self) -> usize {
+ <Self as Idx>::index(self)
+ }
+ }
impl Idx for $type {
#[inline]
}
}
+ impl From<$type> for u32 {
+ fn from(v: $type) -> u32 {
+ v.0
+ }
+ }
+
+ impl From<$type> for usize {
+ fn from(v: $type) -> usize {
+ v.0 as usize
+ }
+ }
+
+ impl From<usize> for $type {
+ fn from(v: usize) -> Self {
+ Self::new(v)
+ }
+ }
+
+ impl From<u32> for $type {
+ fn from(v: u32) -> Self {
+ Self::new(v as usize)
+ }
+ }
+
newtype_index!(
@handle_debug
@derives [$($derives,)*]
@debug_format [$debug_format]);
);
- // Handle the case where someone wants to make the internal field public
- (@type [$type:ident]
- @max [$max:expr]
- @vis [$v:vis]
- @debug_format [$debug_format:tt]
- pub idx
- $($tokens:tt)*) => (
- newtype_index!(
- @pub [pub]
- @type [$type]
- @max [$max]
- @vis [$v]
- @debug_format [$debug_format]
- $($tokens)*);
- );
-
- // The default case is that the internal field is private
- (@type [$type:ident]
- @max [$max:expr]
- @vis [$v:vis]
- @debug_format [$debug_format:tt]
- $($tokens:tt)*) => (
- newtype_index!(
- @pub []
- @type [$type]
- @max [$max]
- @vis [$v]
- @debug_format [$debug_format]
- $($tokens)*);
- );
-
// Append comma to end of derives list if it's missing
- (@pub [$($pub:tt)*]
- @type [$type:ident]
+ (@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
derive [$($derives:ident),*]
$($tokens:tt)*) => (
newtype_index!(
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// By not including the @derives marker in this list nor in the default args, we can force it
// to come first if it exists. When encodable is custom, just use the derives list as-is.
- (@pub [$($pub:tt)*]
- @type [$type:ident]
+ (@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$($tokens:tt)*) => (
newtype_index!(
@derives [$($derives,)+]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// By not including the @derives marker in this list nor in the default args, we can force it
// to come first if it exists. When encodable isn't custom, add serialization traits by default.
- (@pub [$($pub:tt)*]
- @type [$type:ident]
+ (@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$($tokens:tt)*) => (
newtype_index!(
@derives [$($derives,)+ RustcDecodable, RustcEncodable,]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// The case where no derives are added, but encodable is overridden. Don't
// derive serialization traits
- (@pub [$($pub:tt)*]
- @type [$type:ident]
+ (@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$($tokens:tt)*) => (
newtype_index!(
@derives []
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
);
// The case where no derives are added, add serialization derives by default
- (@pub [$($pub:tt)*]
- @type [$type:ident]
+ (@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
@debug_format [$debug_format:tt]
$($tokens:tt)*) => (
newtype_index!(
@derives [RustcDecodable, RustcEncodable,]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// Rewrite final without comma to one that includes comma
(@derives [$($derives:ident,)*]
- @pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
$name:ident = $constant:expr) => (
newtype_index!(
@derives [$($derives,)*]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// Rewrite final const without comma to one that includes comma
(@derives [$($derives:ident,)*]
- @pub [$($pub:tt)*]
@type [$type:ident]
@max [$_max:expr]
@vis [$v:vis]
const $name:ident = $constant:expr) => (
newtype_index!(
@derives [$($derives,)*]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// Replace existing default for max
(@derives [$($derives:ident,)*]
- @pub [$($pub:tt)*]
@type [$type:ident]
@max [$_max:expr]
@vis [$v:vis]
$($tokens:tt)*) => (
newtype_index!(
@derives [$($derives,)*]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// Replace existing default for debug_format
(@derives [$($derives:ident,)*]
- @pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
$($tokens:tt)*) => (
newtype_index!(
@derives [$($derives,)*]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
// Assign a user-defined constant
(@derives [$($derives:ident,)*]
- @pub [$($pub:tt)*]
@type [$type:ident]
@max [$max:expr]
@vis [$v:vis]
pub const $name: $type = $type($constant);
newtype_index!(
@derives [$($derives,)*]
- @pub [$($pub)*]
@type [$type]
@max [$max]
@vis [$v]
use rustc::mir::{ProjectionElem, Rvalue, Statement, StatementKind};
use rustc::ty;
use rustc_data_structures::fx::FxHashSet;
-use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::sync::Lrc;
use rustc_errors::DiagnosticBuilder;
use syntax_pos::Span;
use rustc::mir::*;
use rustc::ty;
use rustc_errors::DiagnosticBuilder;
-use rustc_data_structures::indexed_vec::Idx;
use syntax_pos::Span;
use borrow_check::MirBorrowckCtxt;
}
}
-impl From<usize> for LocationIndex {
- fn from(i: usize) -> LocationIndex {
- LocationIndex::new(i)
- }
-}
-
-impl From<LocationIndex> for usize {
- fn from(vid: LocationIndex) -> usize {
- Idx::index(vid)
- }
-}
-
struct FactWriter<'w> {
location_table: &'w LocationTable,
dir: &'w Path,
use super::*;
use borrow_check::nll::constraints::OutlivesConstraint;
use dot::{self, IntoCow};
-use rustc_data_structures::indexed_vec::Idx;
use std::borrow::Cow;
use std::io::{self, Write};
use transform::{MirPass, MirSource};
use rustc_data_structures::fx::FxHashSet;
-use rustc_data_structures::indexed_vec::Idx;
macro_rules! span_mirbug {
($context:expr, $elem:expr, $($message:tt)*) => ({
use rustc::ty::subst::Kind;
use rustc::ty::{self, CanonicalTy, CanonicalVar, RegionVid, Ty, TyCtxt};
use rustc_data_structures::fx::FxHashMap;
-use rustc_data_structures::indexed_vec::{Idx, IndexVec};
+use rustc_data_structures::indexed_vec::IndexVec;
use std::mem;
pub(super) fn sub_types<'tcx>(
use rustc::hir::def_id::LOCAL_CRATE;
use rustc::mir::*;
use syntax_pos::{Span};
-use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::fx::FxHashMap;
#[derive(Debug)]
use rustc::ty::{self, TyCtxt, Instance, query::TyCtxtAt};
use rustc::ty::layout::{LayoutOf, TyLayout};
use rustc::ty::subst::Subst;
-use rustc_data_structures::indexed_vec::{IndexVec, Idx};
+use rustc_data_structures::indexed_vec::IndexVec;
use syntax::ast::Mutability;
use syntax::source_map::Span;
use rustc::mir::{BasicBlock, Location};
use rustc_data_structures::indexed_set::{HybridIdxSet, IdxSet, Iter};
-use rustc_data_structures::indexed_vec::Idx;
use dataflow::{BitDenotation, BlockSets, DataflowResults};
use dataflow::move_paths::{HasMoveData, MovePathIndex};
use syntax::ast::NodeId;
use rustc::mir::{BasicBlock, Mir};
use rustc_data_structures::bitslice::bits_to_string;
-use rustc_data_structures::indexed_vec::Idx;
use dot;
use dot::IntoCow;
use rustc::{mir, ty};
use rustc::ty::layout::{self, Size, LayoutOf, TyLayout, HasDataLayout, IntegerExt};
-use rustc_data_structures::indexed_vec::Idx;
+
use rustc::mir::interpret::{
GlobalId, AllocId,
ConstValue, Pointer, Scalar, ScalarMaybeUndef,
use rustc::mir;
use rustc::ty::{self, Ty};
use rustc::ty::layout::{self, Size, Align, LayoutOf, TyLayout, HasDataLayout};
-use rustc_data_structures::indexed_vec::Idx;
use rustc_data_structures::stable_hasher::{HashStable, StableHasher, StableHasherResult};
use rustc::mir::interpret::{
use transform::{MirPass, MirSource};
use syntax::source_map::{Span, DUMMY_SP};
use rustc::ty::subst::Substs;
-use rustc_data_structures::indexed_vec::{IndexVec, Idx};
+use rustc_data_structures::indexed_vec::IndexVec;
use rustc::ty::ParamEnv;
use rustc::ty::layout::{
LayoutOf, TyLayout, LayoutError,
self.ecx.tcx.span = source_info.span;
let lint_root = match self.mir.source_scope_local_data {
ClearCrossCrate::Set(ref ivs) => {
- use rustc_data_structures::indexed_vec::Idx;
//FIXME(#51314): remove this check
if source_info.scope.index() >= ivs.len() {
return None;
use rustc::mir::*;
use rustc::util::nodemap::FxHashMap;
use rustc_data_structures::indexed_set::IdxSet;
-use rustc_data_structures::indexed_vec::Idx;
use transform::{MirPass, MirSource};
use util::patch::MirPatch;
use util::elaborate_drops::{DropFlagState, Unwind, elaborate_drop};
use rustc_data_structures::bitvec::BitArray;
use rustc_data_structures::indexed_set::IdxSet;
-use rustc_data_structures::indexed_vec::{IndexVec, Idx};
+use rustc_data_structures::indexed_vec::IndexVec;
use rustc_data_structures::fx::FxHashSet;
use rustc::hir;
use rustc::hir::def_id::DefId;
use rustc::ty::{self, TyCtxt};
use rustc::mir::{self, Mir, Location};
use rustc_data_structures::indexed_set::IdxSet;
-use rustc_data_structures::indexed_vec::Idx;
use transform::{MirPass, MirSource};
use dataflow::{do_dataflow, DebugFormatted};
use std::fmt::Debug;
use std::io::{self, Write};
-use rustc_data_structures::indexed_vec::Idx;
-
use super::pretty::dump_mir_def_ids;
/// Write a graphviz DOT graph of a list of MIRs.