-
Notifications
You must be signed in to change notification settings - Fork 13.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Display short types for unimplemented trait #121739
Merged
Merged
Changes from 1 commit
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -3507,7 +3507,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | |||||||
} | ||||||||
ObligationCauseCode::OpaqueReturnType(expr_info) => { | ||||||||
if let Some((expr_ty, expr_span)) = expr_info { | ||||||||
let expr_ty = with_forced_trimmed_paths!(self.ty_to_string(expr_ty)); | ||||||||
let expr_ty = | ||||||||
with_forced_trimmed_paths!(self.tcx.short_ty_string(expr_ty, &mut None)); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can remove the macro annotation if we're using
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (The other comment about |
||||||||
err.span_label( | ||||||||
expr_span, | ||||||||
with_forced_trimmed_paths!(format!( | ||||||||
|
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
//@ compile-flags: --diagnostic-width=60 -Z write-long-types-to-disk=yes | ||
//@ normalize-stderr-test: "long-type-\d+" -> "long-type-hash" | ||
|
||
pub fn foo() -> impl std::fmt::Display { | ||
//~^ ERROR doesn't implement `std::fmt::Display` | ||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some( | ||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some( | ||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some( | ||
Some(Some(Some(Some(Some(Some(Some(Some(Some(Some(Some( | ||
Some(Some(Some(Some(Some(Some(Some(Some(())))))))), | ||
))))))))))), | ||
))))))))))), | ||
))))))))))), | ||
))))))))))) | ||
} | ||
|
||
fn main() {} |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
error[E0277]: `Option<Option<Option<...>>>` doesn't implement `std::fmt::Display` | ||
--> $DIR/on_unimplemented_long_types.rs:4:17 | ||
| | ||
LL | pub fn foo() -> impl std::fmt::Display { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ `Option<Option<Option<...>>>` cannot be formatted with the default formatter | ||
LL | | ||
LL | / Some(Some(Some(Some(Some(Some(Some(Some(Some(S... | ||
LL | | Some(Some(Some(Some(Some(Some(Some(Some(So... | ||
LL | | Some(Some(Some(Some(Some(Some(Some(Som... | ||
LL | | Some(Some(Some(Some(Some(Some(Some... | ||
... | | ||
LL | | ))))))))))), | ||
LL | | ))))))))))) | ||
| |_______________- return type was inferred to be `Option<Option<Option<...>>>` here | ||
| | ||
= help: the trait `std::fmt::Display` is not implemented for `Option<Option<Option<...>>>` | ||
= note: in format strings you may be able to use `{:?}` (or {:#?} for pretty-print) instead | ||
|
||
error: aborting due to 1 previous error | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should modify
format
to take an extrafile: &mut None
parameter to pass in here and modifyOnUnimplementedNote
to carryfile
as well. You can see how we present that in other places, which makes it so that if the user is interested in looking at the full type for whatever reason, they can. Ideally we'd have a singlefile
for the entire error, and pass that around everywhere that we useshort_ty_string
for E0277, particularlynote_obligation_cause_code
, but that doesn't need to be addressed in this PR, but since you're adding another use there it might be a good idea to do so. Then we can remove all of the redundant "the full type name has been written to '{}'" notes and push them to the top-most call ofnote_obligation_cause_code
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not-within-the-scope-of-this-PR remark: the long type names when written to disk is... still incredibly long. I previously saw some issue proposing that the long types written to disk should be pretty printed (but now I cannot find it) and I think that might be good as an option (not necessarily default-behavior because it's probably easier to diff two long types when they are in single lines).
Some issue like #54923 but it's a different one specifically about when written to disk.