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

clone of fn has odd lifetime issues that copy of fn does not #14820

Closed
pnkfelix opened this issue Jun 11, 2014 · 4 comments
Closed

clone of fn has odd lifetime issues that copy of fn does not #14820

pnkfelix opened this issue Jun 11, 2014 · 4 comments
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@pnkfelix
Copy link
Member

Code:

#![crate_type="lib"]

#[cfg(v1)]
pub fn foo(f: fn<'a>(x: &'a())) -> fn<'b>(y: &'b()) { f }

#[cfg(v2)]
pub fn foo(f: fn<'a>(x: &'a())) -> fn<'b>(y: &'b()) { f.clone() }

Transcript of compile attempts:

% rustc --cfg v1 /tmp/cf.rs
% rustc --cfg v2 /tmp/cf.rs
/tmp/cf.rs:7:55: 7:64 error: mismatched types: expected `fn(&'b ())` but found `fn(&())` (expected concrete lifetime, but found bound lifetime parameter 'b)
/tmp/cf.rs:7 pub fn foo(f: fn<'a>(x: &'a())) -> fn<'b>(y: &'b()) { f.clone() }
                                                                   ^~~~~~~~~
note: expected concrete lifetime is lifetime ReInfer(ReVar(middle::ty::RegionVid{id: 43u}))
error: aborting due to previous error
% 
@pnkfelix
Copy link
Member Author

cc @nikomatsakis

@pnkfelix
Copy link
Member Author

Note that this bug can also manifest itself more subtly if one attempts to do #[deriving(Clone)] on a struct that has a field of type fn (...) -> ..

@nikomatsakis
Copy link
Contributor

I think this has to do with the implementation of Clone for fn types, which is kinda broken because it loses bound lifetimes. After #5527 lands, we'll be able to do:

impl<T:Copy> Clone for T { ... }

and then remove the impls for bare fns, which should solve this problem, at least in this case.

@ghost ghost added the E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. label Oct 30, 2014
@ghost
Copy link

ghost commented Nov 2, 2014

Closing as a dupe of #12741.

@ghost ghost closed this as completed Nov 2, 2014
bors added a commit to rust-lang-ci/rust that referenced this issue Jun 5, 2023
Expand `format_args!` with more details
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

No branches or pull requests

2 participants