-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Conversation
rustbot has assigned @petrochenkov. Use r? to explicitly pick a reviewer |
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.
r? @estebank
Thank you for taking this on!
I have a bunch of nitpicks that I'd like to address. In particular, shortening the type with no way to see the full type anywhere (which we stored to disk) can cause issues for people. Most of the time people don't care about the full type, but when they do, they really do. Also if we can try and pass the file being written to so that we only create one file per error instead of one per shortened type, that will be less disruptive, both on the user's disk as well as in the terminal output (because we'd only have a single note: full type written to...
to display, instead of multiple).
@petrochenkov, I know you have a bunch of things on your plate, taking it on to ease your load.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can remove the macro annotation if we're using short_ty_string
already:
let expr_ty = | |
with_forced_trimmed_paths!(self.tcx.short_ty_string(expr_ty, &mut None)); | |
let expr_ty = self.tcx.short_ty_string(expr_ty, &mut None); |
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.
(The other comment about &mut None
applies here too.)
@@ -824,7 +825,11 @@ impl<'tcx> OnUnimplementedFormatString { | |||
.filter_map(|param| { | |||
let value = match param.kind { | |||
GenericParamDefKind::Type { .. } | GenericParamDefKind::Const { .. } => { | |||
trait_ref.args[param.index as usize].to_string() | |||
if let Some(ty) = trait_ref.args[param.index as usize].as_type() { | |||
tcx.short_ty_string(ty, &mut None) |
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 extra file: &mut None
parameter to pass in here and modify OnUnimplementedNote
to carry file
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 single file
for the entire error, and pass that around everywhere that we use short_ty_string
for E0277, particularly note_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 of note_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.
Thanks for reviewing!
I will try to address them one-by-one.
I strongly agree with this, because I have ran into issues with big types too.
Yeah, I need to fix that. I noticed multiple loooong-type files being created for the same type |
I've unified (I think) the long type output file in |
@@ -111,6 +112,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { | |||
trait_ref: ty::PolyTraitRef<'tcx>, | |||
obligation: &PredicateObligation<'tcx>, | |||
) -> OnUnimplementedNote { | |||
let mut long_ty_file = None; |
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.
Where is the path of this file being printed?
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.
So this is a bit awkward, I tried to make sure I don't miss any silent type name being written to file, but now there seems to be a duplicate written to file note lol
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.
That... should be fine for now. We need to bubble the printing of the file (and passing the file down) more than we do now, but it being duplicated is better than out right losing it.
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.
That... should be fine for now. We need to bubble the printing of the file (and passing the file down) more than we do now, but it being duplicated is better than out right losing it.
Yeah, there's let mut file = None
a bit all over the place right now lol
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.
Other than one (seemingly?) missing note, r=me
@bors r+ |
Display short types for unimplemented trait Shortens unimplemented trait diagnostics. Now shows: ``` 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`. ``` I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate `rustc_trait_selection`'s error reporting to use translatable diagnostics and then properly handle type name printing. Fixes rust-lang#121687.
…iaskrgr Rollup of 10 pull requests Successful merges: - rust-lang#109263 (fix typo in documentation for std::fs::Permissions) - rust-lang#120684 (Update E0716.md for clarity) - rust-lang#121739 (Display short types for unimplemented trait) - rust-lang#121749 (Don't lint on executable crates with `non_snake_case` names) - rust-lang#121758 (Move thread local implementation to `sys`) - rust-lang#121815 (Move `gather_comments`.) - rust-lang#121835 (Move `HandleStore` into `server.rs`.) - rust-lang#121847 (Remove hidden use of Global) - rust-lang#121861 (Use the guaranteed precision of a couple of float functions in docs) - rust-lang#121875 ( Account for unmet T: !Copy in E0277 message) r? `@ghost` `@rustbot` modify labels: rollup
Display short types for unimplemented trait Shortens unimplemented trait diagnostics. Now shows: ``` 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`. ``` I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate `rustc_trait_selection`'s error reporting to use translatable diagnostics and then properly handle type name printing. Fixes rust-lang#121687.
Rollup of 9 pull requests Successful merges: - rust-lang#109263 (fix typo in documentation for std::fs::Permissions) - rust-lang#117156 (Convert `Unix{Datagram,Stream}::{set_}passcred()` to per-OS traits) - rust-lang#120684 (Update E0716.md for clarity) - rust-lang#121739 (Display short types for unimplemented trait) - rust-lang#121815 (Move `gather_comments`.) - rust-lang#121835 (Move `HandleStore` into `server.rs`.) - rust-lang#121847 (Remove hidden use of Global) - rust-lang#121861 (Use the guaranteed precision of a couple of float functions in docs) - rust-lang#121875 ( Account for unmet T: !Copy in E0277 message) r? `@ghost` `@rustbot` modify labels: rollup
…iaskrgr Rollup of 9 pull requests Successful merges: - rust-lang#109263 (fix typo in documentation for std::fs::Permissions) - rust-lang#120684 (Update E0716.md for clarity) - rust-lang#121715 (match lowering: pre-simplify or-patterns too) - rust-lang#121739 (Display short types for unimplemented trait) - rust-lang#121815 (Move `gather_comments`.) - rust-lang#121835 (Move `HandleStore` into `server.rs`.) - rust-lang#121847 (Remove hidden use of Global) - rust-lang#121861 (Use the guaranteed precision of a couple of float functions in docs) - rust-lang#121875 ( Account for unmet T: !Copy in E0277 message) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#121739 - jieyouxu:loooong-typename, r=estebank Display short types for unimplemented trait Shortens unimplemented trait diagnostics. Now shows: ``` 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`. ``` I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate `rustc_trait_selection`'s error reporting to use translatable diagnostics and then properly handle type name printing. Fixes rust-lang#121687.
Shortens unimplemented trait diagnostics. Now shows:
I'm not 100% sure if this is desirable, or if we should just let the long types remain long. This is also kinda a short-term bandaid solution. The real long term solution is to properly migrate
rustc_trait_selection
's error reporting to use translatable diagnostics and then properly handle type name printing.Fixes #121687.