Shorten types more when only interesting part is lifetimes#158992
Open
estebank wants to merge 2 commits into
Open
Shorten types more when only interesting part is lifetimes#158992estebank wants to merge 2 commits into
estebank wants to merge 2 commits into
Conversation
We have a mechanims (`Highlight`) to change the name of inferred lifetimes in types so that we can refer to them by a number. Modify it so that it also avoids printing sub-parts of the type that are irrelevant to the situation at hand. The new behavior will print any sub part that has *any* lifetime (as they might be informative) instead of *just* the lifetimes being replaced. This was found to produce the best effect empirically in the test suite, striking a nice balance between shortening labels and being informative.
```
error: lifetime may not live long enough
--> $DIR/wrong-closure-arg-suggestion-125325.rs:46:18
|
LL | take(|_| to_fn(|_| self.counter += 1));
| --- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of closure `aux::Map<{closure@...}>` contains a lifetime `'2`
| lifetime `'1` represents this closure's body
|
= note: closure implements `Fn`, so references to captured variables can't escape the closure
```
```
error: implementation of `FnOnce` is not general enough
--> $DIR/higher-ranked-auto-trait-15.rs:20:5
|
LL | require_send(future);
| ^^^^^^^^^^^^^^^^^^^^ implementation of `FnOnce` is not general enough
|
= note: closure with signature `fn(&'0 ...) -> std::slice::Iter<'_, i32>` must implement `FnOnce<(&'1 Vec<i32>,)>`, for any two lifetimes `'0` and `'1`...
= note: ...but it actually implements `FnOnce<(&Vec<i32>,)>`
```
Made this change after noticing that the first of the errors above had a corresponding `.stderr` file with lines longer than 150 columns.
Collaborator
|
r? @mejrs rustbot has assigned @mejrs. Use Why was this reviewer chosen?The reviewer was selected based on:
|
estebank
commented
Jul 9, 2026
Comment on lines
+10
to
+11
| = note: expected signature `fn(ValueRef<'1>) -> Result<(&'2 str, &'1 &'2 str), ...>` | ||
| found signature `fn(ValueRef<'1>) -> Result<(&'1 str, &'1 &'1 str), ...>` |
Contributor
Author
There was a problem hiding this comment.
This is not using the "highlighted expected/found" we use for E0308... It'll likely require extending that logic to also learn to replace lifetime names in the same way that Highlight does.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
We have a mechanims (
Highlight) to change the name of inferred lifetimes in types so that we can refer to them by a number. Modify it so that it also avoids printing sub-parts of the type that are irrelevant to the situation at hand. The new behavior will print any sub part that has any lifetime (as they might be informative) instead of just the lifetimes being replaced. This was found to produce the best effect empirically in the test suite, striking a nice balance between shortening labels and being informative.Made this change after noticing that the first of the errors above had a corresponding
.stderrfile with lines longer than 150 columns by usingrg ".. \| .{150}" -g *.stderr.