rust-lang / rust-lang/rust-clippy
`Any` pitfalls
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Since any value can be converted to an Any trait object, you can run into subtle bugs where you put the wrong value behind the Any:
use std::any::Any;
struct Foo;
fn main() {
let x: Box<Foo> = Box::new(Foo);
let mut y: Box<Any> = x;
let z: &mut Any = &mut *y; // remove the `*` and the next line panics
let a: &mut Foo = z.downcast_mut().unwrap(); // panics if `z` contains `Box<Any>` instead of `Any`
}
We should be linting all coercions of references/boxes to Any to a reference to Any. Especially around double references and similar this seems like it can go south very fast
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
Start by reproducing the supplied Rust example and comparing the reference and box coercion cases described in the issue. Done means the lint identifies the risky conversions to Any, including double-reference cases, with its supported cases and expected diagnostics covered by tests.
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
- Mostly clear
- Newbie friendliness
- 35/100