-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Closed
Milestone
Description
#![feature( if_let )]
use std::io::BufReader;
fn main() {
let text = b"the
quick
brown
fox
jumps
over";
let mut reader = BufReader::new(text);
let (tx, rx) = channel();
spawn(proc() {
for line in reader.lines() {
let line = line.unwrap();
let line = line.trim_chars(|c: char| c.is_whitespace());
let list = vec![ line ];
if let [ word ] = &*list {
tx.send(word);
}
}
});
for word in rx.iter() {
println!("{}", word);
}
}One would expect the output to be
the
quick
brown
fox
jumps
over
But the actual output is:
the
overs
overs
ove
overs
over
It looks like the memory location at word is overwritten.
The program will behave correctly if word is deep copied before being sent, i.e. changing tx.send(word) to tx.send(word.to_string())
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Type
Fields
Give feedbackNo fields configured for issues without a type.