SemverQuery(
id: "exhaustive_struct_with_private_fields_added",
human_readable_name: "exhaustive pub struct with private fields added",
description: "A new pub struct with private fields was added.",
required_update: Minor,
lint_level: Allow,
reference_link: Some("https://doc.rust-lang.org/reference/attributes/type_system.html#the-non_exhaustive-attribute"),
query: r#"
{
CrateDiff {
current {
item {
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
attrs @filter(op: "not_contains", value: ["$non_exhaustive"])
# Ensure the struct has at least one private field,
# making it non-constructible via struct literal outside the crate.
field @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
visibility_limit @filter(op: "!=", value: ["$public"])
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
baseline @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
item {
... on ImplOwner {
importable_path {
path @filter(op: "=", value: ["%path"])
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"zero": 0,
"true": true,
"non_exhaustive": "#[non_exhaustive]",
},
error_message: "A new pub struct with non-public fields was added.",
per_result_error_template: Some("struct {{join \"::\" path}} in file {{span_filename}}:{{span_begin_line}}"),
)