georust / geographiclib-rs

A port of geographiclib in Rust.
MIT License
41 stars 9 forks source link

Compilation error[E0195]: lifetime parameters or bounds on type `Target` do not match the trait declaration #54

Closed stephan-j-lange closed 9 months ago

stephan-j-lange commented 10 months ago

Hello,

I'm getting an compilation error when implementing the first example as mentioned in https://crates.io/crates/geographiclib-rs

Compiling geographiclib-rs v0.2.3
error[E0195]: lifetime parameters or bounds on type `Target` do not match the trait declaration
  --> /Users/d029158/.cargo/registry/src/index.crates.io-6f17d22bba15001f/geographiclib-rs-0.2.3/src/geodesic.rs:45:1
   |
45 | / lazy_static! {
46 | |     static ref WGS84_GEOD: Geodesic = Geodesic::new(WGS84_A, WGS84_F);
47 | | }
   | |_^ lifetimes do not match type in trait
   |
   = note: this error originates in the macro `__lazy_static_internal` which comes from the expansion of the macro `lazy_static` (in Nightly builds, run with -Z macro-backtrace for more info)

I have got the same error when compiling a program which uses surrealdb as surrealdb has a dependency to geographiclib-rs v0.2.3.

I'm using a MacBook with the following processor: 2,3 GHz 8-Core Intel Core i9.

Do you have an idea what the problem is?

Kind regards, Stephan

michaelkirk commented 9 months ago

I'm not immediately able to reproduce your issue. I've just added a compilable example with #55 which successfully builds.

Can you tell me the output of cargo --version?

stephan-j-lange commented 9 months ago

I'm using the following cargo version: cargo 1.75.0 (1d8b05cdd 2023-11-20)

My test program is pretty much the example that you are providing.

use geographiclib_rs::{Geodesic, DirectGeodesic};

fn main() {
    // Determine the point 10000 km NE of JFK - the "direct" geodesic calculation.
    let g = Geodesic::wgs84();
    let jfk_lat = 40.64;
    let jfk_lon = -73.78;
    let northeast_azimuth = 45.0;

    let (lat, lon, az) = g.direct(jfk_lat, jfk_lon, northeast_azimuth, 10e6);

    use approx::assert_relative_eq;
    assert_relative_eq!(lat, 32.621100463725796);
    assert_relative_eq!(lon, 49.05248709295982);
    assert_relative_eq!(az,  140.4059858768007);
}

Is it maybe a problem of lazy_static? It has not been maintained for years and there are alternatives available in the standard library now.

michaelkirk commented 9 months ago

Are you able to clone this repository and build the examples?

CI shows that it's possible: https://github.com/georust/geographiclib-rs/pull/55

Is it maybe a problem of lazy_static? It has not been maintained for years and there are alternatives available in the standard library now.

I think it's been stable for years, so it hasn't needed much maintenance.

But yes there are alternatives in std now. Would you be interested in opening a PR to migrate? And do the research to know which MSRV introduced the alternatives so you know what we'd need to bump our MSRV to?

stephan-j-lange commented 9 months ago

Hello Michael,

I have reinstalled Rust and now it works and I can compile the example application. I still don't understand the reason, but the issue was obviously not related to your repository. Sorry for the inconvenience!

Kind regards, Stephan