-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Use tcx.short_string()
in more diagnostics
#144039
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
Conversation
r? @fee1-dead rustbot has assigned @fee1-dead. Use |
HIR ty lowering was modified cc @fmease |
// FIXME(estebank): diagnostics with long type paths that don't print out the full path anywhere | ||
// still prints the note explaining where the type was written to. | ||
//@ compile-flags: -Zwrite-long-types-to-disk=yes |
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 found these by changing the default -Zwrite-long-types-to-disk=no
in compiletest::runtest::TestCx::make_compile_args
to yes
, which highlighted some preexisting cases that I'll investigate.
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.
One left: tests/ui/methods/filter-relevant-fn-bounds.rs
. Also pre-existing.
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.
Figured out what's happening on the last case standing: it's a consequence of using on_unimplemented
. Given the way the machinery is set up, we have to create a map between the type parameter name of the annotated trait and the resolved type, which we need to shorten. Because this happens before we know which type parameters are even referenced in the annotation, we pessimize and write the types to disk when any of those params needs to be shortened, regardless of whether the corresponding message ever gets printed by the E0277. Changing this to use the full type, makes other diagnostics longer. The proper solution is to rearchitect on_unimplemented
to make a map from type param to the actual type, and the shorten during rendering, instead of using strings throughout. I feel it's ok to leave that one case in the test suite be for now.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs
Outdated
Show resolved
Hide resolved
let ty_str = tcx.short_string(ty, err.long_ty_path()); | ||
let msg = format!("required because it appears within the type `{ty_str}`"); | ||
let mut msg = || { | ||
let ty_str = tcx.short_string(ty, err.long_ty_path()); | ||
format!("required because it appears within the type `{ty_str}`") | ||
}; |
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.
This probably illustrates a problem we have with the current system: we don't prevent if a short string was created but was never printed. I think there could be a mechanism (a drop guard for a custom short_string
return newtype) in which we detect that. Could you open an issue?
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.
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.
These ui tests are now regressions because we should not "show generic arguments when the method can't be found in any implementations". If you're trying to prevent us from creating a short string when we don't use it, maybe we should pass a closure down instead of the ty_str_reported
.
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 that I originally made the message only mention the item name instead of the Ty<'_>
was precisely because we didn't have short_string
back then and we could end up with quite long output accidentally. I was concerned back then that there are cases where the method is available on a given type depending on bounds on its type parameters, so I felt comfortable relying exclusively on short_string
for keeping the output readable.
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.
#81576 says we shouldn't show generics at all if they are irrelevant. I agree. I think we should spend effort keeping that behavior here.
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.
Would it be ok to display the type's identity (Option<T>
instead of the current Option
and this PR's Option<ElaboratedType>
) or a freshened type (Option<_>
)? I'd really want to keep the structured error's field a Ty<'_>
instead of a String
, and using the identity allows for 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.
Last commit does this
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.
inconsistent output in aarch64
seems quite odd. Could you explain what the issue is?
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.
It was the error from #144039 (comment)
I suspect that that platform in particular prints a slightly different output for the closure type which puts it under the default terminal width threshold.
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 platform in particular prints a slightly different output for the closure type
That is really really surprising for me. Could you post an issue for this? This seems very worthy of investigation.
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.
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.
#81576 says we shouldn't show generics at all if they are irrelevant. I agree. I think we should spend effort keeping that behavior here.
This PR modifies |
Some changes occurred in need_type_info.rs cc @lcnr |
This comment has been minimized.
This comment has been minimized.
6397fa3
to
5963f7a
Compare
Removed the |
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=me after nit is applied and the commits are squashed
@@ -44,5 +44,5 @@ fn main() { | |||
// our resolution logic needs to be able to call methods such as foo() | |||
// on the outer type even if the inner type is ambiguous. | |||
let _c = (ptr as SmartPtr<_>).read(); | |||
//~^ ERROR no method named `read` found for struct `SmartPtr` | |||
//~^ ERROR no method named `read` found for struct `SmartPtr |
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.
//~^ ERROR no method named `read` found for struct `SmartPtr | |
//~^ ERROR no method named `read` found for struct `SmartPtr<T>` |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
`TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`. We add support for shortening the path of "trait path only". Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem). When we don't actually print out a shortened type we don't need the "use `--verbose`" note. On E0599 show type identity to avoid expanding the receiver's generic parameters. Unify wording on `long_ty_path` everywhere.
@bors r+ |
Use `tcx.short_string()` in more diagnostics `TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`. We add support for shortening the path of "trait path only". Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).
Use `tcx.short_string()` in more diagnostics `TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`. We add support for shortening the path of "trait path only". Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).
Rollup of 7 pull requests Successful merges: - #144039 (Use `tcx.short_string()` in more diagnostics) - #144192 (atomicrmw on pointers: move integer-pointer cast hacks into backend) - #144823 (coverage: Extract HIR-related helper code out of the main module) - #144987 (Enable f16 and f128 on targets that were fixed in LLVM21) - #145001 (regression test for intrinsics may not inline properly on pclmulqdq) - #145080 (Escape diff strings in MIR dataflow graphviz) - #145083 (Fix cross-compilation of Cargo) r? `@ghost` `@rustbot` modify labels: rollup
Do the modified tests still test the exact value of the long type name that's written to the separate file? I think they should. |
Rollup of 8 pull requests Successful merges: - #139451 (Add `target_env = "macabi"` and `target_env = "sim"`) - #144039 (Use `tcx.short_string()` in more diagnostics) - #144192 (atomicrmw on pointers: move integer-pointer cast hacks into backend) - #144545 (In rustc_pattern_analysis, put `true` witnesses before `false` witnesses) - #144579 (Implement declarative (`macro_rules!`) attribute macros (RFC 3697)) - #144649 (Account for bare tuples and `Pin` methods in field searching logic) - #144775 (more strongly dissuade use of `skip_binder`) - #144987 (Enable f16 and f128 on targets that were fixed in LLVM21) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of #144039 - estebank:short-paths, r=fee1-dead Use `tcx.short_string()` in more diagnostics `TyCtxt::short_string` ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to use `short_string`. We add support for shortening the path of "trait path only". Every manual use of `short_string` is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).
Rollup of 8 pull requests Successful merges: - rust-lang/rust#139451 (Add `target_env = "macabi"` and `target_env = "sim"`) - rust-lang/rust#144039 (Use `tcx.short_string()` in more diagnostics) - rust-lang/rust#144192 (atomicrmw on pointers: move integer-pointer cast hacks into backend) - rust-lang/rust#144545 (In rustc_pattern_analysis, put `true` witnesses before `false` witnesses) - rust-lang/rust#144579 (Implement declarative (`macro_rules!`) attribute macros (RFC 3697)) - rust-lang/rust#144649 (Account for bare tuples and `Pin` methods in field searching logic) - rust-lang/rust#144775 (more strongly dissuade use of `skip_binder`) - rust-lang/rust#144987 (Enable f16 and f128 on targets that were fixed in LLVM21) r? `@ghost` `@rustbot` modify labels: rollup
@joshtriplett We don't do that at the moment. We'd have to teach the test runner to look into them. Shouldn't be too hard. Another option is to make these tests have two revisions, one writing to disk and one using the default, that way we can see the full type in the stderr file. |
Rollup of 8 pull requests Successful merges: - rust-lang#139451 (Add `target_env = "macabi"` and `target_env = "sim"`) - rust-lang#144039 (Use `tcx.short_string()` in more diagnostics) - rust-lang#144192 (atomicrmw on pointers: move integer-pointer cast hacks into backend) - rust-lang#144545 (In rustc_pattern_analysis, put `true` witnesses before `false` witnesses) - rust-lang#144579 (Implement declarative (`macro_rules!`) attribute macros (RFC 3697)) - rust-lang#144649 (Account for bare tuples and `Pin` methods in field searching logic) - rust-lang#144775 (more strongly dissuade use of `skip_binder`) - rust-lang#144987 (Enable f16 and f128 on targets that were fixed in LLVM21) r? `@ghost` `@rustbot` modify labels: rollup
TyCtxt::short_string
ensures that user visible type paths aren't overwhelming on the terminal output, and properly saves the long name to disk as a side-channel. We already use these throughout the compiler and have been using them as needed when users find cases where the output is verbose. This is a proactive search of some cases to useshort_string
.We add support for shortening the path of "trait path only".
Every manual use of
short_string
is a bright marker that that error should be using structured diagnostics instead (as they have proper handling of long types without the maintainer having to think abou tthem).