Skip to content

Conversation

@ada4a
Copy link
Contributor

@ada4a ada4a commented Aug 11, 2025

fixes #15381

changelog: [unnecessary_operation]: reduce applicability on exprs with uncertain types

@rustbot
Copy link
Collaborator

rustbot commented Aug 11, 2025

r? @y21

rustbot has assigned @y21.
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 Aug 11, 2025
@ada4a ada4a force-pushed the unnecessary-operation-uncertain-exprs branch from 5477205 to dff9f73 Compare August 11, 2025 22:07
&& expr.span.ctxt() == ctxt
&& let Some(reduced) = reduce_expression(cx, expr)
&& let Some(reduced) = reduce_expression(cx, expr, &mut applicability)
&& reduced.iter().all(|e| e.span.ctxt() == ctxt)
Copy link
Contributor Author

@ada4a ada4a Aug 11, 2025

Choose a reason for hiding this comment

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

Kind of off-topic: I was forced to use the more verbose Vec::new() syntax in all the tests because, when I used vec![], this check would prevent the lint from firing. That doesn't sound quite right to me?

@ada4a ada4a changed the title unnecessary_operation: don't lint on composite types with fields of uncertain types unnecessary_operation: don't suggest autofixes on composite types with fields of uncertain types Aug 12, 2025
&& let Some(end) = range.end =>
{
if [start, end].into_iter().any(|e| expr_type_is_certain(cx, e)) {
Some([start, end].into_iter().collect())
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
Some([start, end].into_iter().collect())
Some(vec![start, end])

Copy link
Member

Choose a reason for hiding this comment

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

But also, two more high level questions here:

  1. Should this also recurse into reduce_expression() with the start and end expressions of the range, to reduce it even further? I see this also isn't consistently done for some other kinds of expressions, like for array literals and struct expressions, so I'd also be fine with leaving it, but I'm not sure why it's done this way.

  2. Why do we return None/not reduce ranges at all if their type isn't certain, instead of only reducing the applicability like we do for structs in general? It still seems worth linting range expression statements that exist solely to make the inner expressions type-check.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. I think reducing too much in one go can end up creating some pretty confusing suggestions.. Although maybe they could make sense for the target audience of this lint (who I'm not really sure who is, except for people that have made a typo in a quick reproducer -- in which case the complete reduction might be actively counter-productive for understanding what the lint wants from them)
  2. I could totally make that change, yes. I guess it was just me too closely copying the structure of the regular Struct arm -- there, the suggestion is deleted when the type has an explicit Drop impl

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've implemented 2. for now

@ada4a ada4a force-pushed the unnecessary-operation-uncertain-exprs branch 2 times, most recently from 5198c64 to e783aea Compare August 22, 2025 13:51
@ada4a ada4a force-pushed the unnecessary-operation-uncertain-exprs branch from e783aea to aaa0940 Compare September 7, 2025 11:33
@rustbot

This comment has been minimized.

@ada4a ada4a force-pushed the unnecessary-operation-uncertain-exprs branch 2 times, most recently from 91c4c17 to d7dbefd Compare September 7, 2025 11:38
@ada4a
Copy link
Contributor Author

ada4a commented Sep 7, 2025

@y21 friendly ping

@rustbot

This comment has been minimized.

@ada4a ada4a force-pushed the unnecessary-operation-uncertain-exprs branch from d7dbefd to 9e1cd08 Compare October 11, 2025 08:15
@rustbot

This comment has been minimized.

@rustbot

This comment has been minimized.

@ada4a ada4a force-pushed the unnecessary-operation-uncertain-exprs branch from 9e1cd08 to 6555bfb Compare October 31, 2025 20:19
@rustbot
Copy link
Collaborator

rustbot commented Oct 31, 2025

This PR was rebased onto a different master commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

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-operation type can no longer be inferred

3 participants