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

Not desugaring to HRTB for closure argument #73433

Open
alecmocatta opened this issue Jun 17, 2020 · 1 comment
Open

Not desugaring to HRTB for closure argument #73433

alecmocatta opened this issue Jun 17, 2020 · 1 comment
Labels
A-closures Area: Closures (`|…| { … }`) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@alecmocatta
Copy link
Contributor

alecmocatta commented Jun 17, 2020

My understanding was that FnMut(&T) desugars to for<'a> FnMut(&'a T). In this instance, it is seemingly not doing so. If you comment out line 44 then this compiles. Why is the map function triggering the incorrect (?) desugaring, and how can I fix it?

trait Pipe<In> {
    type Out;
}

struct Identity;
impl<In> Pipe<In> for Identity {
    type Out = In;
}

struct Map<P, F> {
    p: P,
    f: F,
}
impl<P, In, F, R> Pipe<In> for Map<P, F>
where
    P: Pipe<In>,
    F: FnMut(P::Out) -> R,
{
    type Out = R;
}

fn map<P, In, F, R>(p: P, f: F) -> Map<P, F>
where
    P: Pipe<In>,
    F: FnMut(P::Out) -> R,
{
    Map { p, f }
}

fn pipe<T, Sink>(_: Sink)
where
    Sink: for<'a> Pipe<&'a T>,
    T: 'static,
{
}

fn main() {
    fn abc<'a>(_: &'a String) {}
    pipe(Map {
        p: Identity,
        f: |_: &String| {},
    });
    pipe(map(Identity, abc));
    pipe(map(Identity, |_: &String| {}));
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
  --> src/main.rs:44:5
   |
44 |     pipe(map(Identity, |_: &String| {}));
   |     ^^^^ one type is more general than the other
   |
   = note: expected type `std::ops::FnOnce<(&'a std::string::String,)>`
              found type `std::ops::FnOnce<(&std::string::String,)>`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: could not compile `playground`.

To learn more, run the command again with --verbose.


Possibly related: #70263

@camelid camelid added A-closures Area: Closures (`|…| { … }`) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Oct 20, 2020
@camelid
Copy link
Member

camelid commented Oct 20, 2020

Does anyone know if this is intended behavior?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-closures Area: Closures (`|…| { … }`) A-lifetimes Area: Lifetimes / regions T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

2 participants