Skip to content
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

HRTB rules do not permit "perfect forwarding" of the Fn traits #19730

Closed
nikomatsakis opened this issue Dec 11, 2014 · 1 comment · Fixed by #19884
Closed

HRTB rules do not permit "perfect forwarding" of the Fn traits #19730

nikomatsakis opened this issue Dec 11, 2014 · 1 comment · Fixed by #19884
Assignees

Comments

@nikomatsakis
Copy link
Contributor

It'd be nice to be able to define an impl like this:

impl<Sized? F,A,R> FnMut<A,R> for F
    where F : Fn<A,R>
{
    extern "rust-call" fn call_mut(&mut self, args: A) -> R {
        self.call(args)
    }
}

However, at present impls like this fail to apply for a bound like FnMut(&int) -> &int. This is because the bound region is not part of the impl declaration, and so the current higher-ranked code views this impl as as provided insufficient polymorphism. However, this code is just overly conservative. This is a problem because that impl above is crucial to the overall design.

But wait, you say! I thought there WAS an impl like that which had landed. This is true. Unfortunately, there is also a bug in the higher-ranked code that is presently masking the failure I would expect to see. In other words, the bug allows this impl to function correctly (but also other impls which should not).

I have a plan to fix this but it requires rejiggering how we process HRTB bounds. Instead of an impl providing a higher-ranked trait reference, and then relying on subtyping of trait references, we will instead have the trait selector skolemize the trait reference it is looking for and attempt to match impls. We can then do the same taint checking procedure and so forth, but in the trait checker. I won't go into the details here, it's hard to explain concisely.

@nikomatsakis
Copy link
Contributor Author

Got this mostly implemented now.

nikomatsakis added a commit to nikomatsakis/rust that referenced this issue Dec 19, 2014
bors added a commit that referenced this issue Dec 19, 2014
…ng, r=pnkfelix

Rewrite how the HRTB algorithm matches impls against obligations. Instead of impls providing higher-ranked trait-references, impls now once again only have early-bound regions. The skolemization checks are thus moved out into trait matching itself. This allows to implement "perfect forwarding" impls like those described in #19730. This PR builds on a previous PR that was already reviewed by @pnkfelix.

r? @pnkfelix 

Fixes #19730
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant