Skip to content

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

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

estebank
Copy link
Contributor

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).

@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

r? @fee1-dead

rustbot has assigned @fee1-dead.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 16, 2025
@rustbot
Copy link
Collaborator

rustbot commented Jul 16, 2025

HIR ty lowering was modified

cc @fmease

Comment on lines 1 to 3
// 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
Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

estebank added 6 commits July 17, 2025 18:45
`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.
This test seems to have improper use of `TyCtxt::short_string`.
Comment on lines +578 to +602
// Don't show generic arguments when the method can't be found in any implementation (#81576).
let mut ty_str = None;
if let ty::Adt(_, generics) = ty.kind() {
if generics.len() > 0 {
let mut autoderef = self.autoderef(DUMMY_SP, ty).silence_errors();
let candidate_found = autoderef.any(|(ty, _)| {
if let ty::Adt(adt_def, _) = ty.kind() {
self.tcx.inherent_impls(adt_def.did()).into_iter().any(
|def_id| {
self.associated_value(*def_id, method_name).is_some()
},
)
} else {
false
}
});
let has_deref = autoderef.step_count() > 0;
if !candidate_found && !has_deref && unsatisfied_predicates.is_empty() {
let t = with_forced_trimmed_paths!(ty.to_string());
if let Some((path_string, _)) = t.split_once('<') {
ty_str = Some(path_string.to_string());
}
}
}
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is moved code from 656.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants