SemverQuery(
id: "inherent_method_const_removed",
human_readable_name: "pub method is no longer const",
description: "A method or associated fn can no longer be called in a const context.",
required_update: Major,
reference_link: Some("https://doc.rust-lang.org/reference/const_eval.html"),
query: r#"
{
CrateDiff {
baseline {
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"]) @output
importable_path {
path @output @tag
}
inherent_impl {
method {
method_visibility: visibility_limit @filter(op: "=", value: ["$public"]) @output
method_name: name @output @tag
const @filter(op: "=", value: ["$true"])
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}
current {
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"])
name @output
importable_path {
path @filter(op: "=", value: ["%path"])
}
# We use "impl" instead of "inherent_impl" here because moving
# an inherently-implemented method to a trait is not necessarily
# a breaking change, so we don't want to report it.
#
# We look for "zero matching const methods" rather than
# "methods that are not const" (incorrect!) since multiple methods with
# the same name are allowed to exist on the same type (e.g. via traits).
#
# The above by itself is still not enough: say if the method was removed,
# that still makes the "there is no method ..." statement true.
# So we add an additional clause demanding that a method by that name
# with appropriate visibility actually exists.
impl @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
method {
visibility_limit @filter(op: "one_of", value: ["$public_or_default"])
name @filter(op: "=", value: ["%method_name"])
}
}
impl @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
method {
visibility_limit @filter(op: "one_of", value: ["$public_or_default"])
name @filter(op: "=", value: ["%method_name"])
const @filter(op: "=", value: ["$true"])
}
}
# Get the non-matching methods by that name so we can report them
# in the lint error message.
impl @fold {
method {
visibility_limit @filter(op: "one_of", value: ["$public_or_default"])
name @filter(op: "=", value: ["%method_name"])
unsafe @filter(op: "=", value: ["$true"])
non_matching_span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"public_or_default": ["public", "default"],
"zero": 0,
"true": true,
},
error_message: "A publicly-visible method or associated fn is no longer `const` and can no longer be used in a `const` context.",
per_result_error_template: Some("{{name}}::{{method_name}} in file {{span_filename}}:{{span_begin_line}}"),
)