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

proc with a reference as an argument meets lifetime errors when inferring type #14037

Closed
huonw opened this issue May 8, 2014 · 3 comments
Closed
Labels
A-lifetimes Area: Lifetimes / regions

Comments

@huonw
Copy link
Member

huonw commented May 8, 2014

fn main() {
    let f = proc(_) {};
    let g: proc(&()) = f;
}
proc_ref_infer.rs:3:24: 3:25 error: mismatched types: expected `proc(&())` but found `proc(<generic #3>):Send` (expected concrete lifetime, but found bound lifetime parameter &)
proc_ref_infer.rs:3     let g: proc(&()) = f;
                                           ^
note: expected concrete lifetime is lifetime ReInfer(ReSkolemized(0u, BrAnon(0u)))
proc_ref_infer.rs:2:9: 2:23 error: cannot determine a type for this local variable: unconstrained type
proc_ref_infer.rs:2     let f = proc(_) {};
                            ^~~~~~~~~~~~~~
error: aborting due to 2 previous errors

Changing the argument type to something that's not a reference (e.g. just ()) works fine.

cc @nikomatsakis @pnkfelix

@alexcrichton
Copy link
Member

My best attempt at reproduction still reproduces:

fn main() {
    let f = |: _| {};
    let g: Box<FnMut(&())> = Box::new(f) as Box<FnMut(&())>;
}
foo.rs:3:30: 3:60 error: the trait `for<'r> core::ops::Fn(&'r ())` is not implemented for the type `closure[foo.rs:2:13: 2:21]`
foo.rs:3     let g: Box<FnMut(&())> = Box::new(f) as Box<FnMut(&())>;
                                      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
error: aborting due to previous error

@steveklabnik
Copy link
Member

Updated:

fn main() {
    let f = || {};
    let g: Box<FnMut(&())> = Box::new(f) as Box<FnMut(&())>;
}
hello.rs:3:30: 3:41 error: type mismatch: the type `[closure@hello.rs:2:13: 2:18]` implements the trait `core::ops::FnMut<()>`, but the trait `for<'r> core::ops::FnMut<(&'r (),)>` is required (expected tuple, found ()) [E0281]
hello.rs:3     let g: Box<FnMut(&())> = Box::new(f) as Box<FnMut(&())>;
                                        ^~~~~~~~~~~
hello.rs:3:30: 3:41 help: run `rustc --explain E0281` to see a detailed explanation
hello.rs:3:30: 3:41 note: required for the cast to the object type `for<'r> core::ops::FnMut(&'r ())`
hello.rs:3:30: 3:41 error: type mismatch: the type `[closure@hello.rs:2:13: 2:18]` implements the trait `core::ops::FnOnce<()>`, but the trait `for<'r> core::ops::FnOnce<(&'r (),)>` is required (expected tuple, found ()) [E0281]
hello.rs:3     let g: Box<FnMut(&())> = Box::new(f) as Box<FnMut(&())>;
                                        ^~~~~~~~~~~
hello.rs:3:30: 3:41 help: run `rustc --explain E0281` to see a detailed explanation
hello.rs:3:30: 3:41 note: required for the cast to the object type `for<'r> core::ops::FnMut(&'r ())`
error: aborting due to 2 previous errors

@Mark-Simulacrum
Copy link
Member

Closing in favor of #41078.

bors added a commit to rust-lang-ci/rust that referenced this issue Feb 13, 2023
Handle boolean scrutinees in match <-> if let replacement assists better
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lifetimes Area: Lifetimes / regions
Projects
None yet
Development

No branches or pull requests

4 participants