Add display of lifetime of Ref in fn fmt() for TypeError#107475
Add display of lifetime of Ref in fn fmt() for TypeError#107475yanchen4791 wants to merge 1 commit intorust-lang:masterfrom
Conversation
|
(rustbot has picked a reviewer for you, use r? to override) |
|
r? nagisa |
|
Sorry for the lack of earlier feedback on the issue. The bug that I was reporting here was specifically the mismatch between: and the Rather than between these: As thus, I don’t believe this PR to be a fix for the referenced issue. I’m not particularly familiar with the code, since I haven’t had an opportunity to look at this, but I’m surprised that I also don’t think this PR is the right thing to do in general. Adding lifetimes to all notes that are likely pointing out larger structural differences (like reference vs enum) won’t make the diagnostic much clearer – in fact it will likely contribute to clutter. Adding lifetimes probably only makes sense if the lifetime mismatch is between two reference types of otherwise equivalent structure. cc @estebank |
There isn't, and ReStatic is chosen because it is the closest "safe" lifetime to use, but I'm in favor of introducing ReError. Edit: another case where ReError would have helped #69314 Edit 2: #107652 |
|
☔ The latest upstream changes (presumably #106399) made this pull request unmergeable. Please resolve the merge conflicts. |
|
Given that there's a broader agreement that this is not an approach that will make the situation better, and given the introduction of Thanks for the contribution @yanchen4791, and sorry for not making myself clearer in the issue description! |
Fix for #106517.
Problem:
When explaining the source of a type error, the lifetime portion of references is sometimes omitted in order to shorten the message. This can lead to confusion as the message can disagree with other spans which use the long form with the lifetime portion. For example, for the same type error, one span may print
expected '&str', found enum 'option'while another span may printexpected '&'static str' because of return typeandnote: expected reference '&'static str' found enum 'option<&str>'.Solution:
To add the lifetime portion of the references when generating the message. This will ensure consistency between the messages and avoid confusion, especially when the message is already short and the omitted information does not have to be removed.