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

Ensure callee_ids are body owners #120000

Merged
merged 2 commits into from
Jan 20, 2024
Merged

Ensure callee_ids are body owners #120000

merged 2 commits into from
Jan 20, 2024

Conversation

smoelius
Copy link
Contributor

This PR makes the callee_id argument of Clippy's implements_trait_with_env optional, and when it is passed, ensures it is a body owner.

#118661 added the callee_id parameter to alleviate an ICE. Specifically, the callee_id is used to determine an "effect arg" in certain situations.

Frankly, I do not completely understand what an "effect arg" is. But the code that determines it seems to require that callee_id is a body owner:

In the current head, some def ids passed as callee_ids are not body owners. This PR fixes that.

cc @rust-lang/clippy

r? @fee1-dead

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 15, 2024
@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2024

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

@blyxyas
Copy link
Member

blyxyas commented Jan 15, 2024

Could this be opened as a PR directly to Clippy?

@smoelius
Copy link
Contributor Author

Could this be opened as a PR directly to Clippy?

I'm not sure, TBH.

#118661 was largely unrelated to Clippy. But the way that Clippy called certain APIs ICEd following that PR's changes.

I implemented the follow-up changes here to:

  1. Ensure I didn't reintroduce ICEs.
  2. Get more eyes on my changes, especially those that understand "effect arg"s.

@@ -214,36 +214,21 @@ pub fn implements_trait<'tcx>(
trait_id: DefId,
args: &[GenericArg<'tcx>],
) -> bool {
let callee_id = cx
.enclosing_body
.map(|body| cx.tcx.hir().body_owner(body).owner.to_def_id());
Copy link
Contributor

Choose a reason for hiding this comment

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

Using body_owner.owner is almost never the right thing to do. Would using body_owner_def_id solve the issue directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Please forgive me but is that question directed towards me? Please note that the code you've cited is deleted by this PR.

Copy link
Member

@fee1-dead fee1-dead left a comment

Choose a reason for hiding this comment

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

mostly LGTM, suggested some comment changes to clarify

src/tools/clippy/clippy_utils/src/ty.rs Outdated Show resolved Hide resolved
src/tools/clippy/clippy_utils/src/ty.rs Outdated Show resolved Hide resolved
Co-authored-by: fee1-dead <ent3rm4n@gmail.com>
@smoelius
Copy link
Contributor Author

mostly LGTM, suggested some comment changes to clarify

The additional detail is much appreciated!

@fee1-dead
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Jan 20, 2024

📌 Commit 96b8eb7 has been approved by fee1-dead

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jan 20, 2024
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 20, 2024
Ensure `callee_id`s are body owners

This PR makes the `callee_id` argument of Clippy's `implements_trait_with_env` optional, and when it is passed, ensures it is a body owner.

rust-lang#118661 added the `callee_id` parameter to alleviate an ICE. Specifically, the `callee_id` is used to determine an "effect arg" in certain situations.

Frankly, I [do not completely understand](rust-lang#118661 (comment)) what an "effect arg" is. But the code that determines it seems to require that `callee_id` is a body owner:
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/src/tools/clippy/clippy_utils/src/ty.rs#L286-L288
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/ty/util.rs#L834
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/hir/map/mod.rs#L372

In the current head, some def ids passed as `callee_id`s are not body owners. This PR fixes that.

cc `@rust-lang/clippy`

r? `@fee1-dead`
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2024
…llaumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#118257 (Make traits / trait methods detected by the dead code lint)
 - rust-lang#119997 (Fix impl stripped in rustdoc HTML whereas it should not be in case the impl is implemented on a type alias)
 - rust-lang#120000 (Ensure `callee_id`s are body owners)
 - rust-lang#120015 (coverage: Format all coverage tests with `rustfmt`)
 - rust-lang#120063 (Remove special handling of `box` expressions from parser)
 - rust-lang#120138 (Increase vscode settings.json `git.detectSubmodulesLimit`)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2024
…llaumeGomez

Rollup of 6 pull requests

Successful merges:

 - rust-lang#119997 (Fix impl stripped in rustdoc HTML whereas it should not be in case the impl is implemented on a type alias)
 - rust-lang#120000 (Ensure `callee_id`s are body owners)
 - rust-lang#120063 (Remove special handling of `box` expressions from parser)
 - rust-lang#120116 (Remove alignment-changing in-place collect)
 - rust-lang#120138 (Increase vscode settings.json `git.detectSubmodulesLimit`)
 - rust-lang#120169 (Spelling fix)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 71cef76 into rust-lang:master Jan 20, 2024
11 checks passed
@rustbot rustbot added this to the 1.77.0 milestone Jan 20, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Jan 20, 2024
Rollup merge of rust-lang#120000 - smoelius:fix-clippy, r=fee1-dead

Ensure `callee_id`s are body owners

This PR makes the `callee_id` argument of Clippy's `implements_trait_with_env` optional, and when it is passed, ensures it is a body owner.

rust-lang#118661 added the `callee_id` parameter to alleviate an ICE. Specifically, the `callee_id` is used to determine an "effect arg" in certain situations.

Frankly, I [do not completely understand](rust-lang#118661 (comment)) what an "effect arg" is. But the code that determines it seems to require that `callee_id` is a body owner:
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/src/tools/clippy/clippy_utils/src/ty.rs#L286-L288
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/ty/util.rs#L834
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/hir/map/mod.rs#L372

In the current head, some def ids passed as `callee_id`s are not body owners. This PR fixes that.

cc ``@rust-lang/clippy``

r? ``@fee1-dead``
@smoelius smoelius deleted the fix-clippy branch January 20, 2024 22:26
flip1995 pushed a commit to flip1995/rust that referenced this pull request Jan 25, 2024
Ensure `callee_id`s are body owners

This PR makes the `callee_id` argument of Clippy's `implements_trait_with_env` optional, and when it is passed, ensures it is a body owner.

rust-lang#118661 added the `callee_id` parameter to alleviate an ICE. Specifically, the `callee_id` is used to determine an "effect arg" in certain situations.

Frankly, I [do not completely understand](rust-lang#118661 (comment)) what an "effect arg" is. But the code that determines it seems to require that `callee_id` is a body owner:
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/src/tools/clippy/clippy_utils/src/ty.rs#L286-L288
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/ty/util.rs#L834
- https://github.com/rust-lang/rust/blob/1ead4761e9e2f056385768614c23ffa7acb6a19e/compiler/rustc_middle/src/hir/map/mod.rs#L372

In the current head, some def ids passed as `callee_id`s are not body owners. This PR fixes that.

cc ``@rust-lang/clippy``

r? ``@fee1-dead``
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants