]> git.lizzy.rs Git - rust.git/commitdiff
clarify comment on Deref promotion
authorRalf Jung <post@ralfj.de>
Thu, 1 Dec 2022 15:41:49 +0000 (16:41 +0100)
committerRalf Jung <post@ralfj.de>
Thu, 1 Dec 2022 15:42:33 +0000 (16:42 +0100)
compiler/rustc_const_eval/src/transform/promote_consts.rs

index f48bcd9080966dafe2d693b828bb04aee3aafc69..6777fae74f1ca5d00018354072ef0ef5c15e62c3 100644 (file)
@@ -318,14 +318,14 @@ fn validate_place(&mut self, place: PlaceRef<'tcx>) -> Result<(), Unpromotable>
                 match elem {
                     ProjectionElem::Deref => {
                         let mut promotable = false;
+                        // When a static is used by-value, that gets desugared to `*STATIC_ADDR`,
+                        // and we need to be able to promote this. So check if this deref matches
+                        // that specific pattern.
+
                         // We need to make sure this is a `Deref` of a local with no further projections.
                         // Discussion can be found at
                         // https://github.com/rust-lang/rust/pull/74945#discussion_r463063247
                         if let Some(local) = place_base.as_local() {
-                            // This is a special treatment for cases like *&STATIC where STATIC is a
-                            // global static variable.
-                            // This pattern is generated only when global static variables are directly
-                            // accessed and is qualified for promotion safely.
                             if let TempState::Defined { location, .. } = self.temps[local] {
                                 let def_stmt = self.body[location.block]
                                     .statements