Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upPassing a `Fn` to an `fn` now requires explicit lifetimes for the `Fn` and all references passed to it when invoked #25310
Comments
This comment has been minimized.
This comment has been minimized.
|
Or this might be an intentional breakage from #24461. |
This comment has been minimized.
This comment has been minimized.
|
I don't see |
steveklabnik
added
the
A-closures
label
May 13, 2015
This comment has been minimized.
This comment has been minimized.
|
This is a regression from Rust 1.0 |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
There is also this approach to working around the problem: use a use std::env;
use std::ffi::OsString;
fn foo<F>(bar: &F) -> Option<OsString>
where F: for <'r> Fn(&'r str) -> Option<OsString>
{
bar("HOME")
}
fn main() {
println!("{:?}", foo(&|x|env::var_os(x)));
} |
This comment has been minimized.
This comment has been minimized.
|
Playpen of the failing-on-nightly-but-not-stable version, for reference: http://is.gd/UIC7SX (playpen is now on a nightly new enough to reproduce the failure, despite the inline comment) |
brson
added
I-nominated
regression-from-stable-to-nightly
labels
May 28, 2015
This comment has been minimized.
This comment has been minimized.
|
Nominating because @bluss suggested this was a stable regression. |
This comment has been minimized.
This comment has been minimized.
|
(Just noticed I hadn't included the error message)
|
This comment has been minimized.
This comment has been minimized.
|
Hmm. I do think that this should work. If you edit the example to use a crate-local fn, for example, it does work: http://is.gd/vaEi9C use std::env;
use std::ffi::{OsStr, OsString};
fn test<K:?Sized>(_: &K) -> Option<OsString> where K: AsRef<OsStr> { None }
/* Explicit lifetimes are required by rust-2015-05-11 nightly (newer than playpen) */
fn foo<'a, F>(bar: &'a F) -> Option<OsString>
where F: Fn(&str) -> Option<OsString>
{
bar("HOME")
}
fn main() {
println!("{:?}", foo(&test));
} |
This comment has been minimized.
This comment has been minimized.
|
triage: P-high I'm going to mark this as P-high because I agree it is a regression. My guess would be that perhaps it is related to #24615 or some of the other recent changes to trait selection, but I'll have to dive in and trace it out. |
rust-highfive
added
P-high
and removed
I-nominated
labels
Jun 2, 2015
nikomatsakis
self-assigned this
Jun 2, 2015
nikomatsakis
added
the
T-lang
label
Jun 2, 2015
This comment has been minimized.
This comment has been minimized.
|
So, I've tracked down the origin, but the code in question has landed in stable already. The cause was commit 9b88cd1. This modified the definition of @@ -197,7 +197,7 @@ pub fn var<K: ?Sized>(key: &K) -> Result<String, VarError> where K: AsRef<OsStr>
/// }
/// ```
#[stable(feature = "env", since = "1.0.0")]
-pub fn var_os<K: ?Sized>(key: &K) -> Option<OsString> where K: AsRef<OsStr> {
+pub fn var_os<K: AsRef<OsStr>>(key: K) -> Option<OsString> {
let _g = ENV_LOCK.lock();
os_imp::getenv(key.as_ref())
}One effect of this definition is that let x = var_os;
x(..);
x(..);vs var_os(..);
var_os(..);In this case, the code was capturing a single reference to I'm going to close this, since the code has made it to stable and doesn't seem to have caused dramatic impact, but it's an interesting regression vector. cc @rust-lang/libs <-- this should be kept in mind in the future. |
nikomatsakis
closed this
Jul 24, 2015
This comment has been minimized.
This comment has been minimized.
|
Ah, I see @pnkfelix suggested the second change already. The reason that this works is that it is equivalent to making one reference to |
jmesmon commentedMay 11, 2015
Playpen: http://is.gd/LYhXZx
Might be caused by: #25212
I'm unsure if this is an actual issue that can be fixed, but figured I'd open an issue in case it was.