Skip to content

Comparison of Versions also compares build metadata #303

@GoldsteinE

Description

@GoldsteinE

Hi! This code:

use semver::Version;

fn main() {
    let a = Version::parse("0.0.0+a").unwrap();
    let b = Version::parse("0.0.0+b").unwrap();
    dbg!(a.cmp(&b));
}

currently prints

[src/main.rs:6] a.cmp(&b) = Less

According to SemVer 2.0.0 # 10, comparing versions should ignore build metadata. Including it in this comparison also create an inconsistency with VersionReq and makes cargo consider version change from 0.0.0+b to 0.0.0+a downgrading.

Crate documentation also suggests that implementation of Ord for BuildMetadata is only to allow comparing two BuildMetadata values and shouldn’t affect versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions