Skip to content

Move some utils to clippy_utils::ty #6907

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 15, 2021
Merged

Conversation

camsteffen
Copy link
Contributor

changelog: none

clippy_utils::* has become a giant junk drawer. This is one step to clean it up a bit. One motivation is that I believe the long import statements cause more merge conflicts.

@rust-highfive
Copy link

r? @flip1995

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Mar 14, 2021
@camsteffen
Copy link
Contributor Author

camsteffen commented Mar 14, 2021

If all is well here, next I'll create source_utils with snippet and company.

@bors
Copy link
Contributor

bors commented Mar 15, 2021

☔ The latest upstream changes (presumably #6831) made this pull request unmergeable. Please resolve the merge conflicts.

Copy link
Member

@flip1995 flip1995 left a comment

Choose a reason for hiding this comment

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

LGTM. Just the naming: flip1995::crate_name_repetition triggered: clippy_utils::ty_utils -> clippy_utils::ty.

Ultimately I would like to get rid of the re-export in clippy_lints/src/utils/mod.rs, so the split between use crate::utils::_ and use clippy_utils::ty::_ seems good to me.

(Great idea splitting up the utils, btw. I also thought about this before, but never got around to do it...)

@@ -175,8 +176,8 @@ fn is_some_or_ok_call<'a>(
let outer_ty = cx.typeck_results().expr_ty(expr);

// Check if outer and inner type are Option
let outer_is_some = utils::is_type_diagnostic_item(cx, outer_ty, sym::option_type);
let inner_is_some = utils::is_type_diagnostic_item(cx, inner_ty, sym::option_type);
let outer_is_some = is_type_diagnostic_item(cx, outer_ty, sym::option_type);
Copy link
Member

@flip1995 flip1995 Mar 15, 2021

Choose a reason for hiding this comment

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

I'd like an internal lint checking for uses of utils::something(), but I'm not sure if that's too nitpicky.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

sounds reasonable

@flip1995 flip1995 added S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status) and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties labels Mar 15, 2021
@camsteffen
Copy link
Contributor Author

Just the naming: flip1995::crate_name_repetition triggered: clippy_utils::ty_utils -> clippy_utils::ty.

Ha! I was on the fence about that but now that you say it, I agree. I will just have to put an alias on use rustc_middle::ty as rustc_ty; in clippy_utils/lib.rs. But that should be the only place that is necessary, as long as we are okay with never doing use clippy_utils::ty; (and it sounds like you are from your internal lint idea).

Ultimately I would like to get rid of the re-export in clippy_lints/src/utils/mod.rs, so the split between use crate::utils::_ and use clippy_utils::ty::_ seems good to me.

My thoughts exactly.

@flip1995
Copy link
Member

I will just have to put an alias on use rustc_middle::ty as rustc_ty; in clippy_utils/lib.rs.

Yeah, we shouldn't import clippy_utils::ty, but only the functions.

I'm unsure if we should just reexport everything from the ty module in clippy_utils and then just continue using clippy_utils::something in clippy_lints. But I feel like we should embrace the module structure. So I'm leaning towards not re-exporting it.

@camsteffen
Copy link
Contributor Author

But I feel like we should embrace the module structure.

I agree. It is just easier to wrap my head around all the utils when they are categorized. Also one step is to stop re-exporting clippy_utils::diagnostics::*.

@flip1995
Copy link
Member

Also one step is to stop re-exporting clippy_utils::diagnostics::*.

Yeah, but I would like an extra PR for that, since that will be another big change.

@camsteffen camsteffen changed the title Move some utils into clippy_utils::ty_utils Move some utils to clippy_utils::ty Mar 15, 2021

/// Peels off all references on the type. Returns the underlying type and the number of references
/// removed.
pub fn peel_mid_ty_refs(ty: Ty<'_>) -> (Ty<'_>, usize) {
Copy link
Member

Choose a reason for hiding this comment

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

I guess it is also named "mid_ty" here for the same reason? Normally ty::Ty is referred to as ty_ty vs hir_ty.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I think peel_ty_refs would have been fine here.

@flip1995
Copy link
Member

@bors r+

Thanks!

@bors
Copy link
Contributor

bors commented Mar 15, 2021

📌 Commit eb7f8d6 has been approved by flip1995

@bors
Copy link
Contributor

bors commented Mar 15, 2021

⌛ Testing commit eb7f8d6 with merge ee3a7fd...

bors added a commit that referenced this pull request Mar 15, 2021
Move some utils to `clippy_utils::ty`

changelog: none

`clippy_utils::*` has become a giant junk drawer. This is one step to clean it up a bit. One motivation is that I believe the long import statements cause more merge conflicts.
@camsteffen
Copy link
Contributor Author

@bors wake up!

@bors
Copy link
Contributor

bors commented Mar 15, 2021

💥 Test timed out

@bors
Copy link
Contributor

bors commented Mar 15, 2021

⌛ Testing commit eb7f8d6 with merge 9cd0f50...

@bors
Copy link
Contributor

bors commented Mar 15, 2021

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: flip1995
Pushing 9cd0f50 to master...

@bors bors merged commit 9cd0f50 into rust-lang:master Mar 15, 2021
@camsteffen camsteffen deleted the ty-utils branch March 15, 2021 22:39
bors added a commit that referenced this pull request Mar 16, 2021
Move some utils to `clippy_utils::source`

changelog: none

Continues #6907
bors added a commit that referenced this pull request Mar 16, 2021
Don't re-export `clippy_utils::diagnostics::*`

changelog: none

Continues #6907
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
S-waiting-on-author Status: This is awaiting some action from the author. (Use `@rustbot ready` to update this status)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants