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

Reduce false positives of tail-expr-drop-order from consumed values #129864

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dingxiangfei2009
Copy link
Contributor

@dingxiangfei2009 dingxiangfei2009 commented Sep 1, 2024

r? @jieyouxu

To reduce false positives, the lint does not fire if the locals are consumed/moved, or the values with significant drop are consumed/moved at the tail expression location.

I am also printing the type involved for easier diagnosis.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 1, 2024
@dingxiangfei2009 dingxiangfei2009 force-pushed the reduce-false-positives-from-consumed-droppers branch from c1fce35 to 491fb13 Compare September 1, 2024 18:28
@dingxiangfei2009 dingxiangfei2009 force-pushed the reduce-false-positives-from-consumed-droppers branch from 491fb13 to de2d256 Compare September 1, 2024 18:29
@dingxiangfei2009
Copy link
Contributor Author

I also found that std::io::Error is considered to have significant drop. How weird.

type Error = !;

fn typeck_results(&self) -> Self::TypeckResults<'_> {
self.0.typeck(self.1)
Copy link
Member

Choose a reason for hiding this comment

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

This is going to be extremely expensive for the query, for the record. I would probably make some helper that caches the typeck results after the first call, or better yet just load the typeck results yourself and pass them here.

Comment on lines +19 to +28
match place_with_id.place.base {
PlaceBase::Rvalue => {
self.nodes.insert(place_with_id.hir_id);
}
PlaceBase::Local(id) => {
self.nodes.insert(id);
}
PlaceBase::Upvar(upvar) => {
self.nodes.insert(upvar.var_path.hir_id);
}
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this count partial moves as full moves? Isn't that still not correct for drop ordering?

Copy link
Member

Choose a reason for hiding this comment

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

Also, doesn't this not respect different paths correctly? What about consuming operations that happen on only one branch of a conditional path? I don't know if this sort of analysis is supported with ExprUseVisitor, which has no "flow" state.

}
}

fn extract_tail_expr_consuming_nodes<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> &'tcx HirIdSet {
Copy link
Member

Choose a reason for hiding this comment

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

Make this into a hook, not a query; I don't believe it needs any sort of caching, since that has overhead. This should also explain very clearly what it does.

@compiler-errors compiler-errors self-assigned this Sep 2, 2024
@jieyouxu
Copy link
Member

jieyouxu commented Sep 2, 2024

I opened a zulip thread at https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/More.20precise.20lint.20impl.20for.20Edition.202024.20tail-expr-drop-order to discuss this lint, because as @compiler-errors mentioned I feel like this might almost need to be some kind of flow analysis.

@compiler-errors
Copy link
Member

@rustbot author

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Sep 10, 2024
@bors
Copy link
Contributor

bors commented Sep 14, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants