]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #74662 - Manishearth:rollup-jdt7t71, r=Manishearth
authorbors <bors@rust-lang.org>
Thu, 23 Jul 2020 00:37:58 +0000 (00:37 +0000)
committerbors <bors@rust-lang.org>
Thu, 23 Jul 2020 00:37:58 +0000 (00:37 +0000)
Rollup of 9 pull requests

Successful merges:

 - #73783 (Detect when `'static` obligation might come from an `impl`)
 - #73868 (Advertise correct stable version for const control flow)
 - #74460 (rustdoc: Always warn when linking from public to private items)
 - #74538 (Guard against non-monomorphized type_id intrinsic call)
 - #74541 (Add the aarch64-apple-darwin target )
 - #74600 (Enable perf try builder)
 - #74618 (Do not ICE on assoc type with bad placeholder)
 - #74631 (rustc_target: Add a target spec option for disabling `--eh-frame-hdr`)
 - #74643 (build: Remove unnecessary `cargo:rerun-if-env-changed` annotations)

Failed merges:

r? @ghost

src/librustc_middle/ty/mod.rs
src/librustc_mir/borrow_check/mod.rs
src/librustc_mir/transform/check_unsafety.rs
src/librustc_mir/transform/mod.rs
src/librustc_mir_build/build/mod.rs

index 9007bd99d7e4b6e8df08b1dbc00477781a0a4d79..a5ddcdfdb0408b8767ef0c75c4534ab44a55b85a 100644 (file)
@@ -1617,12 +1617,33 @@ pub struct WithOptConstParam<T> {
 
 impl<T> WithOptConstParam<T> {
     /// Creates a new `WithOptConstParam` setting `const_param_did` to `None`.
+    #[inline(always)]
     pub fn unknown(did: T) -> WithOptConstParam<T> {
         WithOptConstParam { did, const_param_did: None }
     }
 }
 
 impl WithOptConstParam<LocalDefId> {
+    /// Returns `Some((did, param_did))` if `def_id` is a const argument,
+    /// `None` otherwise.
+    #[inline(always)]
+    pub fn try_lookup(did: LocalDefId, tcx: TyCtxt<'_>) -> Option<(LocalDefId, DefId)> {
+        tcx.opt_const_param_of(did).map(|param_did| (did, param_did))
+    }
+
+    /// In case `self` is unknown but `self.did` is a const argument, this returns
+    /// a `WithOptConstParam` with the correct `const_param_did`.
+    #[inline(always)]
+    pub fn try_upgrade(self, tcx: TyCtxt<'_>) -> Option<WithOptConstParam<LocalDefId>> {
+        if self.const_param_did.is_none() {
+            if let const_param_did @ Some(_) = tcx.opt_const_param_of(self.did) {
+                return Some(WithOptConstParam { did: self.did, const_param_did });
+            }
+        }
+
+        None
+    }
+
     pub fn to_global(self) -> WithOptConstParam<DefId> {
         WithOptConstParam { did: self.did.to_def_id(), const_param_did: self.const_param_did }
     }
index 1972b7149d569fb42a1066dd06eefe71129099a8..76cc03fa60909ba58b605fa105b6928bac3a6ea0 100644 (file)
 
 pub fn provide(providers: &mut Providers) {
     *providers = Providers {
-        mir_borrowck: |tcx, did| mir_borrowck(tcx, ty::WithOptConstParam::unknown(did)),
+        mir_borrowck: |tcx, did| {
+            if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
+                tcx.mir_borrowck_const_arg(def)
+            } else {
+                mir_borrowck(tcx, ty::WithOptConstParam::unknown(did))
+            }
+        },
         mir_borrowck_const_arg: |tcx, (did, param_did)| {
             mir_borrowck(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
         },
@@ -100,12 +106,6 @@ fn mir_borrowck<'tcx>(
     tcx: TyCtxt<'tcx>,
     def: ty::WithOptConstParam<LocalDefId>,
 ) -> &'tcx BorrowCheckResult<'tcx> {
-    if def.const_param_did.is_none() {
-        if let Some(param_did) = tcx.opt_const_param_of(def.did) {
-            return tcx.mir_borrowck_const_arg((def.did, param_did));
-        }
-    }
-
     let (input_body, promoted) = tcx.mir_validated(def);
     debug!("run query mir_borrowck: {}", tcx.def_path_str(def.did.to_def_id()));
 
index 81d7ac089262206aa24957a226f5c50ea627701e..9c06e173bcd5713b2b946af7faa85dd4a341614b 100644 (file)
@@ -439,7 +439,11 @@ fn check_target_features(&mut self, func_did: DefId) {
 pub(crate) fn provide(providers: &mut Providers) {
     *providers = Providers {
         unsafety_check_result: |tcx, def_id| {
-            unsafety_check_result(tcx, ty::WithOptConstParam::unknown(def_id))
+            if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
+                tcx.unsafety_check_result_for_const_arg(def)
+            } else {
+                unsafety_check_result(tcx, ty::WithOptConstParam::unknown(def_id))
+            }
         },
         unsafety_check_result_for_const_arg: |tcx, (did, param_did)| {
             unsafety_check_result(
@@ -499,12 +503,6 @@ fn unsafety_check_result<'tcx>(
     tcx: TyCtxt<'tcx>,
     def: ty::WithOptConstParam<LocalDefId>,
 ) -> &'tcx UnsafetyCheckResult {
-    if def.const_param_did.is_none() {
-        if let Some(param_did) = tcx.opt_const_param_of(def.did) {
-            return tcx.unsafety_check_result_for_const_arg((def.did, param_did));
-        }
-    }
-
     debug!("unsafety_violations({:?})", def);
 
     // N.B., this borrow is valid because all the consumers of
index 51a9e76e762ebe50a66548dd4db53e0214da7417..283e4b289f286925979d94c6733fe9c7867cb058 100644 (file)
@@ -48,8 +48,13 @@ pub(crate) fn provide(providers: &mut Providers) {
     *providers = Providers {
         mir_keys,
         mir_const,
-        mir_const_qualif: |tcx, did| {
-            mir_const_qualif(tcx, ty::WithOptConstParam::unknown(did.expect_local()))
+        mir_const_qualif: |tcx, def_id| {
+            let def_id = def_id.expect_local();
+            if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
+                tcx.mir_const_qualif_const_arg(def)
+            } else {
+                mir_const_qualif(tcx, ty::WithOptConstParam::unknown(def_id))
+            }
         },
         mir_const_qualif_const_arg: |tcx, (did, param_did)| {
             mir_const_qualif(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
@@ -60,7 +65,12 @@ pub(crate) fn provide(providers: &mut Providers) {
         optimized_mir_of_const_arg,
         is_mir_available,
         promoted_mir: |tcx, def_id| {
-            promoted_mir(tcx, ty::WithOptConstParam::unknown(def_id.expect_local()))
+            let def_id = def_id.expect_local();
+            if let Some(def) = ty::WithOptConstParam::try_lookup(def_id, tcx) {
+                tcx.promoted_mir_of_const_arg(def)
+            } else {
+                promoted_mir(tcx, ty::WithOptConstParam::unknown(def_id))
+            }
         },
         promoted_mir_of_const_arg: |tcx, (did, param_did)| {
             promoted_mir(tcx, ty::WithOptConstParam { did, const_param_did: Some(param_did) })
@@ -221,12 +231,6 @@ pub fn run_passes(
 }
 
 fn mir_const_qualif(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> ConstQualifs {
-    if def.const_param_did.is_none() {
-        if let Some(param_did) = tcx.opt_const_param_of(def.did) {
-            return tcx.mir_const_qualif_const_arg((def.did, param_did));
-        }
-    }
-
     let const_kind = tcx.hir().body_const_context(def.did);
 
     // No need to const-check a non-const `fn`.
@@ -266,10 +270,8 @@ fn mir_const<'tcx>(
     tcx: TyCtxt<'tcx>,
     def: ty::WithOptConstParam<LocalDefId>,
 ) -> &'tcx Steal<Body<'tcx>> {
-    if def.const_param_did.is_none() {
-        if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
-            return tcx.mir_const(ty::WithOptConstParam { const_param_did, ..def });
-        }
+    if let Some(def) = def.try_upgrade(tcx) {
+        return tcx.mir_const(def);
     }
 
     // Unsafety check uses the raw mir, so make sure it is run.
@@ -312,10 +314,8 @@ fn mir_validated(
     tcx: TyCtxt<'tcx>,
     def: ty::WithOptConstParam<LocalDefId>,
 ) -> (&'tcx Steal<Body<'tcx>>, &'tcx Steal<IndexVec<Promoted, Body<'tcx>>>) {
-    if def.const_param_did.is_none() {
-        if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
-            return tcx.mir_validated(ty::WithOptConstParam { const_param_did, ..def });
-        }
+    if let Some(def) = def.try_upgrade(tcx) {
+        return tcx.mir_validated(def);
     }
 
     // Ensure that we compute the `mir_const_qualif` for constants at
@@ -357,13 +357,8 @@ fn mir_drops_elaborated_and_const_checked<'tcx>(
     tcx: TyCtxt<'tcx>,
     def: ty::WithOptConstParam<LocalDefId>,
 ) -> &'tcx Steal<Body<'tcx>> {
-    if def.const_param_did.is_none() {
-        if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
-            return tcx.mir_drops_elaborated_and_const_checked(ty::WithOptConstParam {
-                const_param_did,
-                ..def
-            });
-        }
+    if let Some(def) = def.try_upgrade(tcx) {
+        return tcx.mir_drops_elaborated_and_const_checked(def);
     }
 
     // (Mir-)Borrowck uses `mir_validated`, so we have to force it to
@@ -490,8 +485,8 @@ fn run_optimization_passes<'tcx>(
 
 fn optimized_mir<'tcx>(tcx: TyCtxt<'tcx>, did: DefId) -> &'tcx Body<'tcx> {
     let did = did.expect_local();
-    if let Some(param_did) = tcx.opt_const_param_of(did) {
-        tcx.optimized_mir_of_const_arg((did, param_did))
+    if let Some(def) = ty::WithOptConstParam::try_lookup(did, tcx) {
+        tcx.optimized_mir_of_const_arg(def)
     } else {
         tcx.arena.alloc(inner_optimized_mir(tcx, ty::WithOptConstParam::unknown(did)))
     }
@@ -528,12 +523,6 @@ fn promoted_mir<'tcx>(
     tcx: TyCtxt<'tcx>,
     def: ty::WithOptConstParam<LocalDefId>,
 ) -> &'tcx IndexVec<Promoted, Body<'tcx>> {
-    if def.const_param_did.is_none() {
-        if let Some(param_did) = tcx.opt_const_param_of(def.did) {
-            return tcx.promoted_mir_of_const_arg((def.did, param_did));
-        }
-    }
-
     if tcx.is_constructor(def.did.to_def_id()) {
         return tcx.arena.alloc(IndexVec::new());
     }
index eb47195c06278d189fff0ac7c9c8204af936e97e..1e677f3d2aba82693e775972cefab82ce3a1dc38 100644 (file)
     tcx: TyCtxt<'tcx>,
     def: ty::WithOptConstParam<LocalDefId>,
 ) -> &'tcx ty::steal::Steal<Body<'tcx>> {
-    if def.const_param_did.is_none() {
-        if let const_param_did @ Some(_) = tcx.opt_const_param_of(def.did) {
-            return tcx.mir_built(ty::WithOptConstParam { const_param_did, ..def });
-        }
+    if let Some(def) = def.try_upgrade(tcx) {
+        return tcx.mir_built(def);
     }
 
     tcx.alloc_steal_mir(mir_build(tcx, def))