-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Unexplained lifetime error in closure type #11740
Comments
A more minimal example: struct Element {
attrs: ~[()],
}
impl Element {
pub unsafe fn get_attr<'a>(&'a self, name: &str) {
self.attrs.iter().find(|attr| {
let attr: () = std::cast::transmute(attr);
true
});
}
}
pub fn main() {} Another slightly peculiar thing: changing the
|
Is this same case? let it = range(100, 999).collect::<Vec<int>>();
println!("{}",
it.move_iter().flat_map(|x| range(x,999).collect::<Vec<int>>()
.iter()
.map(|j| j * x))
.filter(|x| x.to_str() == x.to_str().as_slice().chars().rev().collect::<String>())
.max_by(|x|x.to_int())
); |
@yuchen99 no, I think that is a legitimate error. The use std::iter;
it.move_iter().flat_map(|x| iter::range_step(x * x, 999 * x, x)).filter(... Also, you don't need the Lastly, saying "is not useful" doesn't help us help you :) In any case, you should ask a question like that on StackOverflow, not on an unrelated issue. |
@huonw I'm sorry to say that. |
I attempted to update this to work with the latest rust: struct Element {
attrs: Box<[()]>,
}
impl Element {
pub unsafe fn get_attr<'a>(&'a self, name: &str) {
self.attrs.iter().find(|attr| {
let attr: () = std::mem::transmute(attr);
true
});
}
}
pub fn main() {} but upon compiling, get this error:
|
@frewsxcv this builds (changed struct Element {
attrs: Box<[()]>,
}
impl Element {
pub unsafe fn get_attr<'a>(&'a self, name: &str) {
self.attrs.iter().find(|attr| { // or |attr: &&()|
let attr: Box<()> = std::mem::transmute(attr);
true
});
}
}
pub fn main() {} |
Triage: @remram44 's example still builds today. So it would seem maybe this is fixed? It's getting harder and harder to remember the old syntaxes, and how to most properly map them over... |
I can confirm that the error is gone: struct Attr {
name: String,
value: String,
}
struct Element {
attrs: Vec<Box<Attr>>,
}
impl Element {
pub unsafe fn get_attr<'a>(&'a self, name: &str) {
self.attrs
.iter()
.find(|attr| {
// To remove error: |attr: & & 'a Box<Attr>| {
let attr: &&Box<Attr> = std::mem::transmute(attr);
true
});
}
}
pub fn main() {
let element = Element { attrs: Vec::new() };
let _ = unsafe { element.get_attr("foo") };
} |
Do we want to add a regression test, or should we just close? |
Fixes rust-lang#11740. Fixes rust-lang#19601. Fixes rust-lang#22603 Fixes rust-lang#22789. Fixes rust-lang#26614. r? @Mark-Simulacrum.
Add tests for various issues Fixes rust-lang#11740. Fixes rust-lang#19601. Fixes rust-lang#22603 Fixes rust-lang#22789. Fixes rust-lang#26614. r? @Mark-Simulacrum.
Add tests for various issues Fixes rust-lang#11740. Fixes rust-lang#19601. Fixes rust-lang#22603 Fixes rust-lang#22789. Fixes rust-lang#26614. r? @Mark-Simulacrum.
In the following test, removing the type annotation from
attr
produces lifetime errors:Error message:
The text was updated successfully, but these errors were encountered: