SemverQuery(
id: "struct_marked_non_exhaustive",
human_readable_name: "struct marked #[non_exhaustive]",
description: "An exhaustive struct has been marked #[non_exhaustive].",
reference: Some("An exhaustive struct has been marked #[non_exhaustive] making it no longer constructible using a struct literal outside its crate."),
required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#attr-adding-non-exhaustive"),
query: r#"
{
CrateDiff {
current {
item {
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output
struct_type @output
# The struct is now marked #[non_exhaustive] so it can't be constructed
# using a struct literal outside of its crate. This is the breaking change.
attrs @filter(op: "contains", value: ["$non_exhaustive"])
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
filename @output
begin_line @output
}
}
}
}
baseline {
item {
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"])
attrs @filter(op: "not_contains", value: ["$non_exhaustive"])
# Ensure the struct could previously be constructed outside of its crate
# using a struct literal: it did not have any private fields.
field @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
visibility_limit @filter(op: "!=", value: ["$public"])
}
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"non_exhaustive": "#[non_exhaustive]",
"true": true,
"zero": 0,
},
error_message: "A public struct has been marked #[non_exhaustive], which will prevent it from being constructed using a struct literal outside of its crate. It previously had no private fields, so a struct literal could be used to construct it outside its crate.",
per_result_error_template: Some("struct {{name}} in {{span_filename}}:{{span_begin_line}}"),
)