Skip to content

Commit 3d114c7

Browse files
committed
Remove delay_span_bug() in check_aliasability
This path was considered to be unreachable. However, `&mut` could potentially live inside `static`. For example, `static TAB: [&mut [u8]; 0] = [];`.
1 parent 0f9c784 commit 3d114c7

File tree

3 files changed

+20
-12
lines changed

3 files changed

+20
-12
lines changed

src/librustc_borrowck/borrowck/mod.rs

+1-11
Original file line numberDiff line numberDiff line change
@@ -1113,22 +1113,12 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
11131113
};
11141114

11151115
match cause {
1116-
mc::AliasableStatic => {
1117-
// This happens when we have an `&mut` or assignment to a
1118-
// static. We should have already reported a mutability
1119-
// violation first, but may have continued compiling.
1120-
self.tcx.sess.delay_span_bug(
1121-
span,
1122-
&format!("aliasability violation for static `{}`", prefix)
1123-
);
1124-
return;
1125-
}
11261116
mc::AliasableStaticMut => {
11271117
// This path cannot occur. `static mut X` is not checked
11281118
// for aliasability violations.
11291119
span_bug!(span, "aliasability violation for static mut `{}`", prefix)
11301120
}
1131-
mc::AliasableBorrowed => {}
1121+
mc::AliasableStatic | mc::AliasableBorrowed => {}
11321122
};
11331123
let blame = cmt.immutability_blame();
11341124
let mut err = match blame {

src/test/compile-fail/issue-42344.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
static TAB: [&mut [u8]; 0] = [];
12+
13+
pub unsafe fn test() {
14+
TAB[0].iter_mut(); //~ ERROR cannot borrow data mutably in a `&` reference [E0389]
15+
}
16+
17+
pub fn main() {}

src/test/compile-fail/issue-46604.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ fn write<T: AsRef<[u8]>>(buffer: T) { }
1717

1818
fn main() {
1919
write(&buf);
20-
buf[0]=2; //[mir]~ ERROR E0594
20+
buf[0]=2; //[ast]~ ERROR E0389
21+
//[mir]~^ ERROR E0594
2122
}

0 commit comments

Comments
 (0)