Skip to content

Conversation

profetia
Copy link
Contributor

@profetia profetia commented Sep 30, 2025

Closes #15781

changelog: [map_entry] fix wrong suggestions for insert with cfg-ed out code

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Sep 30, 2025
@rustbot
Copy link
Collaborator

rustbot commented Sep 30, 2025

r? @blyxyas

rustbot has assigned @blyxyas.
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

} else if let Some(insertion) = then_search.as_single_insertion() {
} else if let Some(insertion) = then_search.as_single_insertion()
&& let span_in_between = then_expr.span.shrink_to_lo().between(insertion.call.span)
&& let span_in_between = span_in_between.with_lo(span_in_between.lo() + BytePos::from_usize(1))
Copy link
Contributor

Choose a reason for hiding this comment

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

  • BytePos::from_usize(1) could be replaced with BytePos(1). In fact, this whole line could be simplified using Span::split_at:
Suggested change
&& let span_in_between = span_in_between.with_lo(span_in_between.lo() + BytePos::from_usize(1))
// remove the opening brace
&& let span_in_between = span_in_between.split_at(1).1
  • I think the same check would be needed for the code after the insert?

Generally, it could be better to do all these checks somewhere inside InsertSearcher? Though I'm not very familiar with visitors, so I'm not sure whether that's actually feasible.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think the same check would be needed for the code after the insert?

Uh, I think it's a bit more complicated than that -- if there is cfgd-out code after the insert, then this case isn't even allow_insert_closure anymore. I think this is another argument for doing this check already in the visitor

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_entry: the insert suggestion doesn't take into account #[cfg]-d-out code and comments
4 participants