SemverQuery(
id: "trait_method_receiver_owned_became_mut_ref",
human_readable_name: "trait method receiver changed from owned self to mutable reference",
description: "A method in a pub trait changed its receiver from self to &mut self.",
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
importable_path {
path @tag @output
public_api @filter(op: "=", value: ["$true"])
}
method {
method_name: name @output @tag
public_api_eligible @filter(op: "=", value: ["$true"])
receiver {
by_value @filter(op: "=", value: ["$true"])
receiver_kind: kind @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 {
name @filter(op: "=", value: ["%method_name"])
public_api_eligible @filter(op: "=", value: ["$true"])
receiver {
by_mut_reference @filter(op: "=", value: ["$true"])
kind @filter(op: "=", value: ["%receiver_kind"])
}
span_: span @optional {
filename @output
begin_line @output
end_line @output
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"true": true,
},
error_message: "A trait method in an unsealed trait now takes &mut self instead of taking ownership. This breaks calls that use fully-qualified syntax, as well as any downstream implementations of the trait.",
per_result_error_template: Some("{{join \"::\" path}}::{{method_name}} now takes &mut {{receiver_kind}} instead of {{receiver_kind}}, in {{span_filename}}:{{span_begin_line}}"),
// `value.method()` would work;
// the breakage is `Trait::method(value)` which has to be `Trait::method(&mut value)`
witness: None,
)