Fix misleading return type diagnostic for input type mismatch - #163466
BartSimpson001 wants to merge 1 commit into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project has assigned @oli-obk (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks. Please see the contribution instructions and our LLM policy for more information. Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
1be4b9e to
4dd0f1d
Compare
This comment has been minimized.
This comment has been minimized.
4dd0f1d to
1bda7b4
Compare
This comment has been minimized.
This comment has been minimized.
|
Please avoid using a testing section in the future. It's implicit in the diff. Only include it if you did sth out of the normal usage. Also the section header for summary is redundant, the main PR comment should start with it |
|
@rustbot reroll to find an LLM reviewer (not because it was generated, but because I don't have the energy to figure out if new contributors are biting off things too large for them because the LLM assistance made it somewhat possible to produce sth that passes tests) |
|
@oli-obk Just a small clarification: I’ve previously contributed to rust-ice and the Rust standard library, so I’m not completely new to Rust contributions. |
1bda7b4 to
f8033d7
Compare
Summary
Fixes #163443.
Avoid emitting the misleading "the return type of this call is ..." help when
an argument type mismatch does not actually affect type inference.
Previously, the diagnostic was emitted whenever the mismatched argument's type
was a generic parameter that also appeared in the function's output type. This
is misleading when the parameter is already constrained by another input, e.g.
in
MaybeUninit<u32>::write(&mut self, val: T) -> &mut T, whereTis fixedby
self, so the return type does not depend on the argument at all.This PR adds a condition so the help is only emitted when no other input
parameter of the signature mentions the same type. In that case the argument
really is the only thing that could influence the return type.
While here, the signature index (
sig_idx) is now computed once (accounting forthe
selfreceiver on methods) and reused for the lookup.Testing
(
tests/ui/mismatched_types/return-type-note-constrained-generic-issue-163443.rsand its.stderr)../x test tests/ui/mismatched_types/return-type-note-constrained-generic-issue-163443.rsLLM disclosure
I used an LLM during the development of this change to help analyze the issue
and understand the relevant rustc code and diagnostic behavior. The
implementation and changes were written by me. I ran the test myself and
generated the
.stderroutput with--bless, then reviewed it manually toconfirm it matches the desired output from the issue.