Skip to content

TypeMismatch quickfix position error: to_owned() - #22185

Merged
ChayimFriedman2 merged 2 commits into
rust-lang:masterfrom
WeiTheShinobi:fix_type_mismatch_str_ref_to_owned_block_tail_expr
Oct 12, 2026
Merged

ChayimFriedman2 merged 2 commits into
rust-lang:masterfrom
WeiTheShinobi:fix_type_mismatch_str_ref_to_owned_block_tail_expr

Conversation

@WeiTheShinobi

@WeiTheShinobi WeiTheShinobi commented Apr 26, 2026 •

Copy link
Copy Markdown
Contributor

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() {

@A4-Tacks A4-Tacks Apr 26, 2026 •

Copy link
Copy Markdown
Member

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;

@A4-Tacks A4-Tacks Apr 28, 2026 •

Copy link
Copy Markdown
Member

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

This comment has been minimized.

@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
let file_id = d.expr_or_pat.file_id;
let root = ctx.sema.db.parse_or_expand(file_id);
let mut expr = expr_ptr.to_node(&root);
while let ast::Expr::BlockExpr(block) = expr.clone() {

@A4-Tacks A4-Tacks May 16, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I still hope to change fn emit_type_mismatch() or its calling site

View changes since the review

@rustbot

This comment has been minimized.

@WeiTheShinobi
WeiTheShinobi force-pushed the fix_type_mismatch_str_ref_to_owned_block_tail_expr branch from 4c20a4d to 74d6613 Compare October 1, 2026 14:13
@rustbot

rustbot commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator

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.

};

#[test]
fn str_ref_to_owned_in_block() {

@A4-Tacks A4-Tacks Oct 1, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM
And I think add_reference_when_tail_expr_of_block should be retained

View changes since the review

@A4-Tacks
A4-Tacks enabled auto-merge October 2, 2026 13:48
@A4-Tacks
A4-Tacks added this pull request to the merge queue Oct 2, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Oct 2, 2026
@ChayimFriedman2
ChayimFriedman2 added this pull request to the merge queue Oct 12, 2026
Merged via the queue into rust-lang:master with commit 4f6cca7 Oct 12, 2026
20 checks passed
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

TypeMismatch quickfix position error

4 participants