Skip to content

Hide ToString specializations behind a private trait - #89253

Closed
SkiFire13 wants to merge 1 commit into
rust-lang:masterfrom
SkiFire13:hide-tostring-spec
Closed

Hide ToString specializations behind a private trait#89253
SkiFire13 wants to merge 1 commit into
rust-lang:masterfrom
SkiFire13:hide-tostring-spec

Conversation

@SkiFire13

Copy link
Copy Markdown
Contributor

Normally we use private traits for specializing impls but ToString's were public and the original PR #32586 doesn't seem to have a reason for this. This PR moves those impls to a hidden perma-unstable SpecToString trait (I would have made it private if proc_macro didn't have to specialize it too) and delegates to it, leaving only the impl<T: fmt::Display + ?Sized> ToStringSpec for T as public.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @kennytm

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfiverust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 25, 2021
@rust-log-analyzer

This comment has been minimized.

@kennytm

Copy link
Copy Markdown
Member

but isn't proc_macro specializing ToString an example why the default fn should be kept public 🤔

@SkiFire13

Copy link
Copy Markdown
ContributorAuthor

proc_macro will still use the specialized version, just not publicly

@kennytm

Copy link
Copy Markdown
Member

actually #32586 (comment) questioned the rationale of making ToString publicly specializable, the response was

Very good question. We talked about this some in a recent libs meeting -- ultimately, we're going to want a conventions RFC here, I think. But it's hard to get there without some experimentation first.

what i interpret is that there's no preference in wanting either way. afaik no conventions RFC exists yet. has any experimentation been done?

IMO creating a private-but-actually-public SpecToString trait to hide away the specialization possibility does not provide much benefits over keeping ToString specializable, as long as #31844min_specialization is still unstable.

@SkiFire13

Copy link
Copy Markdown
ContributorAuthor

what i interpret is that there's no preference in wanting either way. afaik no conventions RFC exists yet

While not technically being an RFC, the std-dev-guide specifies that specialization should use private traits https://std-dev-guide.rust-lang.org/code-considerations/using-unstable-lang/specialization.html

IMO creating a private-but-actually-public SpecToString trait to hide away the specialization possibility does not provide much benefits over keeping ToString specializable, as long as #31844 min_specialization is still unstable.

I agree with that, however at least the change makes it consistent with how specialization is handled in the rest of the stdlib.

@the8472

Copy link
Copy Markdown
Member

IIRC the reason for hiding specializations had something to do with the specialized methods being nameable through fully qualified function calls, e.g. <SpecializedImpl as Trait>::specialized_function. The part that I don't recall is what the negative impact of that was. 😅

@apirainoapiraino added the T-libs Relevant to the library team, which will review and decide on the PR/issue. label Oct 14, 2021
@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 31, 2021
@JohnCSimonJohnCSimon added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 5, 2021
@bors

bors commented Jan 16, 2022

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #92598) made this pull request unmergeable. Please resolve the merge conflicts.

@the8472the8472 added the S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. label Jan 16, 2022
@SkiFire13
SkiFire13 deleted the hide-tostring-spec branch March 15, 2022 09:01
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-inactiveStatus: Inactive and waiting on the author. This is often applied to closed PRs.S-waiting-on-reviewStatus: Awaiting review from the assignee but also interested parties.T-libsRelevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@SkiFire13@rust-highfive@rust-log-analyzer@kennytm@the8472@bors@JohnCSimon@apiraino