cargo-semver-checks 0.48.0

Scan your Rust crate for semver violations.
Documentation
SemverQuery(
    id: "trait_method_const_generic_reordered",
    human_readable_name: "trait method const generics were reordered",
    description: "A trait method's signature now requires a generic type in the prior spot of a const generic.",
    required_update: Major,
    lint_level: Deny,
    reference_link: Some("https://doc.rust-lang.org/reference/items/generics.html"),
    query: r#"
    {
        CrateDiff {
            baseline {
                item {
                    ... on Trait {
                        visibility_limit @filter(op: "=", value: ["$public"])
                        name @output

                        importable_path {
                            path @tag @output
                            public_api @filter(op: "=", value: ["$true"])
                        }

                        method {
                            public_api_eligible @filter(op: "=", value: ["$true"])
                            method: name @output @tag

                            # The method takes the same number of const generic
                            # and generic type parameters as before.
                            # Otherwise other lints will trigger instead:
                            # - `trait_method_requires_different_const_generic_params`
                            # - `trait_method_requires_different_generic_type_params`
                            generic_parameter @fold
                                              @transform(op: "count")
                                              @tag(name: "required_const_count")
                                              @output(name: "required_const_count") {
                                ... on GenericConstParameter {
                                    name
                                }
                            }
                            generic_parameter @fold
                                              @transform(op: "count")
                                              @tag(name: "required_type_count")
                                              @output(name: "required_type_count") {
                                ... on GenericTypeParameter {
                                    name
                                }
                            }

                            # But a const generic parameter at a specific position in the signature
                            # has become a generic type instead. This is a breaking change.
                            generic_parameter {
                                ... on GenericConstParameter {
                                    const_name: name @output
                                    position @tag @output
                                }
                            }
                        }
                    }
                }
            }
            current {
                item {
                    ... on Trait {
                        visibility_limit @filter(op: "=", value: ["$public"])

                        importable_path {
                            path @filter(op: "=", value: ["%path"])
                            public_api @filter(op: "=", value: ["$true"])
                        }

                        method {
                            public_api_eligible @filter(op: "=", value: ["$true"])
                            name @filter(op: "=", value: ["%method"])

                            generic_parameter @fold
                                              @transform(op: "count")
                                              @filter(op: "=", value: ["%required_const_count"]) {
                                ... on GenericConstParameter {
                                    name
                                }
                            }
                            generic_parameter @fold
                                              @transform(op: "count")
                                              @filter(op: "=", value: ["%required_type_count"]) {
                                ... on GenericTypeParameter {
                                    name
                                }
                            }

                            generic_parameter {
                                ... on GenericTypeParameter {
                                    type_name: name @output
                                    position @filter(op: "=", value: ["%position"])
                                }
                            }

                            span_: span @optional {
                                filename @output
                                begin_line @output
                                end_line @output
                            }
                        }
                    }
                }
            }
        }
    }"#,
    arguments: {
        "public": "public",
        "true": true,
    },
    error_message: "A trait method's signature now requires a generic type parameter where a const generic previously stood. Implementations or calls of this trait method that supplied that const generic will be broken since a generic type is now required instead.",
    per_result_error_template: Some("{{name}}::{{method}} used to expect const {{const_name}} in the place of type {{type_name}} in {{span_filename}}:{{span_begin_line}}"),
    // TODO: see https://github.com/obi1kenobi/cargo-semver-checks/blob/main/CONTRIBUTING.md#adding-a-witness
    // for information about this field.
    //
    // The witness would be a trait method invocation or implementation using the old
    // const generic position, which is insufficient for the new definition.
    witness: None,
)