Skip to content

Commit 36c884c

Browse files
authoredJun 11, 2024
Rollup merge of #126259 - RalfJung:reachable-const, r=oli-obk
reachable computation: clarify comments around consts Follow-up to #122505
2 parents afce88e + be4cd53 commit 36c884c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed
 

‎compiler/rustc_passes/src/reachable.rs

+9-6
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,21 @@ impl<'tcx> ReachableContext<'tcx> {
207207
}
208208

209209
hir::ItemKind::Const(_, _, init) => {
210-
// Only things actually ending up in the final constant need to be reachable.
211-
// Everything else is either already available as `mir_for_ctfe`, or can't be used
212-
// by codegen anyway.
210+
// Only things actually ending up in the final constant value are reachable
211+
// for codegen. Everything else is only needed during const-eval, so even if
212+
// const-eval happens in a downstream crate, all they need is
213+
// `mir_for_ctfe`.
213214
match self.tcx.const_eval_poly_to_alloc(item.owner_id.def_id.into()) {
214215
Ok(alloc) => {
215216
let alloc = self.tcx.global_alloc(alloc.alloc_id).unwrap_memory();
216217
self.propagate_from_alloc(alloc);
217218
}
218-
// Reachable generic constants will be inlined into other crates
219-
// unconditionally, so we need to make sure that their
220-
// contents are also reachable.
219+
// We can't figure out which value the constant will evaluate to. In
220+
// lieu of that, we have to consider everything mentioned in the const
221+
// initializer reachable, since it *may* end up in the final value.
221222
Err(ErrorHandled::TooGeneric(_)) => self.visit_nested_body(init),
223+
// If there was an error evaluating the const, nothing can be reachable
224+
// via it, and anyway compilation will fail.
222225
Err(ErrorHandled::Reported(..)) => {}
223226
}
224227
}

0 commit comments

Comments
 (0)