Skip to content

Incorrect Send impl for Iter in chapter 7.8 #316

@Icerath

Description

@Icerath

Iter<T> acts like a &T so it's Send impl should depend on T: Sync, not T: Send.

unsafe impl<'a, T: Send> Send for Iter<'a, T> {}

should be

unsafe impl<'a, T: Sync> Send for Iter<'a, T> {}

Here's some example code which shouldn't compile but does.

let mut list = LinkedList::new();
list.push_back(Cell::new(0));
let mut iter_a = list.iter();
let mut iter_b = list.iter();

std::thread::scope(move |scope| {
    scope.spawn(move || iter_a.next().unwrap().set(1));
    scope.spawn(move || iter_b.next().unwrap().set(2));
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions