diff options
| author | Ralf Jung <post@ralfj.de> | 2024-01-03 18:26:26 +0100 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2024-01-22 09:28:00 +0100 |
| commit | 2ab85e41789e3996458f1a0578f225669a8e1d84 (patch) | |
| tree | ea47b2965f19deee4c87f0baef911daa03d7ab6c | |
| parent | 73ce868c7e1fa2d6a4d717de59ca326a0f566ea1 (diff) | |
| download | rust-2ab85e41789e3996458f1a0578f225669a8e1d84.tar.gz rust-2ab85e41789e3996458f1a0578f225669a8e1d84.zip | |
reword comment
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/intern.rs | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index a5a94e80b66..751fbfacaad 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -178,13 +178,16 @@ pub fn intern_const_alloc_recursive< // promoteds as immutable. found_bad_mutable_pointer = true; } - // It is tempting to intern as immutable if `prov.immutable()`. However, there - // might be multiple pointers to the same allocation, and if *at least one* of - // them is mutable, the allocation must be interned mutably. We will intern the - // allocation when we encounter the first pointer. Therefore we always intern - // with `inner_mutability`, and furthermore we ensured above that if that is - // "immutable", then there are *no* mutable pointers anywhere in the newly - // interned memory. + // We always intern with `inner_mutability`, and furthermore we ensured above that if + // that is "immutable", then there are *no* mutable pointers anywhere in the newly + // interned memory -- justifying that we can indeed intern immutably. However this also + // means we can *not* easily intern immutably here if `prov.immutable()` is true and + // `inner_mutability` is `Mut`: there might be other pointers to that allocation, and + // we'd have to somehow check that they are *all* immutable before deciding that this + // allocation can be made immutable. In the future we could consider analyzing all + // pointers before deciding which allocations can be made immutable; but for now we are + // okay with losing some potential for immutability here. This can anyway only affect + // `static mut`. todo.push((alloc_id, inner_mutability)); }) .map_err(|()| { |
