You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Lang/libs coordination question: okay for libs to stabilize traits with final fn in them? #160394
I-lang-nominatedNominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.P-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.S-waiting-on-t-langStatus: Awaiting decision from T-langT-langRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
Filing this issue to get a definitive answer on whether @rust-lang/lang has any concerns about @rust-lang/libs-api stabilizing APIs in the standard library that use final fn.
If we stabilize such an API, that commits us to keeping this mechanism. That seems fine to me, as we have an accepted RFC and we seem to have a consistent expectation of shipping/stabilizing final fn.
Let's ask via FCP (and see what questions come up).
Proposal: We're OK with libs-api stabilizing traits with final fn (RFC 3678) in them subject to1 not stabilizing any trait or trait method that would prevent us from consistently putting these final fn methods in the vtable by making the trait dyn-incompatible if we did or by making it observable how Self is instantiated.
Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.
Totally fine with it for static dispatch, where the rules are clear.
I wonder if we could maybe make using the final fn methods via dyn still be unstable even if the method is stabilized to gain time to solidify exactly what the rules are going to be about that?
I was originally pondering allowing it only for #[rustc_dyn_incompatible_trait] traits, but Rng::fill_bytes looks like something that would be entirely reasonable to use behind dyn Rng.)
Reminder that I still think that final fn methods should be in the vtable, since that allows them to be optimized based on what the other methods they call do. (If <dyn RangeBounds>::contains were to be made final, I wouldn't want it making two dyn calls to get the bounds, for example, when it could make one dyn call to contains which then might not have to do any comparisons at all if the source of the bounds is RangeFull, for example.)
Aside: if Rng::fill_bytes is the motivating example, what's the soundness concern that makes it be final fn instead of an ordinary provided method? Or is it just trying to not put it into the vtable?
We discussed this in today's @rust-lang/lang meeting. We need to more definitively settle some of the questions around dyn and the vtable, so for now we'd like to ask libs-api to only stabilize traits using final fn if 1) they would otherwise be dyn-compatible, and 2) they don't do anything like calling type_id that would allow distinguishing whether it's in the vtable.
what's the soundness concern that makes it be final fn instead of an ordinary provided method?
Not a soundness concern, just wanting to distinguish "what can trait implementers implement", and avoid having to do a pair of circular definitions with must_implement_one_of.
Resolving my concern with the allowed stabilization limited as josh said above
if 1) they would otherwise be dyn-compatible, and
2) they don't do anything like calling type_id that would allow distinguishing whether it's in the vtable.
To document the reasoning: There's a question of whether final fn methods should appear in the vtable. If they do appear in the vtable, final fn would 1) not allow a trait to be dyn compatible when used on a dyn-incompatible method and 2) allow type_id and friends to observe the actual type from the final fn implementation. So by restricting its use in this way, we can change the answer later without changing any observable behavior.
So, I checked my box - but on consideration, I'm not really comfortable here with the information I (don't) have. This isn't a feature stabilization, but it is making something available on stable that requires (some, but minimal) types support.
I'd really like to know what it is exactly that we're committing to with t-types with these functions being used on stable. Perhaps the question around dyn/vtable things has been settled, and that's mostly a lang matter anyways. But, is there any official documentation on what final fn does? And how its implemented?
Looking at #151783, there are really only two things I see that are relevant to t-types:
final fn are ignored for dyn-compatibilty
final fn are not included in the vtable (and are called directly)
That's not much (and neither are really maintenance hazards), but I still want to ensure that this is documented clearly somewhere.
I-lang-nominatedNominated for discussion during a lang team meeting.I-lang-radarItems that are on lang's radar and will need eventual work or consideration.P-lang-drag-2Lang team prioritization drag level 2.https://rust-lang.zulipchat.com/#narrow/channel/410516-t-lang.S-waiting-on-t-langStatus: Awaiting decision from T-langT-langRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.T-typesRelevant to the types team, which will review and decide on the PR/issue.disposition-mergeThis issue / PR is in PFCP or FCP with a disposition to merge it.proposed-final-comment-periodProposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off.
Activity
lcnr commentedon Aug 3, 2026
what's the relevant RFC here and does this also matter for Types?
joboet commentedon Aug 3, 2026
For context: this came up in #160365, but I remember from the All Hands that libs-api would like to use this for
Allocator::by_refas well.The RFC is RFC#3678.
joshtriplett commentedon Aug 4, 2026
@lcnr If Types has recommendations here, I think they'd be relevant.
traviscross commentedon Aug 5, 2026
Let's ask via FCP (and see what questions come up).
Proposal: We're OK with libs-api stabilizing traits with
final fn(RFC 3678) in them subject to1 not stabilizing any trait or trait method that would prevent us from consistently putting thesefinal fnmethods in the vtable by making the trait dyn-incompatible if we did or by making it observable howSelfis instantiated.@rfcbot fcp merge lang,types
Footnotes
Edit 2026-08-10: See the resolution of the concern. ↩
rust-rfcbot commentedon Aug 5, 2026
@traviscross has proposed to merge this. The next step is review by the rest of the tagged team members:
Concerns:
discuss-what-this-promises-for-dynresolved by Lang/libs coordination question: okay for libs to stabilize traits withfinal fnin them? #160394 (comment)final fnin them? #160394 (comment))Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!
cc @rust-lang/lang-advisors: FCP proposed for lang, please feel free to register concerns.
cc @rust-lang/libs-ping: FCP proposed for libs, please feel free to register concerns.
See this document for info about what commands tagged team members can give me.
scottmcm commentedon Aug 5, 2026
@rfcbot concern discuss-what-this-promises-for-dyn
Totally fine with it for static dispatch, where the rules are clear.
I wonder if we could maybe make using the
final fnmethods viadynstill be unstable even if the method is stabilized to gain time to solidify exactly what the rules are going to be about that?I was originally pondering allowing it only for
#[rustc_dyn_incompatible_trait]traits, butRng::fill_byteslooks like something that would be entirely reasonable to use behinddyn Rng.)Reminder that I still think that
final fnmethods should be in the vtable, since that allows them to be optimized based on what the other methods they call do. (If<dyn RangeBounds>::containswere to be madefinal, I wouldn't want it making twodyncalls to get the bounds, for example, when it could make one dyn call tocontainswhich then might not have to do any comparisons at all if the source of the bounds isRangeFull, for example.)Aside: if
Rng::fill_bytesis the motivating example, what's the soundness concern that makes it befinal fninstead of an ordinary provided method? Or is it just trying to not put it into the vtable?joshtriplett commentedon Aug 5, 2026
We discussed this in today's @rust-lang/lang meeting. We need to more definitively settle some of the questions around
dynand the vtable, so for now we'd like to ask libs-api to only stabilize traits usingfinal fnif 1) they would otherwise be dyn-compatible, and 2) they don't do anything like callingtype_idthat would allow distinguishing whether it's in the vtable.We should document this in std-dev-guide.
joshtriplett commentedon Aug 5, 2026
Not a soundness concern, just wanting to distinguish "what can trait implementers implement", and avoid having to do a pair of circular definitions with
must_implement_one_of.scottmcm commentedon Aug 5, 2026
Resolving my concern with the allowed stabilization limited as josh said above
@rfcbot resolve discuss-what-this-promises-for-dyn
scottmcm commentedon Aug 5, 2026
tmandry commentedon Aug 5, 2026
@rfcbot reviewed
Agreed with the limitations listed in #160394 (comment).
To document the reasoning: There's a question of whether
final fnmethods should appear in the vtable. If they do appear in the vtable,final fnwould 1) not allow a trait to be dyn compatible when used on a dyn-incompatible method and 2) allowtype_idand friends to observe the actual type from thefinal fnimplementation. So by restricting its use in this way, we can change the answer later without changing any observable behavior.lcnr commentedon Aug 10, 2026
effectively this locks us into having some way of supporting "extension methods" with the following properties?
Trait::fooTraitis in scope of if the self type isdyn Trait.seems fine enough 🤷 cc rust-lang/library-trait-evolution-initiative#1 which has similar requirements
@rustbot reviewed
jackh726 commentedon Sep 22, 2026
@rustbot concern types-semantics-and-documentation
So, I checked my box - but on consideration, I'm not really comfortable here with the information I (don't) have. This isn't a feature stabilization, but it is making something available on stable that requires (some, but minimal) types support.
I'd really like to know what it is exactly that we're committing to with t-types with these functions being used on stable. Perhaps the question around dyn/vtable things has been settled, and that's mostly a lang matter anyways. But, is there any official documentation on what
final fndoes? And how its implemented?Looking at #151783, there are really only two things I see that are relevant to t-types:
final fnare ignored for dyn-compatibiltyfinal fnare not included in the vtable (and are called directly)That's not much (and neither are really maintenance hazards), but I still want to ensure that this is documented clearly somewhere.
rustbot commentedon Sep 22, 2026
Error: Cannot set
@rustbot concernon an active rfcbot FCP, use@rfcbot concerninstead.Please file an issue on GitHub at triagebot if there's a problem with this bot, or reach out on #triagebot on Zulip.
jackh726 commentedon Sep 22, 2026
@rfcbot concern types-semantics-and-documentation