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

unnecessary_to_owned: don't call iter() on a temporary object #14243

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

lapla-cogito
Copy link
Contributor

fix #14242

changelog: [unnecessary_to_owned]: don't call iter on a temporary object

@rustbot
Copy link
Collaborator

rustbot commented Feb 17, 2025

r? @Centri3

rustbot has assigned @Centri3.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Feb 17, 2025
@@ -2331,6 +2331,16 @@ pub fn is_expr_final_block_expr(tcx: TyCtxt<'_>, expr: &Expr<'_>) -> bool {
matches!(tcx.parent_hir_node(expr.hir_id), Node::Block(..))
}

/// Checks if the expression is a temporary value.
pub fn is_expr_temporary_value(cx: &LateContext<'_>, expr: &Expr<'_>) -> bool {
expr.is_place_expr(|base| {
Copy link
Member

Choose a reason for hiding this comment

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

I think noting that this is the exact same code rustc uses would be helpful for people viewing this later. My main idea is that this looks a bit like a (maybe incorrect) heuristic at first, vs just copying the code, and this change can clear up that hypothetical confusion.

After that, I'll merge this quickly

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.

unnecessary_to_owned in conjunction with reference counted slices and iterators
4 participants