SemverQuery(
id: "trait_method_parameter_count_changed",
human_readable_name: "pub trait method parameter count changed",
description: "A trait method requires a different number of parameters than it used to.",
required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#trait-item-signature"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
method {
method_name: name @output @tag
public_api_eligible @filter(op: "=", value: ["$true"])
old_parameter_: parameter @fold @transform(op: "count") @output @tag(name: "parameters") {
name @filter(op: "!=", value: ["$self"])
}
receiver @fold @transform(op: "count") @tag(name: "has_receiver") @output(name: "has_receiver")
}
}
}
}
current {
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"])
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
method {
name @filter(op: "=", value: ["%method_name"])
new_parameter_: parameter @fold @transform(op: "count") @filter(op: "!=", value: ["%parameters"]) @output {
name @filter(op: "!=", value: ["$self"])
}
receiver @fold @transform(op: "count") @filter(op: "=", value: ["%has_receiver"])
span_: span @optional {
filename @output
begin_line @output
end_line @output
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"self": "self",
"true": true,
},
// TODO: This has a false-positive edge case, because it assumes the trait method
// was *previously* callable. This might not be the case for partially-sealed traits
// which can make some methods uncallable. In that case, the method signature change
// is not a breaking change, since it could never have been called in the first place.
// If the trait wasn't sealed and the method didn't have a default impl, then
// the change is still breaking even if the method wasn't callable -- it's just
// on the side of implementing the trait, not calling the method.
error_message: "A trait method now takes a different number of parameters.",
per_result_error_template: Some("{{name}}::{{method_name}} now takes {{new_parameter_count}} instead of {{old_parameter_count}} parameters, in file {{span_filename}}:{{span_begin_line}}"),
)