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 #47789
This commit is contained in:
Aaron Hill 2018-01-30 21:44:35 -05:00
parent def3269a71
commit bc8e11b975
No known key found for this signature in database
GPG Key ID: B4087E510E98B164
2 changed files with 21 additions and 2 deletions

View File

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

View File

@ -0,0 +1,20 @@
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(nll)]
static mut x: &'static u32 = &0;
fn foo() {
unsafe { x = &1; }
}
fn main() { }