Add display of lifetime of Ref in fn fmt() for TypeError #107475
Closed
+74
−74
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 type
andnote: 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.