-
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
Allow customising ty::TraitRef's printing behavior. #59188
Comments
Blocked on #58140. Also, in order to do this thoroughly, Only after that is done and everything compiles again, can |
Hey @eddyb! I would love to pick this one up and got a bit of the way into exploring this, but wondering — what did you have in mind for where As in — is this method added to the existing |
@stepnivlk you probably meant @eddyb |
Then, in rust/src/librustc/ty/print/pretty.rs Lines 1530 to 1532 in 316a391
and also here: rust/src/librustc/ty/print/pretty.rs Line 1449 in 316a391
(since that is the behavior for printing with |
Thanks @eddyb — that's really helpful! I'll try to make a start on this and see how far I get, it's a really great way to explore my way around the compiler internals some more! 🤞 |
Add a wrapper newtype called `TraitRefPrintOnlyTraitPath` which overrides the printing behaviour of `ty::TraitRef` to be the simple format `Trait<U>`. Printing of `ty::TraitRef` for `Debug` and `Display` is now the more verbose `<T as Trait<U>>`. This fixes rust-lang#59188.
@nathankleyn would you mind me snatching this? |
@Areredify Feel free! Some partial work here if it helps: nathankleyn@f5ec9d8 However it was, when I was last working on it, giving me some confusing issues and I couldn't untangle it. |
Allow customising ty::TraitRef's printing behavior This pr allows to explicitly choose which representation of `TraitRef` (`<T as Trait<U>>` or `Trait<U>`) you want to print. `Debug` and `Display` representations of `TraitRef` now match. Closes rust-lang#59188.
Allow customising ty::TraitRef's printing behavior This pr allows to explicitly choose which representation of `TraitRef` (`<T as Trait<U>>` or `Trait<U>`) you want to print. `Debug` and `Display` representations of `TraitRef` now match. Closes #59188.
(Originally discussed in #58140 (comment))
Right now a
TraitRef
prints as<T as Trait<U>>
via "debug" ({:?}
) andTrait<U>
via "display" ({}
) - this is used all over rustc to indicate what printed form of the trait is desired.However, it would be overall cleaner for "display" and "debug" printing to match (or even for
fmt::Display
to not be implemented at all, perhaps?), and provide all the information that exists (i.e. including theSelf
type).We would then need a replacement for printing "just the trait path with its parameters", and I think we can have a method,
.print_only_trait_path()
, that returns a wrapper which has the different formatting behavior.The text was updated successfully, but these errors were encountered: