Skip to content

Exception Safety section: Hole::get probably doesn't have to be unsafe #426

@frozenspider

Description

@frozenspider

https://doc.rust-lang.org/nomicon/exception-safety.html

struct Hole<'a, T: 'a> {
    data: &'a mut [T],
    /// `elt` is always `Some` from new until drop.
    elt: Option<T>,
    pos: usize,
}

impl<'a, T> Hole<'a, T> {
    // ...

    unsafe fn get(&self, index: usize) -> &T { &self.data[index] }

    // ...
}

Why is get here marked as unsafe? It doesn't seem to be performing anything particularly unsafe, any more so than regular safe code might do. Rust compiler also doesn't require it to be unsafe.

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