Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upBorrowck regression: allows segfault in 1.27.1 #52213
Comments
NilSet
changed the title
Borrowck regression: multiple mut borrows
Borrowck regression: allows segfault in safe rust on beta
Jul 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Here is an example of being able to segfault in safe rust on beta enum Inner {
Stack {
data: [u8;23]
},
Heap {
data: Box<[u8]>
}
}
struct SmallString {
len: usize,
inner: Inner
}
impl SmallString {
fn push_str(&mut self, item: &str) {
match (&mut self.inner, self.len + item.len()) {
(Inner::Heap { data }, x) => {
println!("{}", data.len());
if x > data.len() {
self.grow();
// data is now garbage pointer
}
println!("{:?}", data);
},
_ => ()
}
}
fn grow(&mut self){
// Invalidate borrowed Heap.data
self.inner = Inner::Stack { data: [1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1,0,1] };
}
}
fn main (){
let slice = "this is gonna go bad".to_owned().into_bytes().into_boxed_slice();
let mut ss = SmallString { len: slice.len(), inner: Inner::Heap { data: slice } };
ss.push_str(" right now");
} |
NilSet
changed the title
Borrowck regression: allows segfault in safe rust on beta
Borrowck regression: allows segfault in 1.27.1
Jul 10, 2018
This comment has been minimized.
This comment has been minimized.
|
Turns out this regression is now also in the new patch release on stable! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
cc @nikomatsakis #51686. |
This comment has been minimized.
This comment has been minimized.
|
@rust-lang/compiler the obligatory ping to all of you. |
This comment has been minimized.
This comment has been minimized.
|
Minified: fn transmute_lifetime<'a, 'b, T>(t: &'a (T,)) -> &'b T {
match (&t, ()) {
((t,), ()) => t,
}
}
fn main() {
let x = {
let y = Box::new((42,));
transmute_lifetime(&y)
};
println!("{}", x);
} |
This comment has been minimized.
This comment has been minimized.
|
Did anyone verify that this reproduces on 1.27.1? I am not sure |
This comment has been minimized.
This comment has been minimized.
|
And now I'm in the state of "how does this ever work", given that |
This comment has been minimized.
This comment has been minimized.
|
@arielb1: Your minified example compiles with 1.27.1, and so does the second example in this thread. |
pnkfelix
self-assigned this
Jul 10, 2018
This comment has been minimized.
This comment has been minimized.
|
I have a fix up, will push it soon. |
arielb1
referenced this issue
Jul 10, 2018
Merged
use the adjusted type for cat_pattern in tuple patterns #52232
bors
pushed a commit
that referenced
this issue
Jul 11, 2018
bors
pushed a commit
that referenced
this issue
Jul 11, 2018
bors
added a commit
that referenced
this issue
Jul 11, 2018
bors
closed this
in
#52232
Jul 11, 2018
kennytm
added this to Triaged
in 1.28 regressions
via automation
Jul 11, 2018
kennytm
moved this from Triaged
to Backport in progress
in 1.28 regressions
Jul 11, 2018
pietroalbini
added a commit
to pietroalbini/rust
that referenced
this issue
Jul 14, 2018
pietroalbini
added a commit
to pietroalbini/rust
that referenced
this issue
Jul 14, 2018
pietroalbini
moved this from Backport in progress
to Fixed
in 1.28 regressions
Jul 16, 2018
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this issue
Jul 18, 2018
Mark-Simulacrum
added a commit
to Mark-Simulacrum/rust
that referenced
this issue
Jul 18, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
NilSet commentedJul 10, 2018
The following sample correctly fails to build on stable channel, but erroneously passes on beta and nightly.
It's worth noting that with NLL turned on it also correctly fails to build.