Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding #[must_use] on an item #268

Closed
wants to merge 20 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/lints/enum_must_use_added.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SemverQuery(
id: "enum_must_use_added",
human_readable_name: "enum #[must_use] added",
description: "An enum has been marked with #[must_use].",
required_update: Minor,

// TODO: Change the reference link to point to the cargo semver reference
// once it has a section on attribute #[must_use].
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output

importable_path {
path @tag @output
}

attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
}
}
}
current {
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])

importable_path {
path @filter(op: "=", value: ["%path"])
}

attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"must_use": "must_use",
"zero": 0,
},
error_message: "An enum has been marked with #[must_use]. This can cause downstream crates that did not use this enum's value to get a compiler lint.",
per_result_error_template: Some("enum {{name}} in {{span_filename}}:{{span_begin_line}}"),
)
64 changes: 64 additions & 0 deletions src/lints/function_must_use_added.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SemverQuery(
id: "function_must_use_added",
human_readable_name: "function #[must_use] added",
description: "A function has been marked with #[must_use].",
required_update: Minor,

// TODO: Change the reference link to point to the cargo semver reference
// once it has a section on attribute #[must_use].
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output

importable_path {
path @tag @output
}

attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
}
}
}
current {
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])

importable_path {
path @filter(op: "=", value: ["%path"])
}

attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"must_use": "must_use",
"zero": 0,
},
error_message: "A function has been marked with #[must_use]. This can cause downstream crates that did not use the value returned by this function to get a compiler lint.",
per_result_error_template: Some("function {{join \"::\" path}} in {{span_filename}}:{{span_begin_line}}"),
)
78 changes: 78 additions & 0 deletions src/lints/inherent_method_must_use_added.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
SemverQuery(
id: "inherent_method_must_use_added",
human_readable_name: "inherent method #[must_use] added",
description: "An inherent method has been marked with #[must_use].",
required_update: Minor,

// TODO: Change the reference link to point to the cargo semver reference
// once it has a section on attribute #[must_use].
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"),
query: r#"
{
CrateDiff {
baseline {
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output

importable_path {
path @tag @output
}

inherent_impl {
method {
method_visibility: visibility_limit @filter(op: "=", value: ["$public"]) @output
method_name: name @tag @output

attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
}
}
}
}
}
current {
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])

importable_path {
path @filter(op: "=", value: ["%path"])
}

inherent_impl {
method {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%method_name"])

attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"must_use": "must_use",
"zero": 0,
},
error_message: "An inherent method has been marked with #[must_use]. This can cause downstream crates that did not use the value returned by this method to get a compiler lint.",
per_result_error_template: Some("inherent method {{join \"::\" path}}::{{method_name}} in {{span_filename}}:{{span_begin_line}}"),
)
89 changes: 89 additions & 0 deletions src/lints/method_must_use_added.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
SemverQuery(
id: "method_must_use_added",
human_readable_name: "method #[must_use] added",
description: "A method has been marked with #[must_use].",
required_update: Minor,

// TODO: Change the reference link to point to the cargo semver reference
// once it has a section on attribute #[must_use].
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"),
query: r#"
{
CrateDiff {
baseline {
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output

importable_path {
path @tag @output
}

inherent_impl {
method {
method_visibility: visibility_limit @filter(op: "=", value: ["$public"]) @output
method_name: name @tag @output

attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
}
}
}
}
}
current {
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])

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.
#
# It is also important to notice that #[must_use] can only be
# added to the method declaration or definition inside the trait.
# When #[must_use] is added to the definition inside an
# impl <trait_name> for <...> the attribute is ignored as only
# the attributes from the trait method declaration are applied.

impl {
method {
visibility_limit @filter(op: "one_of", value: ["$public_or_default"])
name @filter(op: "=", value: ["%method_name"])

attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"public_or_default": ["public", "default"],
"must_use": "must_use",
"zero": 0,
},
error_message: "A method has been marked with #[must_use]. This can cause downstream crates that did not use the value returned by this method to get a compiler lint.",
per_result_error_template: Some("method {{join \"::\" path}}::{{method_name}} in {{span_filename}}:{{span_begin_line}}"),
)
64 changes: 64 additions & 0 deletions src/lints/struct_must_use_added.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
SemverQuery(
id: "struct_must_use_added",
human_readable_name: "struct #[must_use] added",
description: "A struct has been marked with #[must_use].",
required_update: Minor,

// TODO: Change the reference link to point to the cargo semver reference
// once it has a section on attribute #[must_use].
reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-must_use-attribute"),
query: r#"
{
CrateDiff {
baseline {
item {
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output

importable_path {
path @tag @output
}

attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$must_use"])
}
}
}
}
}
current {
item {
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])

importable_path {
path @filter(op: "=", value: ["%path"])
}

attribute {
new_attr: raw_attribute @output
content {
base @filter(op: "=", value: ["$must_use"])
}
}

span_: span @optional {
filename @output
begin_line @output
}
}
}
}
}
}"#,
arguments: {
"public": "public",
"must_use": "must_use",
"zero": 0,
},
error_message: "A struct has been marked with #[must_use]. This can cause downstream crates that did not use this struct's value to get a compiler lint.",
per_result_error_template: Some("struct {{name}} in {{span_filename}}:{{span_begin_line}}"),
)
Loading