Skip to content

TypeMismatch quickfix position error: to_owned()#22185

Open
WeiTheShinobi wants to merge 3 commits intorust-lang:masterfrom
WeiTheShinobi:fix_type_mismatch_str_ref_to_owned_block_tail_expr
Open

TypeMismatch quickfix position error: to_owned()#22185
WeiTheShinobi wants to merge 3 commits intorust-lang:masterfrom
WeiTheShinobi:fix_type_mismatch_str_ref_to_owned_block_tail_expr

Conversation

@WeiTheShinobi
Copy link
Copy Markdown
Contributor

@WeiTheShinobi WeiTheShinobi commented Apr 26, 2026

Fixed #22152

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2026
@rustbot

This comment has been minimized.

@WeiTheShinobi WeiTheShinobi marked this pull request as draft April 26, 2026 14:49
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 26, 2026
@WeiTheShinobi WeiTheShinobi changed the title Fix issue #22152: TypeMismatch quick fix error when insert to_owned() to tail expr of block. TypeMismatch quickfix position error: to_owned() Apr 26, 2026
@WeiTheShinobi WeiTheShinobi force-pushed the fix_type_mismatch_str_ref_to_owned_block_tail_expr branch from 65b4fc7 to 94f431c Compare April 26, 2026 14:51

let edit = TextEdit::insert(range.end(), to_owned);
let mut edit_expr = expr.clone();
while let ast::Expr::BlockExpr(block) = edit_expr.clone() {
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks Apr 26, 2026

Choose a reason for hiding this comment

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

This is not a real fix
We should fix the emit of diagnostic because d: &hir::TypeMismatch<'_> points to { "" } instead of ""

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I moved the logic to where TypeMismatch is created and both cases have been solved,
Or should I fix this further upstream?

@WeiTheShinobi WeiTheShinobi marked this pull request as ready for review April 28, 2026 03:13
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 28, 2026
Comment thread crates/hir/src/lib.rs Outdated
ExprOrPatId::ExprId(expr) => source_map.expr_syntax(expr).map(Either::Left),
ExprOrPatId::ExprId(mut expr) => {
while let Expr::Block { tail: Some(tail), .. } = &body[expr] {
expr = *tail;
Copy link
Copy Markdown
Member

@A4-Tacks A4-Tacks Apr 28, 2026

Choose a reason for hiding this comment

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

@ChayimFriedman2 I don't know if it's appropriate this, do you think?

View changes since the review

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't think this is the place. If we have adjustments to do and we can't do them when emitting the type mismatch, we should do them in ide-diagnostics.

@rustbot

This comment has been minimized.

@WeiTheShinobi WeiTheShinobi force-pushed the fix_type_mismatch_str_ref_to_owned_block_tail_expr branch from 6514fc9 to 4c20a4d Compare May 3, 2026 11:41
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented May 3, 2026

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.

@WeiTheShinobi WeiTheShinobi marked this pull request as draft May 3, 2026 12:37
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 3, 2026
@WeiTheShinobi WeiTheShinobi force-pushed the fix_type_mismatch_str_ref_to_owned_block_tail_expr branch from 739a261 to 4c20a4d Compare May 3, 2026 13:54
@WeiTheShinobi WeiTheShinobi marked this pull request as ready for review May 3, 2026 14:20
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label May 3, 2026
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.

TypeMismatch quickfix position error

4 participants