SemverQuery(
id: "non_exhaustive_struct_added",
human_readable_name: "non-exhaustive pub struct added",
description: "A new non-exhaustive pub struct was added. It cannot be constructed using a struct literal outside of its defining crate, and pattern matching will require a wildcard.",
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: "contains", value: ["$non_exhaustive"])
# Ensure the struct can be constructed outside of its crate
# using a struct literal: it does not have any private fields.
field @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
visibility_limit @filter(op: "!=", value: ["$public"])
}
# Ensure that all fields are public API.
# Otherwise constructing the struct with a literal is not public API either.
field @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
public_api_eligible @filter(op: "!=", value: ["$true"])
}
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 #[non_exhaustive] pub struct was added. It cannot be constructed using a struct literal outside of its defining crate, and pattern matching will require a wildcard.",
per_result_error_template: Some("struct {{join \"::\" path}} in file {{span_filename}}:{{span_begin_line}}"),
)