rust-lang / rust-lang/rust-clippy
Should the `mut_from_ref` lint apply to unsafe functions?
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
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() {}
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the provided Rust snippet in the linked Playground and observe how the mut_from_ref lint treats the unsafe functions. Read the linked RefCell implementation for the analogous pattern, then decide whether unsafe functions should be diagnosed and capture the decision in an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100