cargo-semver-checks 0.48.0

Scan your Rust crate for semver violations.
Documentation
SemverQuery(
    id: "inherent_method_const_generic_reordered",
    human_readable_name: "inherent method const generics were reordered",
    description: "An inherent 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 ImplOwner {
                        visibility_limit @filter(op: "=", value: ["$public"])

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

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

                                # The method takes the same number of const generic
                                # and generic type parameters as before.
                                # Otherwise other lints will trigger instead:
                                # - `method_requires_different_const_generic_params`
                                # - `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 generic type parameter at a specific position in the signature
                                # has become a const generic instead. This is a breaking change.
                                generic_parameter {
                                    ... on GenericConstParameter {
                                        const_name: name @output
                                        position @tag @output
                                    }
                                }

                            }
                        }
                    }
                }
            }
            current {
                item {
                    ... on ImplOwner {
                        visibility_limit @filter(op: "=", value: ["$public"])

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

                        # We use "impl" instead of "inherent_impl" here because moving
                        # an inherently-implemented method to a trait is not necessarily
                        # a breaking change, but changing the generic parameter kinds is.
                        impl {
                            method {
                                visibility_limit @filter(op: "one_of", value: ["$public_or_default"])
                                name @filter(op: "=", value: ["%method_name"])
                                public_api_eligible @filter(op: "=", value: ["$true"])

                                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",
        "public_or_default": ["public", "default"],
        "true": true,
    },
    error_message: "An inherent method's signature now requires a generic type parameter where a const generic previously stood. Uses of this method that supplied that const generic will be broken since a generic type is now required instead.",
    per_result_error_template: Some("method {{join \"::\" path}}::{{method_name}} used to expect const {{const_name}} in the place of type {{type_name}} in {{span_filename}}:{{span_begin_line}}"),
    witness: None,
)