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 and Associated Types combine to make fn not implement corresponding Fn trait #28994

Closed
gereeter opened this issue Oct 12, 2015 · 5 comments · Fixed by #131355
Closed

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

gereeter opened this issue Oct 12, 2015 · 5 comments · Fixed by #131355
Labels
A-associated-items Area: Associated items (types, constants & functions) A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Comments

@gereeter
Copy link
Contributor

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
@gereeter
Copy link
Contributor Author

I'm using rustc 1.5.0-nightly (87cd2c082 2015-10-10).

@huonw huonw added A-lifetimes Area: Lifetimes / regions A-associated-items Area: Associated items (types, constants & functions) labels Oct 13, 2015
@huonw
Copy link
Member

huonw commented Oct 13, 2015

cc @nikomatsakis

@jfager
Copy link
Contributor

jfager commented Mar 21, 2017

Still an issue (playpen).

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 24, 2017
@bstrie
Copy link
Contributor

bstrie commented Feb 20, 2020

Triage: no change as of Rust 1.41:

error[E0271]: type mismatch resolving `for<'a> <for<'a> fn(&'a ()) -> <() as LifetimeToType<'a>>::Out {id} as std::ops::FnOnce<(&'a (),)>>::Output == <() as LifetimeToType<'a>>::Out`
  --> src/main.rs:16:5
   |
13 | fn assert_fn<F: for<'a> FnOnce(&'a ()) -> <() as LifetimeToType<'a>>::Out>(_func: F) { }
   |    ---------                              ------------------------------- required by this bound in `assert_fn`
...
16 |     assert_fn(id);
   |     ^^^^^^^^^ expected associated type, found `&()`
   |
   = note: expected associated type `<() as LifetimeToType<'_>>::Out`
                    found reference `&()`
   = note: consider constraining the associated type `<() as LifetimeToType<'_>>::Out` to `&()` or calling a method that returns `<() as LifetimeToType<'_>>::Out`
   = note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html

@Enselic Enselic added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Dec 10, 2023
@fmease
Copy link
Member

fmease commented Sep 24, 2024

Triage: This compiles just fine now.

@fmease fmease added A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-types Relevant to the types team, which will review and decide on the PR/issue. labels Sep 24, 2024
bors added a commit to rust-lang-ci/rust that referenced this issue Oct 7, 2024
Add tests for some old fixed issues

Closes rust-lang#30867
Closes rust-lang#30472
Closes rust-lang#28994
Closes rust-lang#26719 (and migrates the relevant test to the new run-make)
Closes rust-lang#23600

cc `@jieyouxu` for the run-make-support changes

try-job: x86_64-msvc
@bors bors closed this as completed in cc5a24c Oct 8, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 8, 2024
Rollup merge of rust-lang#131355 - clubby789:old-tests, r=jieyouxu

Add tests for some old fixed issues

Closes rust-lang#30867
Closes rust-lang#30472
Closes rust-lang#28994
Closes rust-lang#26719 (and migrates the relevant test to the new run-make)
Closes rust-lang#23600

cc `@jieyouxu` for the run-make-support changes

try-job: x86_64-msvc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-associated-items Area: Associated items (types, constants & functions) A-higher-ranked Area: Higher-ranked things (e.g., lifetimes, types, trait bounds aka HRTBs) A-lifetimes Area: Lifetimes / regions C-bug Category: This is a bug. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants