gccrs: Add lint for unused Drop bound on trait objects
GCC's Rust compiler warns about redundant Drop bounds on trait objects.
GCC’s Rust compiler now issues a warning when a trait object is declared with a Drop bound. Since trait objects themselves are not dropped and values behind them are dropped automatically, the Drop bound on a trait object has no effect. This new lint helps developers by identifying and flagging these redundant, no-op bounds.
In Details
The gccrs type checker has been updated to enforce a new lint rule: warning on trait objects that carry a Drop bound. This is because the Drop trait in Rust is fundamentally about the *value* implementing the trait being dropped. When a value is accessed through a trait object (a dynamic dispatch mechanism), the value itself is not directly managed by the trait object's lifetime in a way that would necessitate a Drop bound on the object. The compiler now flags this as an unused bound, improving code clarity and preventing potential confusion.
- lint
- A static code analysis tool that flags programming errors, bugs, suspicious constructs, and stylistic errors. In this context, it's a compiler warning.
- trait object
- A dynamically dispatched trait. It allows for different types that implement the same trait to be used interchangeably at runtime, typically behind a pointer or reference.
- Drop bound
- A trait bound on a type parameter or object indicating that the type must implement the
Droptrait. This ensures that the type's destructor logic will be executed. - dynamic dispatch
- A mechanism where the specific function or method to be called is determined at runtime, rather than at compile time. Trait objects use dynamic dispatch.