Skip to content

Should the mut_from_ref lint apply to unsafe functions? #4281

Open
@MaikKlein

Description

@MaikKlein
pub struct MutUnsafeSlice<'s>(&'s mut [u32]);
struct Foo {}
impl Foo {
    pub unsafe fn foo(&self) -> &mut [u32] {
        panic!()
    }
    pub unsafe fn foo1(&self) -> MutUnsafeSlice {
        panic!()
    }
}
fn main() {}

playground

Should mut_from_ref apply to unsafe functions as well?

It is trivial to work around that error by wrapping the mutable reference in a new struct.

Here is the refcell implementation that does something very similar.

I personally don't have any strong opinions in either direction. I just needed to implement something similar to RefCell (runtime borrowing) and I ran into this lint.

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