]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #55912 - kennytm:rollup, r=kennytm
authorbors <bors@rust-lang.org>
Tue, 13 Nov 2018 22:17:46 +0000 (22:17 +0000)
committerbors <bors@rust-lang.org>
Tue, 13 Nov 2018 22:17:46 +0000 (22:17 +0000)
Rollup of 20 pull requests

Successful merges:

 - #55136 (Remove short doc where it starts with a codeblock)
 - #55711 (Format BtreeMap::range_mut example)
 - #55722 (impl_stable_hash_for: support enums and tuple structs with generic parameters)
 - #55754 (Avoid converting bytes to UTF-8 strings to print, just pass bytes to stdout/err)
 - #55804 (rustdoc: don't inline `pub use some_crate` unless directly asked to)
 - #55805 (Move `static_assert!` into librustc_data_structures)
 - #55837 (Make PhantomData #[structural_match])
 - #55840 (Fix TLS errors when downloading stage0)
 - #55843 (add FromIterator<A> to Box<[A]>)
 - #55858 (Small fixes on code blocks in rustdoc)
 - #55863 (Fix a typo in std::panic)
 - #55870 (Fix typos.)
 - #55874 (string: Add documentation for `From` impls)
 - #55879 (save-analysis: Don't panic for macro-generated use globs)
 - #55882 (Reference count `crate_inherent_impls`s return value.)
 - #55888 (miri: for uniformity, also move memory_deallocated to AllocationExtra)
 - #55889 (global allocators: add a few comments)
 - #55896 (Document optimizations enabled by FusedIterator)
 - #55905 (Change `Lit::short_name` to `Lit::literal_name`.)
 - #55908 (Fix their/there grammar nit)

1  2 
src/librustc/mir/mod.rs
src/librustc/ty/context.rs
src/librustc/ty/mod.rs
src/librustc/ty/query/mod.rs
src/librustc_typeck/check/mod.rs
src/librustdoc/clean/mod.rs

diff --combined src/librustc/mir/mod.rs
index 9a0b1c68ddcd54eaa805953c515335affba7e686,73800074cc7e88a18c5992d9976d99eacaaaf04d..548d0e0c7905f096c399543439c5441896f12f12
@@@ -40,7 -40,6 +40,7 @@@ use syntax_pos::{Span, DUMMY_SP}
  use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
  use ty::subst::{CanonicalUserSubsts, Subst, Substs};
  use ty::{self, AdtDef, CanonicalTy, ClosureSubsts, GeneratorSubsts, Region, Ty, TyCtxt};
 +use ty::layout::VariantIdx;
  use util::ppaux;
  
  pub use mir::interpret::AssertMessage;
@@@ -1720,14 -1719,14 +1720,14 @@@ pub struct Statement<'tcx> 
      pub kind: StatementKind<'tcx>,
  }
  
+ // `Statement` is used a lot. Make sure it doesn't unintentionally get bigger.
+ #[cfg(target_arch = "x86_64")]
+ static_assert!(MEM_SIZE_OF_STATEMENT: mem::size_of::<Statement<'_>>() == 56);
  impl<'tcx> Statement<'tcx> {
      /// Changes a statement to a nop. This is both faster than deleting instructions and avoids
      /// invalidating statement indices in `Location`s.
      pub fn make_nop(&mut self) {
-         // `Statement` contributes significantly to peak memory usage. Make
-         // sure it doesn't get bigger.
-         static_assert!(STATEMENT_IS_AT_MOST_56_BYTES: mem::size_of::<Statement<'_>>() <= 56);
          self.kind = StatementKind::Nop
      }
  
@@@ -1754,7 -1753,7 +1754,7 @@@ pub enum StatementKind<'tcx> 
      /// Write the discriminant for a variant to the enum Place.
      SetDiscriminant {
          place: Place<'tcx>,
 -        variant_index: usize,
 +        variant_index: VariantIdx,
      },
  
      /// Start a live range for the storage of the local.
@@@ -1940,7 -1939,7 +1940,7 @@@ pub enum ProjectionElem<'tcx, V, T> 
      /// "Downcast" to a variant of an ADT. Currently, we only introduce
      /// this for ADTs with more than one variant. It may be better to
      /// just introduce it always, or always for enums.
 -    Downcast(&'tcx AdtDef, usize),
 +    Downcast(&'tcx AdtDef, VariantIdx),
  }
  
  /// Alias for projections as they appear in places, where the base is a place
@@@ -1951,11 -1950,6 +1951,11 @@@ pub type PlaceProjection<'tcx> = Projec
  /// and the index is a local.
  pub type PlaceElem<'tcx> = ProjectionElem<'tcx, Local, Ty<'tcx>>;
  
 +// at least on 64 bit systems, `PlaceElem` should not be larger than two pointers
 +static_assert!(PROJECTION_ELEM_IS_2_PTRS_LARGE:
 +    mem::size_of::<PlaceElem<'_>>() <= 16
 +);
 +
  /// Alias for projections as they appear in `UserTypeProjection`, where we
  /// need neither the `V` parameter for `Index` nor the `T` for `Field`.
  pub type ProjectionKind<'tcx> = ProjectionElem<'tcx, (), ()>;
@@@ -1975,7 -1969,7 +1975,7 @@@ impl<'tcx> Place<'tcx> 
          self.elem(ProjectionElem::Deref)
      }
  
 -    pub fn downcast(self, adt_def: &'tcx AdtDef, variant_index: usize) -> Place<'tcx> {
 +    pub fn downcast(self, adt_def: &'tcx AdtDef, variant_index: VariantIdx) -> Place<'tcx> {
          self.elem(ProjectionElem::Downcast(adt_def, variant_index))
      }
  
@@@ -2217,7 -2211,7 +2217,7 @@@ pub enum AggregateKind<'tcx> 
      /// active field index would identity the field `c`
      Adt(
          &'tcx AdtDef,
 -        usize,
 +        VariantIdx,
          &'tcx Substs<'tcx>,
          Option<UserTypeAnnotation<'tcx>>,
          Option<usize>,
@@@ -2617,7 -2611,7 +2617,7 @@@ pub fn fmt_const_val(f: &mut impl Write
              _ => {}
          }
      }
-     // print function definitons
+     // print function definitions
      if let FnDef(did, _) = ty.sty {
          return write!(f, "{}", item_path_str(did));
      }
index a86a56a45cd646bc56832ef21023b86d55aac616,f78fad9f7aa9a432a5e0a6bc5f88ad453ae8e43d..cdfe8f53b854b96774f75a92b0c0bfcda80097e1
@@@ -45,7 -45,7 +45,7 @@@ use ty::RegionKind
  use ty::{TyVar, TyVid, IntVar, IntVid, FloatVar, FloatVid};
  use ty::TyKind::*;
  use ty::GenericParamDefKind;
 -use ty::layout::{LayoutDetails, TargetDataLayout};
 +use ty::layout::{LayoutDetails, TargetDataLayout, VariantIdx};
  use ty::query;
  use ty::steal::Steal;
  use ty::BindingMode;
@@@ -823,12 -823,6 +823,6 @@@ impl<'a, 'gcx> HashStable<StableHashing
  
  impl<'tcx> CommonTypes<'tcx> {
      fn new(interners: &CtxtInterners<'tcx>) -> CommonTypes<'tcx> {
-         // Ensure our type representation does not grow
-         #[cfg(target_pointer_width = "64")]
-         static_assert!(ASSERT_TY_KIND: ::std::mem::size_of::<ty::TyKind<'_>>() <= 24);
-         #[cfg(target_pointer_width = "64")]
-         static_assert!(ASSERT_TYS: ::std::mem::size_of::<ty::TyS<'_>>() <= 32);
          let mk = |sty| CtxtInterners::intern_ty(interners, interners, sty);
          let mk_region = |r| {
              if let Some(r) = interners.region.borrow().get(&r) {
@@@ -1009,7 -1003,7 +1003,7 @@@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, '
      pub fn alloc_adt_def(self,
                           did: DefId,
                           kind: AdtKind,
 -                         variants: Vec<ty::VariantDef>,
 +                         variants: IndexVec<VariantIdx, ty::VariantDef>,
                           repr: ReprOptions)
                           -> &'gcx ty::AdtDef {
          let def = ty::AdtDef::new(self, did, kind, variants, repr);
diff --combined src/librustc/ty/mod.rs
index 83feadd50d77fa4e15b3b55feb5e8a8ad391ec3e,979cc9b115b5a2e6307631e1dd035956553eab2f..8197136d189aec581ca0d286c1bdb0c66a24d7d3
@@@ -32,7 -32,6 +32,7 @@@ use mir::GeneratorLayout
  use session::CrateDisambiguator;
  use traits::{self, Reveal};
  use ty;
 +use ty::layout::VariantIdx;
  use ty::subst::{Subst, Substs};
  use ty::util::{IntTypeExt, Discr};
  use ty::walk::TypeWalker;
@@@ -58,7 -57,7 +58,7 @@@ use syntax::symbol::{keywords, Symbol, 
  use syntax_pos::{DUMMY_SP, Span};
  
  use smallvec;
 -use rustc_data_structures::indexed_vec::Idx;
 +use rustc_data_structures::indexed_vec::{Idx, IndexVec};
  use rustc_data_structures::stable_hasher::{StableHasher, StableHasherResult,
                                             HashStable};
  
@@@ -515,6 -514,10 +515,10 @@@ pub struct TyS<'tcx> 
      outer_exclusive_binder: ty::DebruijnIndex,
  }
  
+ // `TyS` is used a lot. Make sure it doesn't unintentionally get bigger.
+ #[cfg(target_arch = "x86_64")]
+ static_assert!(MEM_SIZE_OF_TY_S: ::std::mem::size_of::<TyS<'_>>() == 32);
  impl<'tcx> Ord for TyS<'tcx> {
      fn cmp(&self, other: &TyS<'tcx>) -> Ordering {
          self.sty.cmp(&other.sty)
@@@ -1786,7 -1789,7 +1790,7 @@@ pub enum VariantDiscr 
      /// For efficiency reasons, the distance from the
      /// last `Explicit` discriminant is being stored,
      /// or `0` for the first variant, if it has none.
 -    Relative(usize),
 +    Relative(u32),
  }
  
  #[derive(Debug)]
@@@ -1802,7 -1805,7 +1806,7 @@@ pub struct FieldDef 
  /// table.
  pub struct AdtDef {
      pub did: DefId,
 -    pub variants: Vec<VariantDef>,
 +    pub variants: IndexVec<self::layout::VariantIdx, VariantDef>,
      flags: AdtFlags,
      pub repr: ReprOptions,
  }
@@@ -2000,7 -2003,7 +2004,7 @@@ impl<'a, 'gcx, 'tcx> AdtDef 
      fn new(tcx: TyCtxt<'_, '_, '_>,
             did: DefId,
             kind: AdtKind,
 -           variants: Vec<VariantDef>,
 +           variants: IndexVec<VariantIdx, VariantDef>,
             repr: ReprOptions) -> Self {
          debug!("AdtDef::new({:?}, {:?}, {:?}, {:?})", did, kind, variants, repr);
          let mut flags = AdtFlags::NO_ADT_FLAGS;
      /// Asserts this is a struct or union and returns its unique variant.
      pub fn non_enum_variant(&self) -> &VariantDef {
          assert!(self.is_struct() || self.is_union());
 -        &self.variants[0]
 +        &self.variants[VariantIdx::new(0)]
      }
  
      #[inline]
              .expect("variant_with_id: unknown variant")
      }
  
 -    pub fn variant_index_with_id(&self, vid: DefId) -> usize {
 +    pub fn variant_index_with_id(&self, vid: DefId) -> VariantIdx {
          self.variants
 -            .iter()
 -            .position(|v| v.did == vid)
 +            .iter_enumerated()
 +            .find(|(_, v)| v.did == vid)
              .expect("variant_index_with_id: unknown variant")
 +            .0
      }
  
      pub fn variant_of_def(&self, def: Def) -> &VariantDef {
      pub fn discriminants(
          &'a self,
          tcx: TyCtxt<'a, 'gcx, 'tcx>,
 -    ) -> impl Iterator<Item=Discr<'tcx>> + Captures<'gcx> + 'a {
 +    ) -> impl Iterator<Item=(VariantIdx, Discr<'tcx>)> + Captures<'gcx> + 'a {
          let repr_type = self.repr.discr_type();
          let initial = repr_type.initial_discriminant(tcx.global_tcx());
          let mut prev_discr = None::<Discr<'tcx>>;
 -        self.variants.iter().map(move |v| {
 +        self.variants.iter_enumerated().map(move |(i, v)| {
              let mut discr = prev_discr.map_or(initial, |d| d.wrap_incr(tcx));
              if let VariantDiscr::Explicit(expr_did) = v.discr {
                  if let Some(new_discr) = self.eval_explicit_discr(tcx, expr_did) {
              }
              prev_discr = Some(discr);
  
 -            discr
 +            (i, discr)
          })
      }
  
      /// assuming there are no constant-evaluation errors there.
      pub fn discriminant_for_variant(&self,
                                      tcx: TyCtxt<'a, 'gcx, 'tcx>,
 -                                    variant_index: usize)
 +                                    variant_index: VariantIdx)
                                      -> Discr<'tcx> {
          let (val, offset) = self.discriminant_def_for_variant(variant_index);
          let explicit_value = val
      /// inferred discriminant directly
      pub fn discriminant_def_for_variant(
          &self,
 -        variant_index: usize,
 -    ) -> (Option<DefId>, usize) {
 -        let mut explicit_index = variant_index;
 +        variant_index: VariantIdx,
 +    ) -> (Option<DefId>, u32) {
 +        let mut explicit_index = variant_index.as_u32();
          let expr_did;
          loop {
 -            match self.variants[explicit_index].discr {
 +            match self.variants[VariantIdx::from_u32(explicit_index)].discr {
                  ty::VariantDiscr::Relative(0) => {
                      expr_did = None;
                      break;
                  }
              }
          }
 -        (expr_did, variant_index - explicit_index)
 +        (expr_did, variant_index.as_u32() - explicit_index)
      }
  
      pub fn destructor(&self, tcx: TyCtxt<'a, 'gcx, 'tcx>) -> Option<Destructor> {
index c834166e67d881bdcae92e73212d9a982d9b37f9,27eafa7ab580f2b1c87c1d6f1df7ff044db88e6c..c82a44011db6c95d00b0323ad8734a8b97c94405
@@@ -291,7 -291,8 +291,8 @@@ define_queries! { <'tcx
          /// Gets a complete map from all types to their inherent impls.
          /// Not meant to be used directly outside of coherence.
          /// (Defined only for LOCAL_CRATE)
-         [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum) -> CrateInherentImpls,
+         [] fn crate_inherent_impls: crate_inherent_impls_dep_node(CrateNum)
+             -> Lrc<CrateInherentImpls>,
  
          /// Checks all types in the krate for overlap in their inherent impls. Reports errors.
          /// Not meant to be used directly outside of coherence.
          ) -> Clauses<'tcx>,
  
          // Get the chalk-style environment of the given item.
 -        [] fn environment: Environment(DefId) -> traits::Environment<'tcx>,
 +        [] fn environment: Environment(DefId) -> ty::Binder<traits::Environment<'tcx>>,
      },
  
      Linking {
index 41e0c6c0a19722f45d057f611869cee78e5185c3,091af449095aab80ef0876465dba968cdc1ab423..e3a6f92d79e5b74ed9002313c656e86a09a54225
@@@ -103,8 -103,6 +103,8 @@@ use rustc::ty::adjustment::{Adjust, Adj
  use rustc::ty::fold::TypeFoldable;
  use rustc::ty::query::Providers;
  use rustc::ty::util::{Representability, IntTypeExt, Discr};
 +use rustc::ty::layout::VariantIdx;
 +use rustc_data_structures::indexed_vec::Idx;
  use errors::{Applicability, DiagnosticBuilder, DiagnosticId};
  
  use require_c_abi_if_variadic;
@@@ -550,7 -548,7 +550,7 @@@ pub struct FnCtxt<'a, 'gcx: 'a+'tcx, 't
      /// current expression. As each subpart is processed, they may set
      /// the flag to `Always` etc.  Finally, at the end, we take the
      /// result and "union" it with the original value, so that when we
-     /// return the flag indicates if any subpart of the the parent
+     /// return the flag indicates if any subpart of the parent
      /// expression (up to and including this part) has diverged.  So,
      /// if you read it after evaluating a subexpression `X`, the value
      /// you get indicates whether any subexpression that was
@@@ -1839,11 -1837,10 +1839,11 @@@ pub fn check_enum<'a, 'tcx>(tcx: TyCtxt
      }
  
      let mut disr_vals: Vec<Discr<'tcx>> = Vec::with_capacity(vs.len());
 -    for (discr, v) in def.discriminants(tcx).zip(vs) {
 +    for ((_, discr), v) in def.discriminants(tcx).zip(vs) {
          // Check for duplicate discriminant values
          if let Some(i) = disr_vals.iter().position(|&x| x.val == discr.val) {
 -            let variant_i_node_id = tcx.hir.as_local_node_id(def.variants[i].did).unwrap();
 +            let variant_did = def.variants[VariantIdx::new(i)].did;
 +            let variant_i_node_id = tcx.hir.as_local_node_id(variant_did).unwrap();
              let variant_i = tcx.hir.expect_variant(variant_i_node_id);
              let i_span = match variant_i.node.disr_expr {
                  Some(ref expr) => tcx.hir.span(expr.id),
@@@ -1921,11 -1918,11 +1921,11 @@@ impl<'a, 'gcx, 'tcx> AstConv<'gcx, 'tcx
                                          poly_trait_ref: ty::PolyTraitRef<'tcx>)
                                          -> Ty<'tcx>
      {
 -        let (trait_ref, _) =
 -            self.replace_late_bound_regions_with_fresh_var(
 -                span,
 -                infer::LateBoundRegionConversionTime::AssocTypeProjection(item_def_id),
 -                &poly_trait_ref);
 +        let (trait_ref, _) = self.replace_bound_vars_with_fresh_vars(
 +            span,
 +            infer::LateBoundRegionConversionTime::AssocTypeProjection(item_def_id),
 +            &poly_trait_ref
 +        );
  
          self.tcx().mk_projection(item_def_id, trait_ref.substs)
      }
index 77782c19b725238b881eedc0290a3bbf878b934b,5a020749f3577d4b2eaaf351d13ced1a26bb612d..931ba21f6e4bd8ef66182e089e81b7bbc2c91a41
@@@ -38,12 -38,10 +38,12 @@@ use rustc::hir::def::{self, Def, CtorKi
  use rustc::hir::def_id::{CrateNum, DefId, CRATE_DEF_INDEX, LOCAL_CRATE};
  use rustc::ty::subst::Substs;
  use rustc::ty::{self, TyCtxt, Region, RegionVid, Ty, AdtKind};
 +use rustc::ty::layout::VariantIdx;
  use rustc::middle::stability;
  use rustc::util::nodemap::{FxHashMap, FxHashSet};
  use rustc_typeck::hir_ty_to_ty;
  use rustc::infer::region_constraints::{RegionConstraintData, Constraint};
 +use rustc_data_structures::indexed_vec::{IndexVec, Idx};
  
  use std::collections::hash_map::Entry;
  use std::fmt;
@@@ -100,12 -98,6 +100,12 @@@ impl<T: Clean<U>, U> Clean<Vec<U>> for 
      }
  }
  
 +impl<T: Clean<U>, U, V: Idx> Clean<IndexVec<V, U>> for IndexVec<V, T> {
 +    fn clean(&self, cx: &DocContext) -> IndexVec<V, U> {
 +        self.iter().map(|x| x.clean(cx)).collect()
 +    }
 +}
 +
  impl<T: Clean<U>, U> Clean<U> for P<T> {
      fn clean(&self, cx: &DocContext) -> U {
          (**self).clean(cx)
@@@ -1325,10 -1317,15 +1325,10 @@@ impl<'a> Clean<WherePredicate> for ty::
              Predicate::RegionOutlives(ref pred) => pred.clean(cx),
              Predicate::TypeOutlives(ref pred) => pred.clean(cx),
              Predicate::Projection(ref pred) => pred.clean(cx),
 -            Predicate::WellFormed(ty) => {
 -                // This comes from `where Ty:` (i.e. no bounds) (see #53696).
 -                WherePredicate::BoundPredicate {
 -                    ty: ty.clean(cx),
 -                    bounds: vec![],
 -                }
 -            }
 -            Predicate::ObjectSafe(_) => panic!("not user writable"),
 -            Predicate::ClosureKind(..) => panic!("not user writable"),
 +
 +            Predicate::WellFormed(..) |
 +            Predicate::ObjectSafe(..) |
 +            Predicate::ClosureKind(..) |
              Predicate::ConstEvaluatable(..) => panic!("not user writable"),
          }
      }
@@@ -2889,7 -2886,7 +2889,7 @@@ impl Clean<VariantStruct> for ::rustc::
  
  #[derive(Clone, RustcEncodable, RustcDecodable, Debug)]
  pub struct Enum {
 -    pub variants: Vec<Item>,
 +    pub variants: IndexVec<VariantIdx, Item>,
      pub generics: Generics,
      pub variants_stripped: bool,
  }
@@@ -2905,7 -2902,7 +2905,7 @@@ impl Clean<Item> for doctree::Enum 
              stability: self.stab.clean(cx),
              deprecation: self.depr.clean(cx),
              inner: EnumItem(Enum {
 -                variants: self.variants.clean(cx),
 +                variants: self.variants.iter().map(|v| v.clean(cx)).collect(),
                  generics: self.generics.clean(cx),
                  variants_stripped: false,
              }),
@@@ -3502,13 -3499,16 +3502,16 @@@ impl Clean<Vec<Item>> for doctree::Impo
          // forcefully don't inline if this is not public or if the
          // #[doc(no_inline)] attribute is present.
          // Don't inline doc(hidden) imports so they can be stripped at a later stage.
-         let denied = !self.vis.node.is_pub() || self.attrs.iter().any(|a| {
+         let mut denied = !self.vis.node.is_pub() || self.attrs.iter().any(|a| {
              a.name() == "doc" && match a.meta_item_list() {
                  Some(l) => attr::list_contains_name(&l, "no_inline") ||
                             attr::list_contains_name(&l, "hidden"),
                  None => false,
              }
          });
+         // Also check whether imports were asked to be inlined, in case we're trying to re-export a
+         // crate in Rust 2018+
+         let please_inline = self.attrs.lists("doc").has_word("inline");
          let path = self.path.clean(cx);
          let inner = if self.glob {
              if !denied {
              Import::Glob(resolve_use_source(cx, path))
          } else {
              let name = self.name;
+             if !please_inline {
+                 match path.def {
+                     Def::Mod(did) => if !did.is_local() && did.index == CRATE_DEF_INDEX {
+                         // if we're `pub use`ing an extern crate root, don't inline it unless we
+                         // were specifically asked for it
+                         denied = true;
+                     }
+                     _ => {}
+                 }
+             }
              if !denied {
                  let mut visited = FxHashSet::default();
                  if let Some(items) = inline::try_inline(cx, path.def, name, &mut visited) {