summary refs log tree commit diff
path: root/src/librustc_mir/transform/check_unsafety.rs
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2020-01-27 15:30:31 +0000
committerbors <bors@rust-lang.org>2020-01-27 15:30:31 +0000
commit5e1a799842ba6ed4a57e91f7ab9435947482f7d8 (patch)
tree322e3c225bae8356189d398766651ba7d96ba0d0 /src/librustc_mir/transform/check_unsafety.rs
parent3f41b032eef8b749409b529225f22571075a8aeb (diff)
parent4600d3c594a6ea68aaa944386d14f0c20179861e (diff)
downloadrust-1.41.0.tar.gz
rust-1.41.0.zip
Auto merge of #68568 - pietroalbini:stable-next, r=pietroalbini 1.41.0
[stable] Rust 1.41.0 stable release

This PR produces the 1.41.0 stable release, backporting the following PRs as well:

* #68494: Make pointers to statics internal
* #67928: Update RELEASES.md for 1.41.0

r? @ghost
Diffstat (limited to 'src/librustc_mir/transform/check_unsafety.rs')
-rw-r--r--src/librustc_mir/transform/check_unsafety.rs46
1 files changed, 24 insertions, 22 deletions
diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs
index 284285c327c..7e091413e7b 100644
--- a/src/librustc_mir/transform/check_unsafety.rs
+++ b/src/librustc_mir/transform/check_unsafety.rs
@@ -249,28 +249,30 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
             if let (PlaceBase::Local(local), []) = (&place.base, proj_base) {
                 let decl = &self.body.local_decls[*local];
                 if decl.internal {
-                    // Internal locals are used in the `move_val_init` desugaring.
-                    // We want to check unsafety against the source info of the
-                    // desugaring, rather than the source info of the RHS.
-                    self.source_info = self.body.local_decls[*local].source_info;
-                } else if let LocalInfo::StaticRef { def_id, .. } = decl.local_info {
-                    if self.tcx.is_mutable_static(def_id) {
-                        self.require_unsafe(
-                            "use of mutable static",
-                            "mutable statics can be mutated by multiple threads: aliasing \
-                        violations or data races will cause undefined behavior",
-                            UnsafetyViolationKind::General,
-                        );
-                        return;
-                    } else if self.tcx.is_foreign_item(def_id) {
-                        self.require_unsafe(
-                            "use of extern static",
-                            "extern statics are not controlled by the Rust type system: \
-                        invalid data, aliasing violations or data races will cause \
-                        undefined behavior",
-                            UnsafetyViolationKind::General,
-                        );
-                        return;
+                    if let LocalInfo::StaticRef { def_id, .. } = decl.local_info {
+                        if self.tcx.is_mutable_static(def_id) {
+                            self.require_unsafe(
+                                "use of mutable static",
+                                "mutable statics can be mutated by multiple threads: aliasing \
+                            violations or data races will cause undefined behavior",
+                                UnsafetyViolationKind::General,
+                            );
+                            return;
+                        } else if self.tcx.is_foreign_item(def_id) {
+                            self.require_unsafe(
+                                "use of extern static",
+                                "extern statics are not controlled by the Rust type system: \
+                            invalid data, aliasing violations or data races will cause \
+                            undefined behavior",
+                                UnsafetyViolationKind::General,
+                            );
+                            return;
+                        }
+                    } else {
+                        // Internal locals are used in the `move_val_init` desugaring.
+                        // We want to check unsafety against the source info of the
+                        // desugaring, rather than the source info of the RHS.
+                        self.source_info = self.body.local_decls[*local].source_info;
                     }
                 }
             }