Skip to content
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

Merged
merged 5 commits into from
Jul 3, 2023
Merged

new lint: type_id_on_box #10987

merged 5 commits into from
Jul 3, 2023

Conversation

y21
Copy link
Member

@y21 y21 commented Jun 18, 2023

Closes #7687.

A new lint that detects calling .type_id() on Box<dyn Any> (and not on the underlying dyn Any), which can make up for some pretty confusing bugs!

changelog: new lint: [type_id_on_box]

@rustbot
Copy link
Collaborator

rustbot commented Jun 18, 2023

r? @llogiq

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jun 18, 2023
Copy link
Contributor

@llogiq llogiq left a 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};
Copy link
Contributor

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.

Copy link
Member Author

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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
fn is_dyn_trait(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {
fn is_dyn_any(cx: &LateContext<'_>, ty: Ty<'_>) -> bool {

@llogiq
Copy link
Contributor

llogiq commented Jul 3, 2023

Thank you!

@bors r+

@bors
Copy link
Collaborator

bors commented Jul 3, 2023

📌 Commit 1b6738b has been approved by llogiq

It is now in the queue for this repository.

@bors
Copy link
Collaborator

bors commented Jul 3, 2023

⌛ Testing commit 1b6738b with merge c46ddeb...

@bors
Copy link
Collaborator

bors commented Jul 3, 2023

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: llogiq
Pushing c46ddeb to master...

@bors bors merged commit c46ddeb into rust-lang:master Jul 3, 2023
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Lint: Box<dyn Any>::type_id()
5 participants