Type mismatches resolving a closure that takes arguments by reference

The short version is that there’s a difference between the lifetimes that are inferred if the closure is written inline or stored as a variable. Write the closure inline and remove all the extraneous types: fn test(points: &[Point]) -> (&Point, f32) { let init = points.first().expect(“No initial”); fold(&points, (init, 0.), |(q, max_d), p| { let … Read more

When returning the outcome of consuming a StdinLock, why was the borrow to stdin retained?

This seems to be a bug in the compiler. You can make the compiler happy by using an explicit return statement: use std::io::{stdin, BufRead}; fn foo() -> usize { let stdin = stdin(); let stdinlock = stdin.lock(); return stdinlock .lines() .count(); } fn main() {} playground As mentioned in the comments, there are multiple Rust … Read more

Why am I being allowed to use a const qualified variable as an array size in C?

c99 support variable length arrays but c90 does not support variable length arrays, you can see this more clearly if you are using gcc and try to compile with these arguments: gcc -std=c89 -pedantic this will give you the following warning: warning: ISO C90 forbids variable length array ‘y’ [-Wvla] but if you compile using … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)