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

Don't emit machine applicable map_flatten lint if there are code comments #13940

Merged

Conversation

GuillaumeGomez
Copy link
Member

@GuillaumeGomez GuillaumeGomez commented Jan 4, 2025

Fixes #8528.

Similar to #13911, if there are code comments, we don't want to remove them automatically.

changelog: Don't emit machine applicable map_flatten lint if there are code comments

r? @xFrednet

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Jan 4, 2025
@GuillaumeGomez GuillaumeGomez force-pushed the fix-map_flatten-suggestion branch from 65cf751 to fbc1f00 Compare January 4, 2025 12:24
@GuillaumeGomez
Copy link
Member Author

Fixed fmt error.

@@ -17,10 +17,15 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, recv: &Expr<'_>, map_
let mut applicability = Applicability::MachineApplicable;

let closure_snippet = snippet_with_applicability(cx, map_arg.span, "..", &mut applicability);
let span = expr.span.with_lo(map_span.lo());
// If the methods are separated with comments, we don't apply suggestion automatically.
if applicability != Applicability::Unspecified && span_contains_comment(cx.tcx.sess.source_map(), span) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it really useful to check for the very unlikely Unspecified case here? Sure, it speeds things up a bit in case it matches, but what is the chance?

Copy link
Member

@Centri3 Centri3 Jan 4, 2025

Choose a reason for hiding this comment

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

This is unreachable afaict (snippet_with_applicability never changes it to Unspecified)

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm starting to suspect it will not even change it to HasPlaceholders either (see #13941).

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't mind removing it if preferred.

@GuillaumeGomez GuillaumeGomez force-pushed the fix-map_flatten-suggestion branch from fbc1f00 to 78225cc Compare January 6, 2025 16:36
@GuillaumeGomez
Copy link
Member Author

Removed the applicability != Applicability::Unspecified check.

@xFrednet xFrednet added this pull request to the merge queue Jan 7, 2025
Merged via the queue into rust-lang:master with commit d0d5b8a Jan 7, 2025
9 checks passed
@GuillaumeGomez GuillaumeGomez deleted the fix-map_flatten-suggestion branch January 7, 2025 14:31
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.

map_flatten removes comments between iterator methods with --fix 😞
5 participants