-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
new lint: type_id_on_box
#10987
new lint: type_id_on_box
#10987
Conversation
r? @llogiq (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you, this already looks pretty good. I'd just like some more testing.
|
||
#![warn(clippy::type_id_on_box)] | ||
|
||
use std::any::{Any, TypeId}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like to see a test where the type is behind a type alias, just to be sure we are privy to possible interactions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a few more tests. Not sure if this is how you meant it though
use rustc_middle::ty::{self, ExistentialPredicate}; | ||
use rustc_span::{sym, Span}; | ||
|
||
fn is_dyn_trait(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fn is_dyn_trait(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { | |
fn is_dyn_any(cx: &LateContext<'_>, ty: Ty<'_>) -> bool { |
Thank you! @bors r+ |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Closes #7687.
A new lint that detects calling
.type_id()
onBox<dyn Any>
(and not on the underlyingdyn Any
), which can make up for some pretty confusing bugs!changelog: new lint: [
type_id_on_box
]