diff --git a/src/lints/enum_must_use_added.ron b/src/lints/enum_must_use_added.ron new file mode 100644 index 00000000..49a54063 --- /dev/null +++ b/src/lints/enum_must_use_added.ron @@ -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}}"), +) diff --git a/src/lints/function_must_use_added.ron b/src/lints/function_must_use_added.ron new file mode 100644 index 00000000..915b44d3 --- /dev/null +++ b/src/lints/function_must_use_added.ron @@ -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}}"), +) diff --git a/src/lints/inherent_method_must_use_added.ron b/src/lints/inherent_method_must_use_added.ron new file mode 100644 index 00000000..e7590038 --- /dev/null +++ b/src/lints/inherent_method_must_use_added.ron @@ -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}}"), +) diff --git a/src/lints/method_must_use_added.ron b/src/lints/method_must_use_added.ron new file mode 100644 index 00000000..82624113 --- /dev/null +++ b/src/lints/method_must_use_added.ron @@ -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 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}}"), +) diff --git a/src/lints/struct_must_use_added.ron b/src/lints/struct_must_use_added.ron new file mode 100644 index 00000000..2c244a02 --- /dev/null +++ b/src/lints/struct_must_use_added.ron @@ -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}}"), +) diff --git a/src/lints/trait_must_use_added.ron b/src/lints/trait_must_use_added.ron new file mode 100644 index 00000000..1137c8e2 --- /dev/null +++ b/src/lints/trait_must_use_added.ron @@ -0,0 +1,64 @@ +SemverQuery( + id: "trait_must_use_added", + human_readable_name: "trait #[must_use] added", + description: "A trait 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 Trait { + 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 Trait { + 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 trait has been marked with #[must_use]. This can cause downstream crates that called a function returning an impl or dyn value of this trait to get a compiler lint.", + per_result_error_template: Some("trait {{join \"::\" path}} in {{span_filename}}:{{span_begin_line}}"), +) diff --git a/src/query.rs b/src/query.rs index 9816aeee..6b935e19 100644 --- a/src/query.rs +++ b/src/query.rs @@ -436,4 +436,9 @@ add_lints!( tuple_struct_to_plain_struct, unit_struct_changed_kind, variant_marked_non_exhaustive, + enum_must_use_added, + struct_must_use_added, + function_must_use_added, + trait_must_use_added, + inherent_method_must_use_added, ); diff --git a/test_crates/enum_must_use_added/new/Cargo.toml b/test_crates/enum_must_use_added/new/Cargo.toml new file mode 100644 index 00000000..6a362d66 --- /dev/null +++ b/test_crates/enum_must_use_added/new/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "enum_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/enum_must_use_added/new/src/lib.rs b/test_crates/enum_must_use_added/new/src/lib.rs new file mode 100644 index 00000000..48b99b76 --- /dev/null +++ b/test_crates/enum_must_use_added/new/src/lib.rs @@ -0,0 +1,62 @@ +// These enums did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +#[must_use] +pub enum EnumToMustUseEnum { + Bar, +} + +#[must_use = "Foo"] +pub enum EnumToMustUseMessageEnum { + Bar, +} + + +// These enums had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub enum MustUseEnumToEnum { + Bar, +} + +#[must_use = "Foo"] +pub enum MustUseEnumToMustUseMessageEnum { + Bar, +} + + +// These enums had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub enum MustUseMessageEnumToEnum { + Bar, +} + +#[must_use] +pub enum MustUseMessageEnumToMustUseEnum { + Bar, +} + +#[must_use = "Baz"] +pub enum MustUseMessageEnumToMustUseMessageEnum { + Bar, +} + + +// This enum is private and should NOT be reported by this rule. + +#[must_use] +enum MustUsePrivateEnum { + Bar, +} + + +// This enum was added in the new version of the crate with it's attribute. +// It should NOT be reported by this rule because adding a new enum is not +// a breaking change. + +#[must_use] +pub enum MustUseNewEnum { + Bar, +} diff --git a/test_crates/enum_must_use_added/old/Cargo.toml b/test_crates/enum_must_use_added/old/Cargo.toml new file mode 100644 index 00000000..6a362d66 --- /dev/null +++ b/test_crates/enum_must_use_added/old/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "enum_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/enum_must_use_added/old/src/lib.rs b/test_crates/enum_must_use_added/old/src/lib.rs new file mode 100644 index 00000000..c27a2965 --- /dev/null +++ b/test_crates/enum_must_use_added/old/src/lib.rs @@ -0,0 +1,51 @@ +// These enums did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +pub enum EnumToMustUseEnum { + Bar, +} + +pub enum EnumToMustUseMessageEnum { + Bar, +} + + +// These enums had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use] +pub enum MustUseEnumToEnum { + Bar, +} + +#[must_use] +pub enum MustUseEnumToMustUseMessageEnum { + Bar, +} + + +// These enums had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use = "Foo"] +pub enum MustUseMessageEnumToEnum { + Bar, +} + +#[must_use = "Foo"] +pub enum MustUseMessageEnumToMustUseEnum { + Bar, +} + +#[must_use = "Foo"] +pub enum MustUseMessageEnumToMustUseMessageEnum { + Bar, +} + + +// This enum is private and should NOT be reported by this rule. + +enum MustUsePrivateEnum { + Bar, +} diff --git a/test_crates/function_must_use_added/new/Cargo.toml b/test_crates/function_must_use_added/new/Cargo.toml new file mode 100644 index 00000000..58f04aa8 --- /dev/null +++ b/test_crates/function_must_use_added/new/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "function_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/function_must_use_added/new/src/lib.rs b/test_crates/function_must_use_added/new/src/lib.rs new file mode 100644 index 00000000..87c0ccd7 --- /dev/null +++ b/test_crates/function_must_use_added/new/src/lib.rs @@ -0,0 +1,44 @@ +// These functions did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +#[must_use] +pub fn FunctionToMustUseFunction() {} + +#[must_use = "Foo"] +pub fn FunctionToMustUseMessageFunction() {} + + +// These functions had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub fn MustUseFunctionToFunction() {} + +#[must_use = "Foo"] +pub fn MustUseFunctionToMustUseMessageFunction() {} + + +// These functions had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub fn MustUseMessageFunctionToFunction() {} + +#[must_use] +pub fn MustUseMessageFunctionToMustUseFunction() {} + +#[must_use = "Baz"] +pub fn MustUseMessageFunctionToMustUseMessageFunction() {} + + +// This function is private and should NOT be reported by this rule. + +#[must_use] +fn MustUsePrivateFunction() {} + + +// This function was added in the new version of the crate with it's attribute. +// It should NOT be reported by this rule because adding a new function is not +// a breaking change. + +#[must_use] +pub fn MustUseNewFunction() {} diff --git a/test_crates/function_must_use_added/old/Cargo.toml b/test_crates/function_must_use_added/old/Cargo.toml new file mode 100644 index 00000000..58f04aa8 --- /dev/null +++ b/test_crates/function_must_use_added/old/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "function_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/function_must_use_added/old/src/lib.rs b/test_crates/function_must_use_added/old/src/lib.rs new file mode 100644 index 00000000..dc6172f3 --- /dev/null +++ b/test_crates/function_must_use_added/old/src/lib.rs @@ -0,0 +1,35 @@ +// These functions did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +pub fn FunctionToMustUseFunction() {} + +pub fn FunctionToMustUseMessageFunction() {} + + +// These functions had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use] +pub fn MustUseFunctionToFunction() {} + +#[must_use] +pub fn MustUseFunctionToMustUseMessageFunction() {} + + +// These functions had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use = "Foo"] +pub fn MustUseMessageFunctionToFunction() {} + +#[must_use = "Foo"] +pub fn MustUseMessageFunctionToMustUseFunction() {} + +#[must_use = "Foo"] +pub fn MustUseMessageFunctionToMustUseMessageFunction() {} + + +// This function is private and should NOT be reported by this rule. + +fn MustUsePrivateFunction() {} diff --git a/test_crates/inherent_method_moved_must_use_added/new/Cargo.toml b/test_crates/inherent_method_moved_must_use_added/new/Cargo.toml new file mode 100644 index 00000000..4d6f75de --- /dev/null +++ b/test_crates/inherent_method_moved_must_use_added/new/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "inherent_method_moved_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/inherent_method_moved_must_use_added/new/src/lib.rs b/test_crates/inherent_method_moved_must_use_added/new/src/lib.rs new file mode 100644 index 00000000..8ccc4c32 --- /dev/null +++ b/test_crates/inherent_method_moved_must_use_added/new/src/lib.rs @@ -0,0 +1,165 @@ +pub struct StructWithMovedProvidedMustUseMethods {} + +pub trait TraitWithMovedProvidedMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + #[must_use] + fn MethodToMovedProvidedMustUseMethod(&self) {} + + #[must_use = "Foo"] + fn MethodToMovedProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes of + // the attribute, including deletion, should not be reported. + + fn MustUseMethodToMovedProvidedMethod(&self) {} + + #[must_use = "Foo"] + fn MustUseMethodToMovedProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + fn MustUseMessageMethodToMovedProvidedMethod(&self) {} + + #[must_use] + fn MustUseMessageMethodToMovedProvidedMustUseMethod(&self) {} + + #[must_use = "Baz"] + fn MustUseMessageMethodToMovedProvidedMustUseMessageMethod(&self) {} +} + +impl TraitWithMovedProvidedMustUseMethods for StructWithMovedProvidedMustUseMethods {} + + +pub struct StructWithMovedDeclaredMustUseMethods {} + +pub trait TraitWithMovedDeclaredMustUseMethods { + + #[must_use] + fn MethodToMovedDeclaredMustUseMethod(&self); + + #[must_use = "Foo"] + fn MethodToMovedDeclaredMustUseMessageMethod(&self); + + fn MustUseMethodToMovedDeclaredMethod(&self); + + #[must_use = "Foo"] + fn MustUseMethodToMovedDeclaredMustUseMessageMethod(&self); + + fn MustUseMessageMethodToMovedDeclaredMethod(&self); + + #[must_use] + fn MustUseMessageMethodToMovedDeclaredMustUseMethod(&self); + + #[must_use = "Baz"] + fn MustUseMessageMethodToMovedDeclaredMustUseMessageMethod(&self); +} + +impl TraitWithMovedDeclaredMustUseMethods for StructWithMovedDeclaredMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + fn MethodToMovedDeclaredMustUseMethod(&self) {} + + fn MethodToMovedDeclaredMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes of + // the attribute, including deletion, should not be reported. + + fn MustUseMethodToMovedDeclaredMethod(&self) {} + + fn MustUseMethodToMovedDeclaredMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + fn MustUseMessageMethodToMovedDeclaredMethod(&self) {} + + fn MustUseMessageMethodToMovedDeclaredMustUseMethod(&self) {} + + fn MustUseMessageMethodToMovedDeclaredMustUseMessageMethod(&self) {} +} + + +// This struct is private and adding #[must_use] to it's methods, +// after moving them to a private trait, should NOT be reported. + +struct PrivateStructWithMovedMustUseMethods {} + +trait PrivateTraitWithMovedMustUseMethods { + + #[must_use] + fn PrivateStructMethodToMovedPrivateDeclaredMustUseMethod(&self); + + #[must_use] + fn PrivateStructMethodToMovedPrivateProvidedMustUseMethod(&self) {} + + #[must_use] + fn PrivateStructMethodToMovedPrivateOverrideMustUseMethod(&self) {} +} + +impl PrivateTraitWithMovedMustUseMethods for PrivateStructWithMovedMustUseMethods { + + fn PrivateStructMethodToMovedPrivateDeclaredMustUseMethod(&self) {} + + fn PrivateStructMethodToMovedPrivateOverrideMustUseMethod(&self) {} +} + + +// Adding the #[must_use] attribute inside a trait's impl block +// does NOT generate a compiler lint when calling inner methods +// without using their return value. Thus it should NOT be reported. + +pub struct StructWithMovedImplMustUseMethods {} + +pub trait TraitWithMovedImplMustUseMethods { + + fn MethodToMovedImplDeclaredMustUseMethod(&self); + + fn MethodToMovedImplOverrideMustUseMethod(&self) {} +} + +impl TraitWithMovedImplMustUseMethods for StructWithMovedImplMustUseMethods { + + #[must_use] + fn MethodToMovedImplDeclaredMustUseMethod(&self) {} + + #[must_use] + fn MethodToMovedImplOverrideMustUseMethod(&self) {} +} + + +// This struct, trait and it's inherent methods were added in the new version of +// the crate, together with the method's attribute. It should NOT be reported +// because adding a new struct or trait is not a breaking change. + +pub struct NewStructWithTraitMustUseMethods {} + +pub trait NewTraitWithStructMustUseMethods { + + #[must_use] + fn NewTraitWithStructDeclaredMustUseMethod(&self); + + #[must_use] + fn NewTraitWithStructProvidedMustUseMethod(&self) {} + + #[must_use] + fn NewTraitWithStructOverrideMustUseMethod(&self) {} +} + +impl NewTraitWithStructMustUseMethods for NewStructWithTraitMustUseMethods { + + fn NewTraitWithStructDeclaredMustUseMethod(&self) {} + + fn NewTraitWithStructOverrideMustUseMethod(&self) {} +} diff --git a/test_crates/inherent_method_moved_must_use_added/old/Cargo.toml b/test_crates/inherent_method_moved_must_use_added/old/Cargo.toml new file mode 100644 index 00000000..4d6f75de --- /dev/null +++ b/test_crates/inherent_method_moved_must_use_added/old/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "inherent_method_moved_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/inherent_method_moved_must_use_added/old/src/lib.rs b/test_crates/inherent_method_moved_must_use_added/old/src/lib.rs new file mode 100644 index 00000000..397e0043 --- /dev/null +++ b/test_crates/inherent_method_moved_must_use_added/old/src/lib.rs @@ -0,0 +1,108 @@ +pub struct StructWithMovedProvidedMustUseMethods {} + +impl StructWithMovedProvidedMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + pub fn MethodToMovedProvidedMustUseMethod(&self) {} + + pub fn MethodToMovedProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes + // of the attribute, including deletion, should not be reported. + + #[must_use] + pub fn MustUseMethodToMovedProvidedMethod(&self) {} + + #[must_use] + pub fn MustUseMethodToMovedProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMovedProvidedMethod(&self) {} + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMovedProvidedMustUseMethod(&self) {} + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMovedProvidedMustUseMessageMethod(&self) {} +} + +pub trait TraitWithMovedProvidedMustUseMethods {} + + +pub struct StructWithMovedDeclaredMustUseMethods {} + +impl StructWithMovedDeclaredMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + pub fn MethodToMovedDeclaredMustUseMethod(&self) {} + + pub fn MethodToMovedDeclaredMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes + // of the attribute, including deletion, should not be reported. + + #[must_use] + pub fn MustUseMethodToMovedDeclaredMethod(&self) {} + + #[must_use] + pub fn MustUseMethodToMovedDeclaredMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMovedDeclaredMethod(&self) {} + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMovedDeclaredMustUseMethod(&self) {} + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMovedDeclaredMustUseMessageMethod(&self) {} +} + +pub trait TraitWithMovedDeclaredMustUseMethods {} + +// This struct is private and adding #[must_use] to it's methods, +// after moving them to a private trait, should NOT be reported. + +struct PrivateStructWithMovedMustUseMethods {} + +impl PrivateStructWithMovedMustUseMethods { + + pub fn PrivateStructMethodToMovedPrivateDeclaredMustUseMethod(&self) {} + + pub fn PrivateStructMethodToMovedPrivateProvidedMustUseMethod(&self) {} + + pub fn PrivateStructMethodToMovedPrivateOverrideMustUseMethod(&self) {} +} + +trait PrivateTraitWithMovedMustUseMethods {} + + +// Adding the #[must_use] attribute inside a trait's impl block +// does NOT generate a compiler lint when calling inner methods +// without using the return value. Thus it should NOT be reported. + +pub struct StructWithMovedImplMustUseMethods {} + +impl StructWithMovedImplMustUseMethods { + + pub fn MethodToMovedImplDeclaredMustUseMethod(&self) {} + + pub fn MethodToMovedImplOverrideMustUseMethod(&self) {} +} + +pub trait TraitWithMovedImplMustUseMethods {} diff --git a/test_crates/inherent_method_must_use_added/new/Cargo.toml b/test_crates/inherent_method_must_use_added/new/Cargo.toml new file mode 100644 index 00000000..6c98db59 --- /dev/null +++ b/test_crates/inherent_method_must_use_added/new/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "inherent_method_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/inherent_method_must_use_added/new/src/lib.rs b/test_crates/inherent_method_must_use_added/new/src/lib.rs new file mode 100644 index 00000000..834708c8 --- /dev/null +++ b/test_crates/inherent_method_must_use_added/new/src/lib.rs @@ -0,0 +1,73 @@ +pub struct StructWithMustUseMethods {} + +impl StructWithMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + #[must_use] + pub fn MethodToMustUseMethod(&self) {} + + #[must_use = "Foo"] + pub fn MethodToMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes of + // the attribute, including deletion, should not be reported. + + pub fn MustUseMethodToMethod(&self) {} + + #[must_use = "Foo"] + pub fn MustUseMethodToMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + pub fn MustUseMessageMethodToMethod(&self) {} + + #[must_use] + pub fn MustUseMessageMethodToMustUseMethod(&self) {} + + #[must_use = "Baz"] + pub fn MustUseMessageMethodToMustUseMessageMethod(&self) {} +} + + +// This public struct's inherent method did not have the #[must_use] attribute +// in the old version. Because the method is private, adding the attribute +// should NOT be reported. + +pub struct StructWithPrivateMustUseMethods {} + +impl StructWithPrivateMustUseMethods { + + #[must_use] + fn PrivateMethodToPrivateMustUseMethod(&self) {} +} + + +// This struct is private and adding #[must_use] to it's inherent methods +// should NOT be reported. + +struct PrivateStructWithMustUseMethods {} + +impl PrivateStructWithMustUseMethods { + + #[must_use] + fn PrivateStructMethodToPrivateStructMustUseMethod(&self) {} +} + + +// This struct and it's inherent method were added in the new version of the +// crate, together with the method's attribute. It should NOT be reported +// because adding a new struct is not a breaking change. + +pub struct NewStructWithMustUseMethods {} + +impl NewStructWithMustUseMethods { + + #[must_use] + pub fn NewStructMustUseMethod(&self) {} +} diff --git a/test_crates/inherent_method_must_use_added/old/Cargo.toml b/test_crates/inherent_method_must_use_added/old/Cargo.toml new file mode 100644 index 00000000..6c98db59 --- /dev/null +++ b/test_crates/inherent_method_must_use_added/old/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "inherent_method_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/inherent_method_must_use_added/old/src/lib.rs b/test_crates/inherent_method_must_use_added/old/src/lib.rs new file mode 100644 index 00000000..62525e4e --- /dev/null +++ b/test_crates/inherent_method_must_use_added/old/src/lib.rs @@ -0,0 +1,58 @@ +pub struct StructWithMustUseMethods {} + +impl StructWithMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + pub fn MethodToMustUseMethod(&self) {} + + pub fn MethodToMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes + // of the attribute, including deletion, should not be reported. + + #[must_use] + pub fn MustUseMethodToMethod(&self) {} + + #[must_use] + pub fn MustUseMethodToMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMethod(&self) {} + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMustUseMethod(&self) {} + + #[must_use = "Foo"] + pub fn MustUseMessageMethodToMustUseMessageMethod(&self) {} +} + + +// This public struct's inherent method did not have the #[must_use] attribute +// in the old version. Because the method is private, adding the attribute +// should NOT be reported. + +pub struct StructWithPrivateMustUseMethods {} + +impl StructWithPrivateMustUseMethods { + + fn PrivateMethodToPrivateMustUseMethod(&self) {} +} + + +// This struct is private and adding #[must_use] to it's inherent methods +// should NOT be reported. + +struct PrivateStructWithMustUseMethods {} + +impl PrivateStructWithMustUseMethods { + + fn PrivateStructMethodToPrivateStructMustUseMethod(&self) {} +} diff --git a/test_crates/struct_must_use_added/new/Cargo.toml b/test_crates/struct_must_use_added/new/Cargo.toml new file mode 100644 index 00000000..a2dd5d4c --- /dev/null +++ b/test_crates/struct_must_use_added/new/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "struct_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/struct_must_use_added/new/src/lib.rs b/test_crates/struct_must_use_added/new/src/lib.rs new file mode 100644 index 00000000..4dff93f2 --- /dev/null +++ b/test_crates/struct_must_use_added/new/src/lib.rs @@ -0,0 +1,62 @@ +// These structs did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +#[must_use] +pub struct StructToMustUseStruct { + bar: u64, +} + +#[must_use = "Foo"] +pub struct StructToMustUseMessageStruct { + bar: u64, +} + + +// These structs had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub struct MustUseStructToStruct { + bar: u64, +} + +#[must_use = "Foo"] +pub struct MustUseStructToMustUseMessageStruct { + bar: u64, +} + + +// These structs had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub struct MustUseMessageStructToStruct { + bar: u64, +} + +#[must_use] +pub struct MustUseMessageStructToMustUseStruct { + bar: u64, +} + +#[must_use = "Baz"] +pub struct MustUseMessageStructToMustUseMessageStruct { + bar: u64, +} + + +// This struct is private and should NOT be reported by this rule. + +#[must_use] +struct MustUsePrivateStruct { + bar: u64, +} + + +// This struct was added in the new version of the crate with it's attribute. +// It should NOT be reported by this rule because adding a new struct is not +// a breaking change. + +#[must_use] +pub struct MustUseNewStruct { + bar: u64, +} diff --git a/test_crates/struct_must_use_added/old/Cargo.toml b/test_crates/struct_must_use_added/old/Cargo.toml new file mode 100644 index 00000000..a2dd5d4c --- /dev/null +++ b/test_crates/struct_must_use_added/old/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "struct_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/struct_must_use_added/old/src/lib.rs b/test_crates/struct_must_use_added/old/src/lib.rs new file mode 100644 index 00000000..1a749ab0 --- /dev/null +++ b/test_crates/struct_must_use_added/old/src/lib.rs @@ -0,0 +1,51 @@ +// These structs did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +pub struct StructToMustUseStruct { + bar: u64, +} + +pub struct StructToMustUseMessageStruct { + bar: u64, +} + + +// These structs had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use] +pub struct MustUseStructToStruct { + bar: u64, +} + +#[must_use] +pub struct MustUseStructToMustUseMessageStruct { + bar: u64, +} + + +// These structs had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use = "Foo"] +pub struct MustUseMessageStructToStruct { + bar: u64, +} + +#[must_use = "Foo"] +pub struct MustUseMessageStructToMustUseStruct { + bar: u64, +} + +#[must_use = "Foo"] +pub struct MustUseMessageStructToMustUseMessageStruct { + bar: u64, +} + + +// This struct is private and should NOT be reported by this rule. + +struct MustUsePrivateStruct { + bar: u64, +} diff --git a/test_crates/trait_method_must_use_added/new/Cargo.toml b/test_crates/trait_method_must_use_added/new/Cargo.toml new file mode 100644 index 00000000..34afe366 --- /dev/null +++ b/test_crates/trait_method_must_use_added/new/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "trait_method_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/trait_method_must_use_added/new/src/lib.rs b/test_crates/trait_method_must_use_added/new/src/lib.rs new file mode 100644 index 00000000..738c5da1 --- /dev/null +++ b/test_crates/trait_method_must_use_added/new/src/lib.rs @@ -0,0 +1,95 @@ +pub trait TraitWithDeclaredMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + #[must_use] + fn DeclaredMethodToDeclaredMustUseMethod(&self); + + #[must_use = "Foo"] + fn DeclaredMethodToDeclaredMustUseMessageMethod(&self); + + + // These methods had the #[must_use] attribute in the old version. Changes of + // the attribute, including deletion, should not be reported. + + fn DeclaredMustUseMethodToDeclaredMethod(&self); + + #[must_use = "Foo"] + fn DeclaredMustUseMethodToDeclaredMustUseMessageMethod(&self); + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + fn DeclaredMustUseMessageMethodToDeclaredMethod(&self); + + #[must_use] + fn DeclaredMustUseMessageMethodToDeclaredMustUseMethod(&self); + + #[must_use = "Baz"] + fn DeclaredMustUseMessageMethodToDeclaredMustUseMessageMethod(&self); +} + + +pub trait TraitWithProvidedMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + #[must_use] + fn ProvidedMethodToProvidedMustUseMethod(&self) {} + + #[must_use = "Foo"] + fn ProvidedMethodToProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes of + // the attribute, including deletion, should not be reported. + + fn ProvidedMustUseMethodToProvidedMethod(&self) {} + + #[must_use = "Foo"] + fn ProvidedMustUseMethodToProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + fn ProvidedMustUseMessageMethodToProvidedMethod(&self) {} + + #[must_use] + fn ProvidedMustUseMessageMethodToProvidedMustUseMethod(&self) {} + + #[must_use = "Baz"] + fn ProvidedMustUseMessageMethodToProvidedMustUseMessageMethod(&self) {} +} + + +// This trait is private and adding #[must_use] to it's methods +// should NOT be reported. + +trait PrivateTraitWithMustUseMethods { + + #[must_use] + fn PrivateDeclaredMethodToPrivateDeclaredMustUseMethod(&self); + + #[must_use] + fn PrivateProvidedMethodToPrivateProvidedMustUseMethod(&self) {} +} + + +// This trait and it's methods were added in the new version of the crate, +// together with the method's attribute. It should NOT be reported because +// adding a new trait is not a breaking change. + +pub trait NewTraitWithMustUseMethods { + + #[must_use] + fn NewTraitWithDeclaredMustUseMethod(&self); + + #[must_use] + fn NewTraitWithProvidedMustUseMethod(&self) {} +} diff --git a/test_crates/trait_method_must_use_added/old/Cargo.toml b/test_crates/trait_method_must_use_added/old/Cargo.toml new file mode 100644 index 00000000..34afe366 --- /dev/null +++ b/test_crates/trait_method_must_use_added/old/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "trait_method_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/trait_method_must_use_added/old/src/lib.rs b/test_crates/trait_method_must_use_added/old/src/lib.rs new file mode 100644 index 00000000..5a60d5dd --- /dev/null +++ b/test_crates/trait_method_must_use_added/old/src/lib.rs @@ -0,0 +1,79 @@ +pub trait TraitWithDeclaredMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + fn DeclaredMethodToDeclaredMustUseMethod(&self); + + fn DeclaredMethodToDeclaredMustUseMessageMethod(&self); + + + // These methods had the #[must_use] attribute in the old version. Changes + // of the attribute, including deletion, should not be reported. + + #[must_use] + fn DeclaredMustUseMethodToDeclaredMethod(&self); + + #[must_use] + fn DeclaredMustUseMethodToDeclaredMustUseMessageMethod(&self); + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + #[must_use = "Foo"] + fn DeclaredMustUseMessageMethodToDeclaredMethod(&self); + + #[must_use = "Foo"] + fn DeclaredMustUseMessageMethodToDeclaredMustUseMethod(&self); + + #[must_use = "Foo"] + fn DeclaredMustUseMessageMethodToDeclaredMustUseMessageMethod(&self); +} + + +pub trait TraitWithProvidedMustUseMethods { + + // These methods did not have the #[must_use] attribute in the old version. + // Addition of the attribute should be reported. + + fn ProvidedMethodToProvidedMustUseMethod(&self) {} + + fn ProvidedMethodToProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. Changes + // of the attribute, including deletion, should not be reported. + + #[must_use] + fn ProvidedMustUseMethodToProvidedMethod(&self) {} + + #[must_use] + fn ProvidedMustUseMethodToProvidedMustUseMessageMethod(&self) {} + + + // These methods had the #[must_use] attribute in the old version. + // They also included the user-defined warning message. Changes of + // the attribute, including deletion, should not be reported. + + #[must_use = "Foo"] + fn ProvidedMustUseMessageMethodToProvidedMethod(&self) {} + + #[must_use = "Foo"] + fn ProvidedMustUseMessageMethodToProvidedMustUseMethod(&self) {} + + #[must_use = "Foo"] + fn ProvidedMustUseMessageMethodToProvidedMustUseMessageMethod(&self) {} +} + + +// This trait is private and adding #[must_use] to it's methods +// should NOT be reported. + +trait PrivateTraitWithMustUseMethods { + + fn PrivateDeclaredMethodToPrivateDeclaredMustUseMethod(&self); + + fn PrivateProvidedMethodToPrivateProvidedMustUseMethod(&self) {} +} diff --git a/test_crates/trait_must_use_added/new/Cargo.toml b/test_crates/trait_must_use_added/new/Cargo.toml new file mode 100644 index 00000000..5965321c --- /dev/null +++ b/test_crates/trait_must_use_added/new/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "trait_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/trait_must_use_added/new/src/lib.rs b/test_crates/trait_must_use_added/new/src/lib.rs new file mode 100644 index 00000000..c102410c --- /dev/null +++ b/test_crates/trait_must_use_added/new/src/lib.rs @@ -0,0 +1,44 @@ +// These traits did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +#[must_use] +pub trait TraitToMustUseTrait {} + +#[must_use = "Foo"] +pub trait TraitToMustUseMessageTrait {} + + +// These traits had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub trait MustUseTraitToTrait {} + +#[must_use = "Foo"] +pub trait MustUseTraitToMustUseMessageTrait {} + + +// These traits had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub trait MustUseMessageTraitToTrait {} + +#[must_use] +pub trait MustUseMessageTraitToMustUseTrait {} + +#[must_use = "Baz"] +pub trait MustUseMessageTraitToMustUseMessageTrait {} + + +// This trait is private and should NOT be reported by this rule. + +#[must_use] +trait MustUsePrivateTrait {} + + +// This trait was added in the new version of the crate with it's attribute. +// It should NOT be reported by this rule because adding a new trait is not +// a breaking change. + +#[must_use] +pub trait MustUseNewTrait {} diff --git a/test_crates/trait_must_use_added/old/Cargo.toml b/test_crates/trait_must_use_added/old/Cargo.toml new file mode 100644 index 00000000..5965321c --- /dev/null +++ b/test_crates/trait_must_use_added/old/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "trait_must_use_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/trait_must_use_added/old/src/lib.rs b/test_crates/trait_must_use_added/old/src/lib.rs new file mode 100644 index 00000000..d4660165 --- /dev/null +++ b/test_crates/trait_must_use_added/old/src/lib.rs @@ -0,0 +1,35 @@ +// These traits did not have the #[must_use] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +pub trait TraitToMustUseTrait {} + +pub trait TraitToMustUseMessageTrait {} + + +// These traits had the #[must_use] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use] +pub trait MustUseTraitToTrait {} + +#[must_use] +pub trait MustUseTraitToMustUseMessageTrait {} + + +// These traits had the #[must_use] attribute in the old version. +// They also included the user-defined warning message. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[must_use = "Foo"] +pub trait MustUseMessageTraitToTrait {} + +#[must_use = "Foo"] +pub trait MustUseMessageTraitToMustUseTrait {} + +#[must_use = "Foo"] +pub trait MustUseMessageTraitToMustUseMessageTrait {} + + +// This trait is private and should NOT be reported by this rule. + +trait MustUsePrivateTrait {} diff --git a/test_outputs/enum_must_use_added.output.ron b/test_outputs/enum_must_use_added.output.ron new file mode 100644 index 00000000..5a0d3ab2 --- /dev/null +++ b/test_outputs/enum_must_use_added.output.ron @@ -0,0 +1,26 @@ +{ + "./test_crates/enum_must_use_added/": [ + { + "name": String("EnumToMustUseEnum"), + "new_attr": String("#[must_use]"), + "path": List([ + String("enum_must_use_added"), + String("EnumToMustUseEnum"), + ]), + "span_begin_line": Uint64(5), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "name": String("EnumToMustUseMessageEnum"), + "new_attr": String("#[must_use = \"Foo\"]"), + "path": List([ + String("enum_must_use_added"), + String("EnumToMustUseMessageEnum"), + ]), + "span_begin_line": Uint64(10), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + ], +} diff --git a/test_outputs/function_must_use_added.output.ron b/test_outputs/function_must_use_added.output.ron new file mode 100644 index 00000000..dc871d7e --- /dev/null +++ b/test_outputs/function_must_use_added.output.ron @@ -0,0 +1,26 @@ +{ + "./test_crates/function_must_use_added/": [ + { + "name": String("FunctionToMustUseFunction"), + "new_attr": String("#[must_use]"), + "path": List([ + String("function_must_use_added"), + String("FunctionToMustUseFunction"), + ]), + "span_begin_line": Uint64(5), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "name": String("FunctionToMustUseMessageFunction"), + "new_attr": String("#[must_use = \"Foo\"]"), + "path": List([ + String("function_must_use_added"), + String("FunctionToMustUseMessageFunction"), + ]), + "span_begin_line": Uint64(8), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + ], +} diff --git a/test_outputs/inherent_method_must_use_added.output.ron b/test_outputs/inherent_method_must_use_added.output.ron new file mode 100644 index 00000000..86931109 --- /dev/null +++ b/test_outputs/inherent_method_must_use_added.output.ron @@ -0,0 +1,30 @@ +{ + "./test_crates/inherent_method_must_use_added/": [ + { + "method_name": String("MethodToMustUseMethod"), + "method_visibility": String("public"), + "name": String("StructWithMustUseMethods"), + "new_attr": String("#[must_use]"), + "path": List([ + String("inherent_method_must_use_added"), + String("StructWithMustUseMethods"), + ]), + "span_begin_line": Uint64(9), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "method_name": String("MethodToMustUseMessageMethod"), + "method_visibility": String("public"), + "name": String("StructWithMustUseMethods"), + "new_attr": String("#[must_use = \"Foo\"]"), + "path": List([ + String("inherent_method_must_use_added"), + String("StructWithMustUseMethods"), + ]), + "span_begin_line": Uint64(12), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + ], +} diff --git a/test_outputs/method_must_use_added.output.ron b/test_outputs/method_must_use_added.output.ron new file mode 100644 index 00000000..7f42b1cc --- /dev/null +++ b/test_outputs/method_must_use_added.output.ron @@ -0,0 +1,5 @@ +{ + "./test_crates/method_must_use_added/": [ + // TODO + ] +} diff --git a/test_outputs/struct_must_use_added.output.ron b/test_outputs/struct_must_use_added.output.ron new file mode 100644 index 00000000..575b353a --- /dev/null +++ b/test_outputs/struct_must_use_added.output.ron @@ -0,0 +1,26 @@ +{ + "./test_crates/struct_must_use_added/": [ + { + "name": String("StructToMustUseStruct"), + "new_attr": String("#[must_use]"), + "path": List([ + String("struct_must_use_added"), + String("StructToMustUseStruct"), + ]), + "span_begin_line": Uint64(5), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "name": String("StructToMustUseMessageStruct"), + "new_attr": String("#[must_use = \"Foo\"]"), + "path": List([ + String("struct_must_use_added"), + String("StructToMustUseMessageStruct"), + ]), + "span_begin_line": Uint64(10), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + ], +} diff --git a/test_outputs/trait_must_use_added.output.ron b/test_outputs/trait_must_use_added.output.ron new file mode 100644 index 00000000..8c0807e5 --- /dev/null +++ b/test_outputs/trait_must_use_added.output.ron @@ -0,0 +1,26 @@ +{ + "./test_crates/trait_must_use_added/": [ + { + "name": String("TraitToMustUseTrait"), + "new_attr": String("#[must_use]"), + "path": List([ + String("trait_must_use_added"), + String("TraitToMustUseTrait"), + ]), + "span_begin_line": Uint64(5), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "name": String("TraitToMustUseMessageTrait"), + "new_attr": String("#[must_use = \"Foo\"]"), + "path": List([ + String("trait_must_use_added"), + String("TraitToMustUseMessageTrait"), + ]), + "span_begin_line": Uint64(8), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + ], +}