about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-03-14 17:19:06 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2024-06-05 15:40:11 +0000
commit22d0073d47e7f82b0943db94babe40420205eb6a (patch)
treefd1af49a10ed94ed9c4aefaa138a281c9d600d05 /compiler/rustc_passes/src
parent50b07aa89970369d2a25203b9426a47a9fec5fb4 (diff)
downloadrust-22d0073d47e7f82b0943db94babe40420205eb6a.tar.gz
rust-22d0073d47e7f82b0943db94babe40420205eb6a.zip
Don't walk the bodies of free constants for reachability.
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/reachable.rs18
1 files changed, 14 insertions, 4 deletions
diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs
index 954a1ab6560..ee632ea5df3 100644
--- a/compiler/rustc_passes/src/reachable.rs
+++ b/compiler/rustc_passes/src/reachable.rs
@@ -29,12 +29,12 @@ use rustc_hir::def::{DefKind, Res};
 use rustc_hir::def_id::{DefId, LocalDefId};
 use rustc_hir::intravisit::{self, Visitor};
 use rustc_hir::Node;
-use rustc_middle::bug;
 use rustc_middle::middle::codegen_fn_attrs::{CodegenFnAttrFlags, CodegenFnAttrs};
 use rustc_middle::middle::privacy::{self, Level};
-use rustc_middle::mir::interpret::{ConstAllocation, GlobalAlloc};
+use rustc_middle::mir::interpret::{ConstAllocation, ErrorHandled, GlobalAlloc};
 use rustc_middle::query::Providers;
 use rustc_middle::ty::{self, ExistentialTraitRef, TyCtxt};
+use rustc_middle::{bug, span_bug};
 use rustc_privacy::DefIdVisitor;
 use rustc_session::config::CrateType;
 use tracing::debug;
@@ -209,8 +209,18 @@ impl<'tcx> ReachableContext<'tcx> {
                     // Reachable constants will be inlined into other crates
                     // unconditionally, so we need to make sure that their
                     // contents are also reachable.
-                    hir::ItemKind::Const(_, _, init) => {
-                        self.visit_nested_body(init);
+                    hir::ItemKind::Const(..) => {
+                        match self.tcx.const_eval_poly_to_alloc(item.owner_id.def_id.into()) {
+                            Ok(alloc) => {
+                                let alloc = self.tcx.global_alloc(alloc.alloc_id).unwrap_memory();
+                                self.propagate_from_alloc(alloc);
+                            }
+                            Err(ErrorHandled::TooGeneric(span)) => span_bug!(
+                                span,
+                                "generic constants aren't implemented in reachability"
+                            ),
+                            Err(ErrorHandled::Reported(..)) => {}
+                        }
                     }
                     hir::ItemKind::Static(..) => {
                         if let Ok(alloc) = self.tcx.eval_static_initializer(item.owner_id.def_id) {