Closed
Description
trait XLen {
fn xlen(&mut self) -> usize;
}
impl<'a> XLen for &'a [u8] {
fn xlen(&mut self) -> usize {
self.len()
}
}
fn main() {
const A: &'static [u8] = b"x";
println!("{} {}",A.len(),A.xlen());
}
This code compiles, but yields:
1 2097865012304223517
The second number may vary.
This used to lead to segfaults (in 1.5.0 and earlier) in code such as:
use std::io::Read;
fn main() {
const A: &'static [u8] = b"x";
let mut a=[0u8;32];
A.read(&mut a);
}
This doesn't segfault in 1.6.0 anymore, but that is due to an unrelated change.