@@ -178,13 +178,16 @@ pub fn intern_const_alloc_recursive<
178178 // promoteds as immutable.
179179 found_bad_mutable_pointer = true ;
180180 }
181- // It is tempting to intern as immutable if `prov.immutable()`. However, there
182- // might be multiple pointers to the same allocation, and if *at least one* of
183- // them is mutable, the allocation must be interned mutably. We will intern the
184- // allocation when we encounter the first pointer. Therefore we always intern
185- // with `inner_mutability`, and furthermore we ensured above that if that is
186- // "immutable", then there are *no* mutable pointers anywhere in the newly
187- // interned memory.
181+ // We always intern with `inner_mutability`, and furthermore we ensured above that if
182+ // that is "immutable", then there are *no* mutable pointers anywhere in the newly
183+ // interned memory -- justifying that we can indeed intern immutably. However this also
184+ // means we can *not* easily intern immutably here if `prov.immutable()` is true and
185+ // `inner_mutability` is `Mut`: there might be other pointers to that allocation, and
186+ // we'd have to somehow check that they are *all* immutable before deciding that this
187+ // allocation can be made immutable. In the future we could consider analyzing all
188+ // pointers before deciding which allocations can be made immutable; but for now we are
189+ // okay with losing some potential for immutability here. This can anyway only affect
190+ // `static mut`.
188191 todo. push ( ( alloc_id, inner_mutability) ) ;
189192 } )
190193 . map_err ( |( ) | {
0 commit comments