Skip to content

HRTB and Associated Types combine to make fn not implement corresponding Fn trait #28994

Description

@gereeter
trait LifetimeToType<'a> {
    type Out;
}

impl<'a> LifetimeToType<'a> for () {
    type Out = &'a ();
}

fn id<'a>(val: &'a ()) -> <() as LifetimeToType<'a>>::Out {
    val
}

fn assert_fn<F: for<'a> FnOnce(&'a ()) -> <() as LifetimeToType<'a>>::Out>(_func: F) { }

fn main() {
    assert_fn(id);
}

fails with

test.rs:16:5: 16:14 error: type mismatch resolving `for<'a> <fn(&'a ()) -> <() as LifetimeToType<'a>>::Out {id} as core::ops::FnOnce<(&'a (),)>>::Output == <() as LifetimeToType<'a>>::Out`:
 expected &-ptr,
    found associated type [E0271]
test.rs:16     assert_fn(id);
               ^~~~~~~~~
test.rs:16:5: 16:14 help: run `rustc --explain E0271` to see a detailed explanation
test.rs:16:5: 16:14 note: required by `assert_fn`
error: aborting due to previous error

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-associated-itemsArea: Associated items (types, constants & functions)A-higher-rankedArea: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs)A-lifetimesArea: Lifetimes / regionsC-bugCategory: This is a bug.E-needs-testCall for participation: An issue has been fixed and does not reproduce, but no test has been added.T-compilerRelevant to the compiler 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.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions