Skip to content

Commit bea33cd

Browse files
committed
reachable computation: clarify comments around consts
1 parent aec67e2 commit bea33cd

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

compiler/rustc_passes/src/reachable.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -207,18 +207,20 @@ 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 need to be
211+
// reachable. Everything else is only needed during const-eval and hence
212+
// already available as `mir_for_ctfe`.
213213
match self.tcx.const_eval_poly_to_alloc(item.owner_id.def_id.into()) {
214214
Ok(alloc) => {
215215
let alloc = self.tcx.global_alloc(alloc.alloc_id).unwrap_memory();
216216
self.propagate_from_alloc(alloc);
217217
}
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.
218+
// We can't figure out which value the constant will evaluate to. In
219+
// lieu of that, we have to consider everything mentioned in the const
220+
// initializer reachable, since it *may* end up in the final value.
221221
Err(ErrorHandled::TooGeneric(_)) => self.visit_nested_body(init),
222+
// If there was an error evaluating the const, nothing can be reachable
223+
// via it, and anyway compilation will fail.
222224
Err(ErrorHandled::Reported(..)) => {}
223225
}
224226
}

0 commit comments

Comments
 (0)