]> git.lizzy.rs Git - rust.git/commitdiff
Rollup merge of #70913 - eddyb:rc-arc-diagnostic-items, r=matthewjasper
authorMazdak Farrokhzad <twingoow@gmail.com>
Fri, 10 Apr 2020 10:48:45 +0000 (12:48 +0200)
committerGitHub <noreply@github.com>
Fri, 10 Apr 2020 10:48:45 +0000 (12:48 +0200)
Replace "rc"/"arc" lang items with Rc/Arc diagnostic items.

`Rc`/`Arc` should have no special semantics, so it seems appropriate for them to not be lang items.

r? @matthewjasper

1  2 
src/librustc_middle/ty/context.rs
src/librustc_middle/ty/mod.rs
src/librustc_middle/ty/sty.rs

index 6e504a107a3f36a2477f136d3b28083636dea9b2,076134b8e9462c630cb61459331d40d084ff277a..b336a30e3d338fa2f7f9ff9872682ca203fc7ac0
@@@ -1162,17 -1162,17 +1162,17 @@@ impl<'tcx> TyCtxt<'tcx> 
              maybe_unused_trait_imports: resolutions
                  .maybe_unused_trait_imports
                  .into_iter()
 -                .map(|id| definitions.local_def_id(id))
 +                .map(|id| definitions.local_def_id(id).to_def_id())
                  .collect(),
              maybe_unused_extern_crates: resolutions
                  .maybe_unused_extern_crates
                  .into_iter()
 -                .map(|(id, sp)| (definitions.local_def_id(id), sp))
 +                .map(|(id, sp)| (definitions.local_def_id(id).to_def_id(), sp))
                  .collect(),
              glob_map: resolutions
                  .glob_map
                  .into_iter()
 -                .map(|(id, names)| (definitions.local_def_id(id), names))
 +                .map(|(id, names)| (definitions.local_def_id(id).to_def_id(), names))
                  .collect(),
              extern_prelude: resolutions.extern_prelude,
              untracked_crate: krate,
@@@ -2065,6 -2065,10 +2065,6 @@@ macro_rules! direct_interners 
      }
  }
  
 -pub fn keep_local<'tcx, T: ty::TypeFoldable<'tcx>>(x: &T) -> bool {
 -    x.has_type_flags(ty::TypeFlags::KEEP_IN_LOCAL_TCX)
 -}
 -
  direct_interners!(
      region: mk_region(RegionKind),
      goal: mk_goal(GoalKind<'tcx>),
@@@ -2209,6 -2213,12 +2209,12 @@@ impl<'tcx> TyCtxt<'tcx> 
          Some(self.mk_generic_adt(def_id, ty))
      }
  
+     #[inline]
+     pub fn mk_diagnostic_item(self, ty: Ty<'tcx>, name: Symbol) -> Option<Ty<'tcx>> {
+         let def_id = self.get_diagnostic_item(name)?;
+         Some(self.mk_generic_adt(def_id, ty))
+     }
      #[inline]
      pub fn mk_maybe_uninit(self, ty: Ty<'tcx>) -> Ty<'tcx> {
          let def_id = self.require_lang_item(lang_items::MaybeUninitLangItem, None);
index 18518e78e3556558f6bea58a8263f17ad2e53a4c,3683ea3288feb10909c1260b72dc12939db67f7d..8dbf27b0ed872c85f0a7a3545f5c75da5d517e4e
@@@ -71,7 -71,7 +71,7 @@@ pub use crate::ty::diagnostics::*
  pub use self::binding::BindingMode;
  pub use self::binding::BindingMode::*;
  
 -pub use self::context::{keep_local, tls, FreeRegionInfo, TyCtxt};
 +pub use self::context::{tls, FreeRegionInfo, TyCtxt};
  pub use self::context::{
      CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, ResolvedOpaqueTy,
      UserType, UserTypeAnnotationIndex,
@@@ -577,23 -577,50 +577,23 @@@ bitflags! 
                                            | TypeFlags::HAS_TY_OPAQUE.bits
                                            | TypeFlags::HAS_CT_PROJECTION.bits;
  
 -        /// Present if the type belongs in a local type context.
 -        /// Set for placeholders and inference variables that are not "Fresh".
 -        const KEEP_IN_LOCAL_TCX           = 1 << 13;
 -
          /// Is an error type reachable?
 -        const HAS_TY_ERR                  = 1 << 14;
 +        const HAS_TY_ERR                  = 1 << 13;
  
          /// Does this have any region that "appears free" in the type?
          /// Basically anything but [ReLateBound] and [ReErased].
 -        const HAS_FREE_REGIONS            = 1 << 15;
 +        const HAS_FREE_REGIONS            = 1 << 14;
  
          /// Does this have any [ReLateBound] regions? Used to check
          /// if a global bound is safe to evaluate.
 -        const HAS_RE_LATE_BOUND           = 1 << 16;
 +        const HAS_RE_LATE_BOUND           = 1 << 15;
  
          /// Does this have any [ReErased] regions?
 -        const HAS_RE_ERASED               = 1 << 17;
 +        const HAS_RE_ERASED               = 1 << 16;
  
          /// Does this value have parameters/placeholders/inference variables which could be
          /// replaced later, in a way that would change the results of `impl` specialization?
 -        const STILL_FURTHER_SPECIALIZABLE = 1 << 18;
 -
 -        /// Flags representing the nominal content of a type,
 -        /// computed by FlagsComputation. If you add a new nominal
 -        /// flag, it should be added here too.
 -        const NOMINAL_FLAGS               = TypeFlags::HAS_TY_PARAM.bits
 -                                          | TypeFlags::HAS_RE_PARAM.bits
 -                                          | TypeFlags::HAS_CT_PARAM.bits
 -                                          | TypeFlags::HAS_TY_INFER.bits
 -                                          | TypeFlags::HAS_RE_INFER.bits
 -                                          | TypeFlags::HAS_CT_INFER.bits
 -                                          | TypeFlags::HAS_TY_PLACEHOLDER.bits
 -                                          | TypeFlags::HAS_RE_PLACEHOLDER.bits
 -                                          | TypeFlags::HAS_CT_PLACEHOLDER.bits
 -                                          | TypeFlags::HAS_FREE_LOCAL_REGIONS.bits
 -                                          | TypeFlags::HAS_TY_PROJECTION.bits
 -                                          | TypeFlags::HAS_TY_OPAQUE.bits
 -                                          | TypeFlags::HAS_CT_PROJECTION.bits
 -                                          | TypeFlags::KEEP_IN_LOCAL_TCX.bits
 -                                          | TypeFlags::HAS_TY_ERR.bits
 -                                          | TypeFlags::HAS_FREE_REGIONS.bits
 -                                          | TypeFlags::HAS_RE_LATE_BOUND.bits
 -                                          | TypeFlags::HAS_RE_ERASED.bits
 -                                          | TypeFlags::STILL_FURTHER_SPECIALIZABLE.bits;
 +        const STILL_FURTHER_SPECIALIZABLE = 1 << 17;
      }
  }
  
@@@ -1829,14 -1856,9 +1829,9 @@@ bitflags! 
          const IS_BOX              = 1 << 6;
          /// Indicates whether the type is `ManuallyDrop`.
          const IS_MANUALLY_DROP    = 1 << 7;
-         // FIXME(matthewjasper) replace these with diagnostic items
-         /// Indicates whether the type is an `Arc`.
-         const IS_ARC              = 1 << 8;
-         /// Indicates whether the type is an `Rc`.
-         const IS_RC               = 1 << 9;
          /// Indicates whether the variant list of this ADT is `#[non_exhaustive]`.
          /// (i.e., this flag is never set unless this ADT is an enum).
-         const IS_VARIANT_LIST_NON_EXHAUSTIVE = 1 << 10;
+         const IS_VARIANT_LIST_NON_EXHAUSTIVE = 1 << 8;
      }
  }
  
@@@ -2221,12 -2243,6 +2216,6 @@@ impl<'tcx> AdtDef 
          if Some(did) == tcx.lang_items().manually_drop() {
              flags |= AdtFlags::IS_MANUALLY_DROP;
          }
-         if Some(did) == tcx.lang_items().arc() {
-             flags |= AdtFlags::IS_ARC;
-         }
-         if Some(did) == tcx.lang_items().rc() {
-             flags |= AdtFlags::IS_RC;
-         }
  
          AdtDef { did, variants, flags, repr }
      }
          self.flags.contains(AdtFlags::IS_PHANTOM_DATA)
      }
  
-     /// Returns `true` if this is `Arc<T>`.
-     pub fn is_arc(&self) -> bool {
-         self.flags.contains(AdtFlags::IS_ARC)
-     }
-     /// Returns `true` if this is `Rc<T>`.
-     pub fn is_rc(&self) -> bool {
-         self.flags.contains(AdtFlags::IS_RC)
-     }
      /// Returns `true` if this is Box<T>.
      #[inline]
      pub fn is_box(&self) -> bool {
index 392abf37ba598fa5f70d6b1978fbeb6cd4abba11,fbd5049b0fbcb6789abeaa64ae463f736e04fa90..081e6f06b331155b01e8909e20b83dcc1ecaedbb
@@@ -1605,6 -1605,7 +1605,6 @@@ impl RegionKind 
                  flags = flags | TypeFlags::HAS_FREE_REGIONS;
                  flags = flags | TypeFlags::HAS_FREE_LOCAL_REGIONS;
                  flags = flags | TypeFlags::HAS_RE_INFER;
 -                flags = flags | TypeFlags::KEEP_IN_LOCAL_TCX;
                  flags = flags | TypeFlags::STILL_FURTHER_SPECIALIZABLE;
              }
              ty::RePlaceholder(..) => {
@@@ -1864,24 -1865,6 +1864,6 @@@ impl<'tcx> TyS<'tcx> 
          self.is_region_ptr() || self.is_unsafe_ptr() || self.is_fn_ptr()
      }
  
-     /// Returns `true` if this type is an `Arc<T>`.
-     #[inline]
-     pub fn is_arc(&self) -> bool {
-         match self.kind {
-             Adt(def, _) => def.is_arc(),
-             _ => false,
-         }
-     }
-     /// Returns `true` if this type is an `Rc<T>`.
-     #[inline]
-     pub fn is_rc(&self) -> bool {
-         match self.kind {
-             Adt(def, _) => def.is_rc(),
-             _ => false,
-         }
-     }
      #[inline]
      pub fn is_box(&self) -> bool {
          match self.kind {
@@@ -2360,8 -2343,8 +2342,8 @@@ impl<'tcx> Const<'tcx> 
          let try_const_eval = |did, param_env: ParamEnv<'tcx>, substs, promoted| {
              let param_env_and_substs = param_env.with_reveal_all().and(substs);
  
 -            // Avoid querying `tcx.const_eval(...)` with any e.g. inference vars.
 -            if param_env_and_substs.has_local_value() {
 +            // Avoid querying `tcx.const_eval(...)` with any inference vars.
 +            if param_env_and_substs.needs_infer() {
                  return None;
              }
  
  
          match self.val {
              ConstKind::Unevaluated(did, substs, promoted) => {
 -                // HACK(eddyb) when substs contain e.g. inference variables,
 +                // HACK(eddyb) when substs contain inference variables,
                  // attempt using identity substs instead, that will succeed
                  // when the expression doesn't depend on any parameters.
                  // FIXME(eddyb, skinny121) pass `InferCtxt` into here when it's available, so that
                  // we can call `infcx.const_eval_resolve` which handles inference variables.
 -                if substs.has_local_value() {
 +                if substs.needs_infer() {
                      let identity_substs = InternalSubsts::identity_for_item(tcx, did);
                      // The `ParamEnv` needs to match the `identity_substs`.
                      let identity_param_env = tcx.param_env(did);