Skip to content

Commit 2e3a8f5

Browse files
committed
Rollup merge of rust-lang#47898 - Aaron1011:static-ref-nll, r=nikomatsakis Fix ICE when assigning references to a static mut with NLL is_unsafe_place only filters out statics in the rhs, not the lhs. Since it's possible to reach that 'Place::Static', we handle statics the same way as we do locals. Fixes rust-lang#47789
2 parents a671944 + bc8e11b commit 2e3a8f5

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/librustc_mir/dataflow/impls/borrows.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,7 @@ impl<'a, 'gcx, 'tcx> Borrows<'a, 'gcx, 'tcx> {
396396
// Issue #46746: Two-phase borrows handles
397397
// stmts of form `Tmp = &mut Borrow` ...
398398
match lhs {
399-
Place::Local(..) => {} // okay
400-
Place::Static(..) => unreachable!(), // (filtered by is_unsafe_place)
399+
Place::Local(..) | Place::Static(..) => {} // okay
401400
Place::Projection(..) => {
402401
// ... can assign into projections,
403402
// e.g. `box (&mut _)`. Current

src/test/run-pass/issue-47789.rs

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
12+
#![feature(nll)]
13+
14+
static mut x: &'static u32 = &0;
15+
16+
fn foo() {
17+
unsafe { x = &1; }
18+
}
19+
20+
fn main() { }

0 commit comments

Comments
 (0)