Skip to content

Tracking Issue for RFC 3591: useing a function from a trait #134691

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
1 of 4 tasks
clubby789 opened this issue Dec 23, 2024 · 7 comments
Open
1 of 4 tasks

Tracking Issue for RFC 3591: useing a function from a trait #134691

clubby789 opened this issue Dec 23, 2024 · 7 comments
Labels
B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC S-tracking-unimplemented Status: The feature has not been implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@clubby789
Copy link
Contributor

clubby789 commented Dec 23, 2024

This is a tracking issue for the RFC "Add support for use Trait::func" (rust-lang/rfcs#3591).
The feature gate for the issue is #![feature(import_trait_associated_functions)].

About tracking issues

Tracking issues are used to record the overall progress of implementation.
They are also used as hubs connecting to other relevant issues, e.g., bugs or open design questions.
A tracking issue is however not meant for large scale discussion, questions, or bug reports about a feature.
Instead, open a dedicated issue for the specific matter and add the relevant feature gate label.
Discussion comments will get marked as off-topic or deleted.
Repeated discussions on the tracking issue may lead to the tracking issue getting locked.

Steps

Unresolved Questions

Implementation history

@clubby789 clubby789 added the C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC label Dec 23, 2024
@fmease fmease added B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue. S-tracking-unimplemented Status: The feature has not been implemented. labels Dec 23, 2024
@crumblingstatue
Copy link
Contributor

crumblingstatue commented Dec 23, 2024

Might be worth noting that there is an orthogonal implementation of using a trait function through the unstable fn_delegation feature.

#![feature(fn_delegation)]

reuse Default::default;

fn main() {
    let s: i32 = default();
    dbg!(s);
}

Although my understanding is that this is just some kind of experiment, and will not be stabilized?
Might be worth taking a look at the implementation though.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 16, 2025
…sociated_functions, r=oli-obk

Implement `use` associated items of traits

This PR implements rust-lang#134691.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 16, 2025
…sociated_functions, r=oli-obk

Implement `use` associated items of traits

This PR implements rust-lang#134691.
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Jan 17, 2025
Rollup merge of rust-lang#134754 - frank-king:feature/import_trait_associated_functions, r=oli-obk

Implement `use` associated items of traits

This PR implements rust-lang#134691.
m-ou-se added a commit to m-ou-se/rust that referenced this issue Apr 3, 2025
unstable book: document import_trait_associated_functions

Documents rust-lang#134691 which was implemented in rust-lang#134754
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Apr 3, 2025
unstable book: document import_trait_associated_functions

Documents rust-lang#134691 which was implemented in rust-lang#134754
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Apr 3, 2025
Rollup merge of rust-lang#139149 - mejrs:itaf, r=ehuss

unstable book: document import_trait_associated_functions

Documents rust-lang#134691 which was implemented in rust-lang#134754
@joshtriplett
Copy link
Member

We were discussing this feature in a @rust-lang/libs-api meeting. We were wondering if the infrastructure that enables this feature would make it straightforward to provide a (separate) feature allowing use of an inherent function or associated constant/type from a concrete type.

@joshtriplett
Copy link
Member

Also, separately from that: what's the status of this feature? Are there any blockers that aren't in the (currently empty) list at the top of this tracking issue? If not, could @rust-lang/lang get a stabilization report, please?

@fmease
Copy link
Member

fmease commented Apr 29, 2025

Also, separately from that: what's the status of this feature? Are there any blockers that aren't in the (currently empty) list at the top of this tracking issue?

We have the open PR #138712 that will slightly relax the feature and make it deviate from the RFC. All that's left is another review, then I'll likely approve it (as a T-compiler member). Details can be found over there.

@fmease
Copy link
Member

fmease commented Apr 29, 2025

We were wondering if the infrastructure that enables this feature would make it straightforward to provide a (separate) feature allowing use of an inherent function or associated constant/type from a concrete type.

Not in the slightest. The feature whose development is being tracked here is solely powered by name resolution and its impl basically only needed to lift some artificial restrictions.

Referencing a specific inherent associated item on the other hand always requires type checking routines (namely, type unification) because they are first identified by their self type which can be arbitrary and contain aliases that'd need to be normalized first (which requires type checking routines). Don't forget about bounds & where clauses on impls themselves which would need to be checked by the trait solver to weed out impls and to normalize aliases.

Furthermore, the current use syntax won't do (fn_delegation's reuse comes closer, see below), how else would you be able to disambiguate between impl Ty<A> { fn f() {} } and impl Ty<B> { fn f() {} } if not by generic arguments which aren't syntactically allowed in uses. How would you refer to inherent impls for dyn Trait?

This is T-types territory. Even then, it's incredibly hard to support for the same reason why inherent associated types haven't been implemented for more than a decade — which we can likely only support in a more limited form via HACKs: See #140247 most recently.

Note that we also have the feature fn_delegation (reuse …; in code) (rust-lang/rfcs#3530) with which one can do a lot more things but it also doesn't support inherent associated items and likely won't do so anytime soon.

@petrochenkov
Copy link
Contributor

Note that we also have the feature fn_delegation (reuse …; in code) (rust-lang/rfcs#3530) with which one can do a lot more things but it also doesn't support inherent associated items and likely won't do so anytime soon.

Unlike in use imports, in delegation it should be quite realistic (there's an old semi-working prototype here), we are planning to implement it this year or in early 2026.

@fmease
Copy link
Member

fmease commented Apr 30, 2025

As long as you have Body (which you would have for reuse'd inherent assoc consts & fns) and lower the target via a FnCtxt instead of an ItemCtxt, everything should indeed be fine. The problem is ItemCtxts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-RFC-approved Blocker: Approved by a merged RFC but not yet implemented. C-tracking-issue Category: An issue tracking the progress of sth. like the implementation of an RFC S-tracking-unimplemented Status: The feature has not been implemented. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants