From a26518c1a6cbc244c97e14b0fef688a1e41ecf9a Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Fri, 10 Feb 2023 22:16:43 +0100 Subject: [PATCH 1/9] Add lint for "deprecated" attribute on structs This was mostly done copying and adjusting code from the "must_use" attribute lint. --- src/lints/struct_deprecated_added.ron | 60 +++++++++++++++++++ src/query.rs | 1 + .../struct_deprecated_added/new/Cargo.toml | 7 +++ .../struct_deprecated_added/new/src/lib.rs | 59 ++++++++++++++++++ .../struct_deprecated_added/old/Cargo.toml | 7 +++ .../struct_deprecated_added/old/src/lib.rs | 48 +++++++++++++++ .../struct_deprecated_added.output.ron | 26 ++++++++ 7 files changed, 208 insertions(+) create mode 100644 src/lints/struct_deprecated_added.ron create mode 100644 test_crates/struct_deprecated_added/new/Cargo.toml create mode 100644 test_crates/struct_deprecated_added/new/src/lib.rs create mode 100644 test_crates/struct_deprecated_added/old/Cargo.toml create mode 100644 test_crates/struct_deprecated_added/old/src/lib.rs create mode 100644 test_outputs/struct_deprecated_added.output.ron diff --git a/src/lints/struct_deprecated_added.ron b/src/lints/struct_deprecated_added.ron new file mode 100644 index 00000000..20e74368 --- /dev/null +++ b/src/lints/struct_deprecated_added.ron @@ -0,0 +1,60 @@ +SemverQuery( + id: "struct_deprecated_added", + human_readable_name: "struct #[deprecated] added", + description: "A struct has been newly marked with #[deprecated].", + required_update: Minor, + reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"), + query: r#" + { + CrateDiff { + current { + item { + ... on Struct { + visibility_limit @filter(op: "=", value: ["$public"]) + name @output + + importable_path { + path @tag @output + } + + attribute { + new_attr: raw_attribute @output + content { + base @filter(op: "=", value: ["$deprecated"]) + } + } + + span_: span @optional { + filename @output + begin_line @output + } + } + } + } + baseline { + item { + ... on Struct { + visibility_limit @filter(op: "=", value: ["$public"]) @output + + importable_path { + path @filter(op: "=", value: ["%path"]) + } + + attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { + content { + base @filter(op: "=", value: ["$deprecated"]) + } + } + } + } + } + } + }"#, + arguments: { + "public": "public", + "deprecated": "deprecated", + "zero": 0, + }, + error_message: "A struct is now #[deprecated]. Downstream crates will get a compiler warning.", + per_result_error_template: Some("struct {{name}} in {{span_filename}}:{{span_begin_line}}"), +) diff --git a/src/query.rs b/src/query.rs index f7aa5b70..120e3fd3 100644 --- a/src/query.rs +++ b/src/query.rs @@ -476,4 +476,5 @@ add_lints!( tuple_struct_to_plain_struct, unit_struct_changed_kind, variant_marked_non_exhaustive, + struct_deprecated_added, ); diff --git a/test_crates/struct_deprecated_added/new/Cargo.toml b/test_crates/struct_deprecated_added/new/Cargo.toml new file mode 100644 index 00000000..41979e28 --- /dev/null +++ b/test_crates/struct_deprecated_added/new/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "struct_deprecated_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/struct_deprecated_added/new/src/lib.rs b/test_crates/struct_deprecated_added/new/src/lib.rs new file mode 100644 index 00000000..e79ad4bf --- /dev/null +++ b/test_crates/struct_deprecated_added/new/src/lib.rs @@ -0,0 +1,59 @@ +// These structs did not have the #[deprecated] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +#[deprecated] +pub struct StructToDeprecatedStruct { + bar: u64, +} + +#[deprecated = "Foo"] +pub struct StructToDeprecatedMessageStruct { + bar: u64, +} + +// These structs had the #[deprecated] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub struct DeprecatedStructToStruct { + bar: u64, +} + +#[deprecated = "Foo"] +pub struct DeprecatedStructToDeprecatedMessageStruct { + bar: u64, +} + +// These structs had the #[deprecated] 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 DeprecatedMessageStructToStruct { + bar: u64, +} + +#[deprecated] +pub struct DeprecatedMessageStructToDeprecatedStruct { + bar: u64, +} + +#[deprecated = "Baz"] +pub struct DeprecatedMessageStructToDeprecatedMessageStruct { + bar: u64, +} + +// This struct is private and should NOT be reported by this rule. + +#[deprecated] +struct DeprecatedPrivateStruct { + bar: u64, +} + +// This struct was added in the new version of the crate with its attribute. +// It should NOT be reported by this rule to avoid duplicate lints. +// It should be reported as a new pub type that is part of the crate's API. +// This might seem like a nonsensical test but is a valid edge case. + +#[deprecated] +pub struct DeprecatedNewStruct { + bar: u64, +} diff --git a/test_crates/struct_deprecated_added/old/Cargo.toml b/test_crates/struct_deprecated_added/old/Cargo.toml new file mode 100644 index 00000000..41979e28 --- /dev/null +++ b/test_crates/struct_deprecated_added/old/Cargo.toml @@ -0,0 +1,7 @@ +[package] +publish = false +name = "struct_deprecated_added" +version = "0.1.0" +edition = "2021" + +[dependencies] diff --git a/test_crates/struct_deprecated_added/old/src/lib.rs b/test_crates/struct_deprecated_added/old/src/lib.rs new file mode 100644 index 00000000..0123a51c --- /dev/null +++ b/test_crates/struct_deprecated_added/old/src/lib.rs @@ -0,0 +1,48 @@ +// These structs did not have the #[deprecated] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +pub struct StructToDeprecatedStruct { + bar: u64, +} + +pub struct StructToDeprecatedMessageStruct { + bar: u64, +} + +// These structs had the #[deprecated] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +#[deprecated] +pub struct DeprecatedStructToStruct { + bar: u64, +} + +#[deprecated] +pub struct DeprecatedStructToDeprecatedMessageStruct { + bar: u64, +} + +// These structs had the #[deprecated] 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. + +#[deprecated = "Foo"] +pub struct DeprecatedMessageStructToStruct { + bar: u64, +} + +#[deprecated = "Foo"] +pub struct DeprecatedMessageStructToDeprecatedStruct { + bar: u64, +} + +#[deprecated = "Foo"] +pub struct DeprecatedMessageStructToDeprecatedMessageStruct { + bar: u64, +} + +// This struct is private and should NOT be reported by this rule. + +struct DeprecatedPrivateStruct { + bar: u64, +} diff --git a/test_outputs/struct_deprecated_added.output.ron b/test_outputs/struct_deprecated_added.output.ron new file mode 100644 index 00000000..7ecf074b --- /dev/null +++ b/test_outputs/struct_deprecated_added.output.ron @@ -0,0 +1,26 @@ +{ + "./test_crates/struct_deprecated_added/": [ + { + "name": String("StructToDeprecatedStruct"), + "new_attr": String("#[deprecated]"), + "path": List([ + String("struct_deprecated_added"), + String("StructToDeprecatedStruct"), + ]), + "span_begin_line": Uint64(5), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "name": String("StructToDeprecatedMessageStruct"), + "new_attr": String("#[deprecated = \"Foo\"]"), + "path": List([ + String("struct_deprecated_added"), + String("StructToDeprecatedMessageStruct"), + ]), + "span_begin_line": Uint64(10), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + ] +} From 5bf166cda40b656b656d329ef486d31be22839e3 Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Sat, 11 Feb 2023 14:03:18 +0100 Subject: [PATCH 2/9] Generalize lint for "deprecated" struct attribute Now the same query also checks enums and unions. --- src/lints/struct_deprecated_added.ron | 6 ++++-- test_outputs/struct_deprecated_added.output.ron | 2 ++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lints/struct_deprecated_added.ron b/src/lints/struct_deprecated_added.ron index 20e74368..0e3bc666 100644 --- a/src/lints/struct_deprecated_added.ron +++ b/src/lints/struct_deprecated_added.ron @@ -9,9 +9,10 @@ SemverQuery( CrateDiff { current { item { - ... on Struct { + ... on ImplOwner { visibility_limit @filter(op: "=", value: ["$public"]) name @output + owner_type: __typename @tag @output importable_path { path @tag @output @@ -33,8 +34,9 @@ SemverQuery( } baseline { item { - ... on Struct { + ... on ImplOwner { visibility_limit @filter(op: "=", value: ["$public"]) @output + __typename @filter(op: "=", value: ["%owner_type"]) importable_path { path @filter(op: "=", value: ["%path"]) diff --git a/test_outputs/struct_deprecated_added.output.ron b/test_outputs/struct_deprecated_added.output.ron index 7ecf074b..f330d207 100644 --- a/test_outputs/struct_deprecated_added.output.ron +++ b/test_outputs/struct_deprecated_added.output.ron @@ -3,6 +3,7 @@ { "name": String("StructToDeprecatedStruct"), "new_attr": String("#[deprecated]"), + "owner_type": String("Struct"), "path": List([ String("struct_deprecated_added"), String("StructToDeprecatedStruct"), @@ -14,6 +15,7 @@ { "name": String("StructToDeprecatedMessageStruct"), "new_attr": String("#[deprecated = \"Foo\"]"), + "owner_type": String("Struct"), "path": List([ String("struct_deprecated_added"), String("StructToDeprecatedMessageStruct"), From d6180496a6a8ba1b6bf8b45e983ec7ca3ba1899c Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Sat, 11 Feb 2023 15:04:49 +0100 Subject: [PATCH 3/9] Rename struct_deprecated_added lint to its now more general use case --- ...dded.ron => enum_struct_union_deprecated_added.ron} | 10 +++++----- src/query.rs | 2 +- .../new/Cargo.toml | 2 +- .../new/src/lib.rs | 0 .../old/Cargo.toml | 2 +- .../old/src/lib.rs | 0 ...n => enum_struct_union_deprecated_added.output.ron} | 6 +++--- 7 files changed, 11 insertions(+), 11 deletions(-) rename src/lints/{struct_deprecated_added.ron => enum_struct_union_deprecated_added.ron} (81%) rename test_crates/{struct_deprecated_added => enum_struct_union_deprecated_added}/new/Cargo.toml (63%) rename test_crates/{struct_deprecated_added => enum_struct_union_deprecated_added}/new/src/lib.rs (100%) rename test_crates/{struct_deprecated_added => enum_struct_union_deprecated_added}/old/Cargo.toml (63%) rename test_crates/{struct_deprecated_added => enum_struct_union_deprecated_added}/old/src/lib.rs (100%) rename test_outputs/{struct_deprecated_added.output.ron => enum_struct_union_deprecated_added.output.ron} (82%) diff --git a/src/lints/struct_deprecated_added.ron b/src/lints/enum_struct_union_deprecated_added.ron similarity index 81% rename from src/lints/struct_deprecated_added.ron rename to src/lints/enum_struct_union_deprecated_added.ron index 0e3bc666..818ceabe 100644 --- a/src/lints/struct_deprecated_added.ron +++ b/src/lints/enum_struct_union_deprecated_added.ron @@ -1,7 +1,7 @@ SemverQuery( - id: "struct_deprecated_added", - human_readable_name: "struct #[deprecated] added", - description: "A struct has been newly marked with #[deprecated].", + id: "enum_struct_union_deprecated_added", + human_readable_name: "enum/struct/union #[deprecated] added", + description: "Either an enum, a struct or a union has been newly marked with #[deprecated].", required_update: Minor, reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"), query: r#" @@ -57,6 +57,6 @@ SemverQuery( "deprecated": "deprecated", "zero": 0, }, - error_message: "A struct is now #[deprecated]. Downstream crates will get a compiler warning.", - per_result_error_template: Some("struct {{name}} in {{span_filename}}:{{span_begin_line}}"), + error_message: "Either an enum, a struct or a union is now #[deprecated]. Downstream crates will get a compiler warning.", + per_result_error_template: Some("{{owner_type}} {{name}} in {{span_filename}}:{{span_begin_line}}"), ) diff --git a/src/query.rs b/src/query.rs index 120e3fd3..9ad54298 100644 --- a/src/query.rs +++ b/src/query.rs @@ -447,6 +447,7 @@ add_lints!( enum_repr_c_removed, enum_repr_int_changed, enum_repr_int_removed, + enum_struct_union_deprecated_added, enum_struct_variant_field_added, enum_struct_variant_field_missing, enum_variant_added, @@ -476,5 +477,4 @@ add_lints!( tuple_struct_to_plain_struct, unit_struct_changed_kind, variant_marked_non_exhaustive, - struct_deprecated_added, ); diff --git a/test_crates/struct_deprecated_added/new/Cargo.toml b/test_crates/enum_struct_union_deprecated_added/new/Cargo.toml similarity index 63% rename from test_crates/struct_deprecated_added/new/Cargo.toml rename to test_crates/enum_struct_union_deprecated_added/new/Cargo.toml index 41979e28..08f389ce 100644 --- a/test_crates/struct_deprecated_added/new/Cargo.toml +++ b/test_crates/enum_struct_union_deprecated_added/new/Cargo.toml @@ -1,6 +1,6 @@ [package] publish = false -name = "struct_deprecated_added" +name = "enum_struct_union_deprecated_added" version = "0.1.0" edition = "2021" diff --git a/test_crates/struct_deprecated_added/new/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs similarity index 100% rename from test_crates/struct_deprecated_added/new/src/lib.rs rename to test_crates/enum_struct_union_deprecated_added/new/src/lib.rs diff --git a/test_crates/struct_deprecated_added/old/Cargo.toml b/test_crates/enum_struct_union_deprecated_added/old/Cargo.toml similarity index 63% rename from test_crates/struct_deprecated_added/old/Cargo.toml rename to test_crates/enum_struct_union_deprecated_added/old/Cargo.toml index 41979e28..08f389ce 100644 --- a/test_crates/struct_deprecated_added/old/Cargo.toml +++ b/test_crates/enum_struct_union_deprecated_added/old/Cargo.toml @@ -1,6 +1,6 @@ [package] publish = false -name = "struct_deprecated_added" +name = "enum_struct_union_deprecated_added" version = "0.1.0" edition = "2021" diff --git a/test_crates/struct_deprecated_added/old/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs similarity index 100% rename from test_crates/struct_deprecated_added/old/src/lib.rs rename to test_crates/enum_struct_union_deprecated_added/old/src/lib.rs diff --git a/test_outputs/struct_deprecated_added.output.ron b/test_outputs/enum_struct_union_deprecated_added.output.ron similarity index 82% rename from test_outputs/struct_deprecated_added.output.ron rename to test_outputs/enum_struct_union_deprecated_added.output.ron index f330d207..f4babbc3 100644 --- a/test_outputs/struct_deprecated_added.output.ron +++ b/test_outputs/enum_struct_union_deprecated_added.output.ron @@ -1,11 +1,11 @@ { - "./test_crates/struct_deprecated_added/": [ + "./test_crates/enum_struct_union_deprecated_added/": [ { "name": String("StructToDeprecatedStruct"), "new_attr": String("#[deprecated]"), "owner_type": String("Struct"), "path": List([ - String("struct_deprecated_added"), + String("enum_struct_union_deprecated_added"), String("StructToDeprecatedStruct"), ]), "span_begin_line": Uint64(5), @@ -17,7 +17,7 @@ "new_attr": String("#[deprecated = \"Foo\"]"), "owner_type": String("Struct"), "path": List([ - String("struct_deprecated_added"), + String("enum_struct_union_deprecated_added"), String("StructToDeprecatedMessageStruct"), ]), "span_begin_line": Uint64(10), From a502c0dbbf3a8666e29da500adf6e8187ecc9460 Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Sat, 11 Feb 2023 19:57:54 +0100 Subject: [PATCH 4/9] Reduce comments, use more meaningful strings --- .../new/src/lib.rs | 4 ++-- .../old/src/lib.rs | 20 ++++++++----------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs index e79ad4bf..2c14c1f9 100644 --- a/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs +++ b/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs @@ -18,7 +18,7 @@ pub struct DeprecatedStructToStruct { bar: u64, } -#[deprecated = "Foo"] +#[deprecated = "This message was added"] pub struct DeprecatedStructToDeprecatedMessageStruct { bar: u64, } @@ -36,7 +36,7 @@ pub struct DeprecatedMessageStructToDeprecatedStruct { bar: u64, } -#[deprecated = "Baz"] +#[deprecated = "This message was changed"] pub struct DeprecatedMessageStructToDeprecatedMessageStruct { bar: u64, } diff --git a/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs index 0123a51c..a83e1c5f 100644 --- a/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs +++ b/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs @@ -1,5 +1,6 @@ -// These structs did not have the #[deprecated] attribute in the old version. -// Addition of the attribute should be reported by this rule. +// STRUCTS + +// Adding #[deprecated] to these structs should be reported. pub struct StructToDeprecatedStruct { bar: u64, @@ -9,8 +10,7 @@ pub struct StructToDeprecatedMessageStruct { bar: u64, } -// These structs had the #[deprecated] attribute in the old version. Changes of -// the attribute, including deletion, should NOT be reported by this rule. +// These structs already have the attribute and changes to the attribute will not be reported. #[deprecated] pub struct DeprecatedStructToStruct { @@ -22,26 +22,22 @@ pub struct DeprecatedStructToDeprecatedMessageStruct { bar: u64, } -// These structs had the #[deprecated] 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. - -#[deprecated = "Foo"] +#[deprecated = "This attribute will be deleted"] pub struct DeprecatedMessageStructToStruct { bar: u64, } -#[deprecated = "Foo"] +#[deprecated = "This message will be deleted"] pub struct DeprecatedMessageStructToDeprecatedStruct { bar: u64, } -#[deprecated = "Foo"] +#[deprecated = "This message will change"] pub struct DeprecatedMessageStructToDeprecatedMessageStruct { bar: u64, } -// This struct is private and should NOT be reported by this rule. +// This struct is private and should NOT be reported. struct DeprecatedPrivateStruct { bar: u64, From c4d52722b872235c654896599d2f5bb87882da14 Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Sat, 11 Feb 2023 20:41:28 +0100 Subject: [PATCH 5/9] Add tests for deprecated enums --- .../new/src/lib.rs | 63 ++++++++++++++++++- .../old/src/lib.rs | 47 +++++++++++++- ...m_struct_union_deprecated_added.output.ron | 30 ++++++++- 3 files changed, 135 insertions(+), 5 deletions(-) diff --git a/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs index 2c14c1f9..70a19bd0 100644 --- a/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs +++ b/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs @@ -1,3 +1,5 @@ +// STRUCTS + // These structs did not have the #[deprecated] attribute in the old version. // Addition of the attribute should be reported by this rule. @@ -6,7 +8,7 @@ pub struct StructToDeprecatedStruct { bar: u64, } -#[deprecated = "Foo"] +#[deprecated = "This attribute was added"] pub struct StructToDeprecatedMessageStruct { bar: u64, } @@ -57,3 +59,62 @@ struct DeprecatedPrivateStruct { pub struct DeprecatedNewStruct { bar: u64, } + +// ENUMS + +// These enums did not have the #[deprecated] attribute in the old version. +// Addition of the attribute should be reported. + +#[deprecated] +pub enum EnumToDeprecatedEnum { + First, +} + +#[deprecated = "This attribute was added"] +pub enum EnumToDeprecatedMessageEnum { + First, +} + +// These structs had the #[deprecated] 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 DeprecatedEnumToEnum { + First, +} + +#[deprecated = "This message was added"] +pub enum DeprecatedEnumToDeprecatedMessageEnum { + First, +} + +pub enum DeprecatedMessageEnumToEnum { + First, +} + +#[deprecated] +pub enum DeprecatedMessageEnumToDeprecatedEnum { + First, +} + +#[deprecated = "This message was changed"] +pub enum DeprecatedMessageEnumToDeprecatedMessageEnum { + First, +} + +// This enum is private and should NOT be reported. + +#[deprecated] +enum DeprecatedPrivateEnum { + First, +} + +// This struct was added in the new version of the crate with its attribute. +// It should NOT be reported by this rule to avoid duplicate lints. +// It should be reported as a new pub type that is part of the crate's API. +// This might seem like a nonsensical test but is a valid edge case. + +#[deprecated] +pub struct DeprecatedNewEnum { + bar: u64, +} diff --git a/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs index a83e1c5f..4835777c 100644 --- a/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs +++ b/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs @@ -10,7 +10,7 @@ pub struct StructToDeprecatedMessageStruct { bar: u64, } -// These structs already have the attribute and changes to the attribute will not be reported. +// These structs already have the attribute and changes to the attribute should not be reported. #[deprecated] pub struct DeprecatedStructToStruct { @@ -42,3 +42,48 @@ pub struct DeprecatedMessageStructToDeprecatedMessageStruct { struct DeprecatedPrivateStruct { bar: u64, } + +// ENUMS + +// Adding #[deprecated] to these enums should be reported. + +pub enum EnumToDeprecatedEnum { + First, +} + +pub enum EnumToDeprecatedMessageEnum { + First, +} + +// These enums already have the attribute and changes to the attribute should not be reported. + +#[deprecated] +pub enum DeprecatedEnumToEnum { + First, +} + +#[deprecated] +pub enum DeprecatedEnumToDeprecatedMessageEnum { + First, +} + +#[deprecated = "This attribute will be deleted"] +pub enum DeprecatedMessageEnumToEnum { + First, +} + +#[deprecated = "This message will be deleted"] +pub enum DeprecatedMessageEnumToDeprecatedEnum { + First, +} + +#[deprecated = "This message will change"] +pub enum DeprecatedMessageEnumToDeprecatedMessageEnum { + First, +} + +// This enum is private and should NOT be reported. + +enum DeprecatedPrivateEnum { + First, +} diff --git a/test_outputs/enum_struct_union_deprecated_added.output.ron b/test_outputs/enum_struct_union_deprecated_added.output.ron index f4babbc3..caa6a826 100644 --- a/test_outputs/enum_struct_union_deprecated_added.output.ron +++ b/test_outputs/enum_struct_union_deprecated_added.output.ron @@ -8,19 +8,43 @@ String("enum_struct_union_deprecated_added"), String("StructToDeprecatedStruct"), ]), - "span_begin_line": Uint64(5), + "span_begin_line": Uint64(7), "span_filename": String("src/lib.rs"), "visibility_limit": String("public"), }, { "name": String("StructToDeprecatedMessageStruct"), - "new_attr": String("#[deprecated = \"Foo\"]"), + "new_attr": String("#[deprecated = \"This attribute was added\"]"), "owner_type": String("Struct"), "path": List([ String("enum_struct_union_deprecated_added"), String("StructToDeprecatedMessageStruct"), ]), - "span_begin_line": Uint64(10), + "span_begin_line": Uint64(12), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "name": String("EnumToDeprecatedEnum"), + "new_attr": String("#[deprecated]"), + "owner_type": String("Enum"), + "path": List([ + String("enum_struct_union_deprecated_added"), + String("EnumToDeprecatedEnum"), + ]), + "span_begin_line": Uint64(69), + "span_filename": String("src/lib.rs"), + "visibility_limit": String("public"), + }, + { + "name": String("EnumToDeprecatedMessageEnum"), + "new_attr": String("#[deprecated = \"This attribute was added\"]"), + "owner_type": String("Enum"), + "path": List([ + String("enum_struct_union_deprecated_added"), + String("EnumToDeprecatedMessageEnum"), + ]), + "span_begin_line": Uint64(74), "span_filename": String("src/lib.rs"), "visibility_limit": String("public"), }, From a31e1b90587fcf163a4ab2792c233a88689d895a Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Sat, 11 Feb 2023 20:57:18 +0100 Subject: [PATCH 6/9] Add tests for deprecated unions Unions are not supported yet by the query engine, so the output file doesn't change. --- .../new/src/lib.rs | 63 ++++++++++++++++++- .../old/src/lib.rs | 45 +++++++++++++ 2 files changed, 106 insertions(+), 2 deletions(-) diff --git a/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs index 70a19bd0..2500202e 100644 --- a/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs +++ b/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs @@ -109,12 +109,71 @@ enum DeprecatedPrivateEnum { First, } -// This struct was added in the new version of the crate with its attribute. +// This enum was added in the new version of the crate with its attribute. +// It should NOT be reported by this rule to avoid duplicate lints. +// It should be reported as a new pub type that is part of the crate's API. +// This might seem like a nonsensical test but is a valid edge case. + +#[deprecated] +pub enum DeprecatedNewEnum { + First, +} + +// UNION + +// These unions did not have the #[deprecated] attribute in the old version. +// Addition of the attribute should be reported. + +#[deprecated] +pub union UnionToDeprecatedUnion { + bar: u64, +} + +#[deprecated = "This attribute was added"] +pub union UnionToDeprecatedMessageUnion { + bar: u64, +} + +// These structs had the #[deprecated] 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 union DeprecatedUnionToUnion { + bar: u64, +} + +#[deprecated = "This message was added"] +pub union DeprecatedUnionToDeprecatedMessageUnion { + bar: u64, +} + +pub union DeprecatedMessageUnionToUnion { + bar: u64, +} + +#[deprecated] +pub union DeprecatedMessageUnionToDeprecatedUnion { + bar: u64, +} + +#[deprecated = "This message was changed"] +pub union DeprecatedMessageUnionToDeprecatedMessageUnion { + bar: u64, +} + +// This union is private and should NOT be reported. + +#[deprecated] +union DeprecatedPrivateUnion { + bar: u64, +} + +// This union was added in the new version of the crate with its attribute. // It should NOT be reported by this rule to avoid duplicate lints. // It should be reported as a new pub type that is part of the crate's API. // This might seem like a nonsensical test but is a valid edge case. #[deprecated] -pub struct DeprecatedNewEnum { +pub union DeprecatedNewUnion { bar: u64, } diff --git a/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs b/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs index 4835777c..8bbbba3b 100644 --- a/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs +++ b/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs @@ -87,3 +87,48 @@ pub enum DeprecatedMessageEnumToDeprecatedMessageEnum { enum DeprecatedPrivateEnum { First, } + +// UNIONS + +// Adding #[deprecated] to these unions should be reported. + +pub union UnionToDeprecatedUnion { + bar: u64, +} + +pub union UnionToDeprecatedMessageUnion { + bar: u64, +} + +// These unions already have the attribute and changes to the attribute should not be reported. + +#[deprecated] +pub union DeprecatedUnionToUnion { + bar: u64, +} + +#[deprecated] +pub union DeprecatedUnionToDeprecatedMessageUnion { + bar: u64, +} + +#[deprecated = "This attribute will be deleted"] +pub union DeprecatedMessageUnionToUnion { + bar: u64, +} + +#[deprecated = "This message will be deleted"] +pub union DeprecatedMessageUnionToDeprecatedUnion { + bar: u64, +} + +#[deprecated = "This message will change"] +pub union DeprecatedMessageUnionToDeprecatedMessageUnion { + bar: u64, +} + +// This union is private and should NOT be reported. + +union DeprecatedPrivateUnion { + bar: u64, +} From cbc4aa67de5a2d6760cd875d3a6df93c19e79280 Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Sun, 12 Feb 2023 11:17:59 +0100 Subject: [PATCH 7/9] Simplify deprecated lint name --- ...deprecated_added.ron => type_marked_deprecated.ron} | 8 ++++---- src/query.rs | 2 +- .../new/Cargo.toml | 2 +- .../new/src/lib.rs | 0 .../old/Cargo.toml | 2 +- .../old/src/lib.rs | 0 ...ed.output.ron => type_marked_deprecated.output.ron} | 10 +++++----- 7 files changed, 12 insertions(+), 12 deletions(-) rename src/lints/{enum_struct_union_deprecated_added.ron => type_marked_deprecated.ron} (85%) rename test_crates/{enum_struct_union_deprecated_added => type_marked_deprecated}/new/Cargo.toml (63%) rename test_crates/{enum_struct_union_deprecated_added => type_marked_deprecated}/new/src/lib.rs (100%) rename test_crates/{enum_struct_union_deprecated_added => type_marked_deprecated}/old/Cargo.toml (63%) rename test_crates/{enum_struct_union_deprecated_added => type_marked_deprecated}/old/src/lib.rs (100%) rename test_outputs/{enum_struct_union_deprecated_added.output.ron => type_marked_deprecated.output.ron} (84%) diff --git a/src/lints/enum_struct_union_deprecated_added.ron b/src/lints/type_marked_deprecated.ron similarity index 85% rename from src/lints/enum_struct_union_deprecated_added.ron rename to src/lints/type_marked_deprecated.ron index 818ceabe..d66234ac 100644 --- a/src/lints/enum_struct_union_deprecated_added.ron +++ b/src/lints/type_marked_deprecated.ron @@ -1,7 +1,7 @@ SemverQuery( - id: "enum_struct_union_deprecated_added", - human_readable_name: "enum/struct/union #[deprecated] added", - description: "Either an enum, a struct or a union has been newly marked with #[deprecated].", + id: "type_marked_deprecated", + human_readable_name: "#[deprecated] added on type", + description: "A type has been newly marked with #[deprecated].", required_update: Minor, reference_link: Some("https://doc.rust-lang.org/reference/attributes/diagnostics.html#the-deprecated-attribute"), query: r#" @@ -57,6 +57,6 @@ SemverQuery( "deprecated": "deprecated", "zero": 0, }, - error_message: "Either an enum, a struct or a union is now #[deprecated]. Downstream crates will get a compiler warning.", + error_message: "A type is now #[deprecated]. Downstream crates will get a compiler warning when using this type.", per_result_error_template: Some("{{owner_type}} {{name}} in {{span_filename}}:{{span_begin_line}}"), ) diff --git a/src/query.rs b/src/query.rs index 9ad54298..d02e9a61 100644 --- a/src/query.rs +++ b/src/query.rs @@ -447,7 +447,6 @@ add_lints!( enum_repr_c_removed, enum_repr_int_changed, enum_repr_int_removed, - enum_struct_union_deprecated_added, enum_struct_variant_field_added, enum_struct_variant_field_missing, enum_variant_added, @@ -475,6 +474,7 @@ add_lints!( trait_unsafe_added, trait_unsafe_removed, tuple_struct_to_plain_struct, + type_marked_deprecated, unit_struct_changed_kind, variant_marked_non_exhaustive, ); diff --git a/test_crates/enum_struct_union_deprecated_added/new/Cargo.toml b/test_crates/type_marked_deprecated/new/Cargo.toml similarity index 63% rename from test_crates/enum_struct_union_deprecated_added/new/Cargo.toml rename to test_crates/type_marked_deprecated/new/Cargo.toml index 08f389ce..bdcf17f0 100644 --- a/test_crates/enum_struct_union_deprecated_added/new/Cargo.toml +++ b/test_crates/type_marked_deprecated/new/Cargo.toml @@ -1,6 +1,6 @@ [package] publish = false -name = "enum_struct_union_deprecated_added" +name = "type_marked_deprecated" version = "0.1.0" edition = "2021" diff --git a/test_crates/enum_struct_union_deprecated_added/new/src/lib.rs b/test_crates/type_marked_deprecated/new/src/lib.rs similarity index 100% rename from test_crates/enum_struct_union_deprecated_added/new/src/lib.rs rename to test_crates/type_marked_deprecated/new/src/lib.rs diff --git a/test_crates/enum_struct_union_deprecated_added/old/Cargo.toml b/test_crates/type_marked_deprecated/old/Cargo.toml similarity index 63% rename from test_crates/enum_struct_union_deprecated_added/old/Cargo.toml rename to test_crates/type_marked_deprecated/old/Cargo.toml index 08f389ce..bdcf17f0 100644 --- a/test_crates/enum_struct_union_deprecated_added/old/Cargo.toml +++ b/test_crates/type_marked_deprecated/old/Cargo.toml @@ -1,6 +1,6 @@ [package] publish = false -name = "enum_struct_union_deprecated_added" +name = "type_marked_deprecated" version = "0.1.0" edition = "2021" diff --git a/test_crates/enum_struct_union_deprecated_added/old/src/lib.rs b/test_crates/type_marked_deprecated/old/src/lib.rs similarity index 100% rename from test_crates/enum_struct_union_deprecated_added/old/src/lib.rs rename to test_crates/type_marked_deprecated/old/src/lib.rs diff --git a/test_outputs/enum_struct_union_deprecated_added.output.ron b/test_outputs/type_marked_deprecated.output.ron similarity index 84% rename from test_outputs/enum_struct_union_deprecated_added.output.ron rename to test_outputs/type_marked_deprecated.output.ron index caa6a826..396fc4db 100644 --- a/test_outputs/enum_struct_union_deprecated_added.output.ron +++ b/test_outputs/type_marked_deprecated.output.ron @@ -1,11 +1,11 @@ { - "./test_crates/enum_struct_union_deprecated_added/": [ + "./test_crates/type_marked_deprecated/": [ { "name": String("StructToDeprecatedStruct"), "new_attr": String("#[deprecated]"), "owner_type": String("Struct"), "path": List([ - String("enum_struct_union_deprecated_added"), + String("type_marked_deprecated"), String("StructToDeprecatedStruct"), ]), "span_begin_line": Uint64(7), @@ -17,7 +17,7 @@ "new_attr": String("#[deprecated = \"This attribute was added\"]"), "owner_type": String("Struct"), "path": List([ - String("enum_struct_union_deprecated_added"), + String("type_marked_deprecated"), String("StructToDeprecatedMessageStruct"), ]), "span_begin_line": Uint64(12), @@ -29,7 +29,7 @@ "new_attr": String("#[deprecated]"), "owner_type": String("Enum"), "path": List([ - String("enum_struct_union_deprecated_added"), + String("type_marked_deprecated"), String("EnumToDeprecatedEnum"), ]), "span_begin_line": Uint64(69), @@ -41,7 +41,7 @@ "new_attr": String("#[deprecated = \"This attribute was added\"]"), "owner_type": String("Enum"), "path": List([ - String("enum_struct_union_deprecated_added"), + String("type_marked_deprecated"), String("EnumToDeprecatedMessageEnum"), ]), "span_begin_line": Uint64(74), From b96739387e1092c186200d114210e7c849e58d94 Mon Sep 17 00:00:00 2001 From: Said Aroua Date: Sun, 12 Feb 2023 11:56:09 +0100 Subject: [PATCH 8/9] Reorganize deprecated tests --- .../type_marked_deprecated/new/src/enums.rs | 57 ++++++ .../type_marked_deprecated/new/src/lib.rs | 182 +----------------- .../type_marked_deprecated/new/src/structs.rs | 59 ++++++ .../type_marked_deprecated/new/src/unions.rs | 56 ++++++ .../type_marked_deprecated/old/src/enums.rs | 43 +++++ .../type_marked_deprecated/old/src/lib.rs | 137 +------------ .../type_marked_deprecated/old/src/structs.rs | 43 +++++ .../type_marked_deprecated/old/src/unions.rs | 42 ++++ .../type_marked_deprecated.output.ron | 44 +++-- 9 files changed, 330 insertions(+), 333 deletions(-) create mode 100644 test_crates/type_marked_deprecated/new/src/enums.rs create mode 100644 test_crates/type_marked_deprecated/new/src/structs.rs create mode 100644 test_crates/type_marked_deprecated/new/src/unions.rs create mode 100644 test_crates/type_marked_deprecated/old/src/enums.rs create mode 100644 test_crates/type_marked_deprecated/old/src/structs.rs create mode 100644 test_crates/type_marked_deprecated/old/src/unions.rs diff --git a/test_crates/type_marked_deprecated/new/src/enums.rs b/test_crates/type_marked_deprecated/new/src/enums.rs new file mode 100644 index 00000000..2261b89c --- /dev/null +++ b/test_crates/type_marked_deprecated/new/src/enums.rs @@ -0,0 +1,57 @@ +// These enums did not have the #[deprecated] attribute in the old version. +// Addition of the attribute should be reported. + +#[deprecated] +pub enum EnumToDeprecatedEnum { + First, +} + +#[deprecated = "This attribute was added"] +pub enum EnumToDeprecatedMessageEnum { + First, +} + +// These structs had the #[deprecated] 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 DeprecatedEnumToEnum { + First, +} + +#[deprecated = "This message was added"] +pub enum DeprecatedEnumToDeprecatedMessageEnum { + First, +} + +pub enum DeprecatedMessageEnumToEnum { + First, +} + +#[deprecated] +pub enum DeprecatedMessageEnumToDeprecatedEnum { + First, +} + +#[deprecated = "This message was changed"] +pub enum DeprecatedMessageEnumToDeprecatedMessageEnum { + First, +} + +// This enum is private and should NOT be reported. + +#[deprecated] +enum DeprecatedPrivateEnum { + First, +} + +// This enum was added in the new version of the crate with its attribute. +// It should NOT be reported by this rule to avoid duplicate lints. +// It should be reported as a new pub type that is part of the crate's API. +// This might seem like a nonsensical test but is a valid edge case. + +#[deprecated] +pub enum DeprecatedNewEnum { + First, +} + diff --git a/test_crates/type_marked_deprecated/new/src/lib.rs b/test_crates/type_marked_deprecated/new/src/lib.rs index 2500202e..8a40ae7e 100644 --- a/test_crates/type_marked_deprecated/new/src/lib.rs +++ b/test_crates/type_marked_deprecated/new/src/lib.rs @@ -1,179 +1,3 @@ -// STRUCTS - -// These structs did not have the #[deprecated] attribute in the old version. -// Addition of the attribute should be reported by this rule. - -#[deprecated] -pub struct StructToDeprecatedStruct { - bar: u64, -} - -#[deprecated = "This attribute was added"] -pub struct StructToDeprecatedMessageStruct { - bar: u64, -} - -// These structs had the #[deprecated] attribute in the old version. Changes of -// the attribute, including deletion, should NOT be reported by this rule. - -pub struct DeprecatedStructToStruct { - bar: u64, -} - -#[deprecated = "This message was added"] -pub struct DeprecatedStructToDeprecatedMessageStruct { - bar: u64, -} - -// These structs had the #[deprecated] 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 DeprecatedMessageStructToStruct { - bar: u64, -} - -#[deprecated] -pub struct DeprecatedMessageStructToDeprecatedStruct { - bar: u64, -} - -#[deprecated = "This message was changed"] -pub struct DeprecatedMessageStructToDeprecatedMessageStruct { - bar: u64, -} - -// This struct is private and should NOT be reported by this rule. - -#[deprecated] -struct DeprecatedPrivateStruct { - bar: u64, -} - -// This struct was added in the new version of the crate with its attribute. -// It should NOT be reported by this rule to avoid duplicate lints. -// It should be reported as a new pub type that is part of the crate's API. -// This might seem like a nonsensical test but is a valid edge case. - -#[deprecated] -pub struct DeprecatedNewStruct { - bar: u64, -} - -// ENUMS - -// These enums did not have the #[deprecated] attribute in the old version. -// Addition of the attribute should be reported. - -#[deprecated] -pub enum EnumToDeprecatedEnum { - First, -} - -#[deprecated = "This attribute was added"] -pub enum EnumToDeprecatedMessageEnum { - First, -} - -// These structs had the #[deprecated] 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 DeprecatedEnumToEnum { - First, -} - -#[deprecated = "This message was added"] -pub enum DeprecatedEnumToDeprecatedMessageEnum { - First, -} - -pub enum DeprecatedMessageEnumToEnum { - First, -} - -#[deprecated] -pub enum DeprecatedMessageEnumToDeprecatedEnum { - First, -} - -#[deprecated = "This message was changed"] -pub enum DeprecatedMessageEnumToDeprecatedMessageEnum { - First, -} - -// This enum is private and should NOT be reported. - -#[deprecated] -enum DeprecatedPrivateEnum { - First, -} - -// This enum was added in the new version of the crate with its attribute. -// It should NOT be reported by this rule to avoid duplicate lints. -// It should be reported as a new pub type that is part of the crate's API. -// This might seem like a nonsensical test but is a valid edge case. - -#[deprecated] -pub enum DeprecatedNewEnum { - First, -} - -// UNION - -// These unions did not have the #[deprecated] attribute in the old version. -// Addition of the attribute should be reported. - -#[deprecated] -pub union UnionToDeprecatedUnion { - bar: u64, -} - -#[deprecated = "This attribute was added"] -pub union UnionToDeprecatedMessageUnion { - bar: u64, -} - -// These structs had the #[deprecated] 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 union DeprecatedUnionToUnion { - bar: u64, -} - -#[deprecated = "This message was added"] -pub union DeprecatedUnionToDeprecatedMessageUnion { - bar: u64, -} - -pub union DeprecatedMessageUnionToUnion { - bar: u64, -} - -#[deprecated] -pub union DeprecatedMessageUnionToDeprecatedUnion { - bar: u64, -} - -#[deprecated = "This message was changed"] -pub union DeprecatedMessageUnionToDeprecatedMessageUnion { - bar: u64, -} - -// This union is private and should NOT be reported. - -#[deprecated] -union DeprecatedPrivateUnion { - bar: u64, -} - -// This union was added in the new version of the crate with its attribute. -// It should NOT be reported by this rule to avoid duplicate lints. -// It should be reported as a new pub type that is part of the crate's API. -// This might seem like a nonsensical test but is a valid edge case. - -#[deprecated] -pub union DeprecatedNewUnion { - bar: u64, -} +pub mod enums; +pub mod structs; +pub mod unions; diff --git a/test_crates/type_marked_deprecated/new/src/structs.rs b/test_crates/type_marked_deprecated/new/src/structs.rs new file mode 100644 index 00000000..1c3f4231 --- /dev/null +++ b/test_crates/type_marked_deprecated/new/src/structs.rs @@ -0,0 +1,59 @@ +// These structs did not have the #[deprecated] attribute in the old version. +// Addition of the attribute should be reported by this rule. + +#[deprecated] +pub struct StructToDeprecatedStruct { + bar: u64, +} + +#[deprecated = "This attribute was added"] +pub struct StructToDeprecatedMessageStruct { + bar: u64, +} + +// These structs had the #[deprecated] attribute in the old version. Changes of +// the attribute, including deletion, should NOT be reported by this rule. + +pub struct DeprecatedStructToStruct { + bar: u64, +} + +#[deprecated = "This message was added"] +pub struct DeprecatedStructToDeprecatedMessageStruct { + bar: u64, +} + +// These structs had the #[deprecated] 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 DeprecatedMessageStructToStruct { + bar: u64, +} + +#[deprecated] +pub struct DeprecatedMessageStructToDeprecatedStruct { + bar: u64, +} + +#[deprecated = "This message was changed"] +pub struct DeprecatedMessageStructToDeprecatedMessageStruct { + bar: u64, +} + +// This struct is private and should NOT be reported by this rule. + +#[deprecated] +struct DeprecatedPrivateStruct { + bar: u64, +} + +// This struct was added in the new version of the crate with its attribute. +// It should NOT be reported by this rule to avoid duplicate lints. +// It should be reported as a new pub type that is part of the crate's API. +// This might seem like a nonsensical test but is a valid edge case. + +#[deprecated] +pub struct DeprecatedNewStruct { + bar: u64, +} diff --git a/test_crates/type_marked_deprecated/new/src/unions.rs b/test_crates/type_marked_deprecated/new/src/unions.rs new file mode 100644 index 00000000..dc3cf4e0 --- /dev/null +++ b/test_crates/type_marked_deprecated/new/src/unions.rs @@ -0,0 +1,56 @@ +// These unions did not have the #[deprecated] attribute in the old version. +// Addition of the attribute should be reported. + +#[deprecated] +pub union UnionToDeprecatedUnion { + bar: u64, +} + +#[deprecated = "This attribute was added"] +pub union UnionToDeprecatedMessageUnion { + bar: u64, +} + +// These structs had the #[deprecated] 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 union DeprecatedUnionToUnion { + bar: u64, +} + +#[deprecated = "This message was added"] +pub union DeprecatedUnionToDeprecatedMessageUnion { + bar: u64, +} + +pub union DeprecatedMessageUnionToUnion { + bar: u64, +} + +#[deprecated] +pub union DeprecatedMessageUnionToDeprecatedUnion { + bar: u64, +} + +#[deprecated = "This message was changed"] +pub union DeprecatedMessageUnionToDeprecatedMessageUnion { + bar: u64, +} + +// This union is private and should NOT be reported. + +#[deprecated] +union DeprecatedPrivateUnion { + bar: u64, +} + +// This union was added in the new version of the crate with its attribute. +// It should NOT be reported by this rule to avoid duplicate lints. +// It should be reported as a new pub type that is part of the crate's API. +// This might seem like a nonsensical test but is a valid edge case. + +#[deprecated] +pub union DeprecatedNewUnion { + bar: u64, +} \ No newline at end of file diff --git a/test_crates/type_marked_deprecated/old/src/enums.rs b/test_crates/type_marked_deprecated/old/src/enums.rs new file mode 100644 index 00000000..cc9297cd --- /dev/null +++ b/test_crates/type_marked_deprecated/old/src/enums.rs @@ -0,0 +1,43 @@ +// Adding #[deprecated] to these enums should be reported. + +pub enum EnumToDeprecatedEnum { + First, +} + +pub enum EnumToDeprecatedMessageEnum { + First, +} + +// These enums already have the attribute and changes to the attribute should not be reported. + +#[deprecated] +pub enum DeprecatedEnumToEnum { + First, +} + +#[deprecated] +pub enum DeprecatedEnumToDeprecatedMessageEnum { + First, +} + +#[deprecated = "This attribute will be deleted"] +pub enum DeprecatedMessageEnumToEnum { + First, +} + +#[deprecated = "This message will be deleted"] +pub enum DeprecatedMessageEnumToDeprecatedEnum { + First, +} + +#[deprecated = "This message will change"] +pub enum DeprecatedMessageEnumToDeprecatedMessageEnum { + First, +} + +// This enum is private and should NOT be reported. + +enum DeprecatedPrivateEnum { + First, +} + diff --git a/test_crates/type_marked_deprecated/old/src/lib.rs b/test_crates/type_marked_deprecated/old/src/lib.rs index 8bbbba3b..8a40ae7e 100644 --- a/test_crates/type_marked_deprecated/old/src/lib.rs +++ b/test_crates/type_marked_deprecated/old/src/lib.rs @@ -1,134 +1,3 @@ -// STRUCTS - -// Adding #[deprecated] to these structs should be reported. - -pub struct StructToDeprecatedStruct { - bar: u64, -} - -pub struct StructToDeprecatedMessageStruct { - bar: u64, -} - -// These structs already have the attribute and changes to the attribute should not be reported. - -#[deprecated] -pub struct DeprecatedStructToStruct { - bar: u64, -} - -#[deprecated] -pub struct DeprecatedStructToDeprecatedMessageStruct { - bar: u64, -} - -#[deprecated = "This attribute will be deleted"] -pub struct DeprecatedMessageStructToStruct { - bar: u64, -} - -#[deprecated = "This message will be deleted"] -pub struct DeprecatedMessageStructToDeprecatedStruct { - bar: u64, -} - -#[deprecated = "This message will change"] -pub struct DeprecatedMessageStructToDeprecatedMessageStruct { - bar: u64, -} - -// This struct is private and should NOT be reported. - -struct DeprecatedPrivateStruct { - bar: u64, -} - -// ENUMS - -// Adding #[deprecated] to these enums should be reported. - -pub enum EnumToDeprecatedEnum { - First, -} - -pub enum EnumToDeprecatedMessageEnum { - First, -} - -// These enums already have the attribute and changes to the attribute should not be reported. - -#[deprecated] -pub enum DeprecatedEnumToEnum { - First, -} - -#[deprecated] -pub enum DeprecatedEnumToDeprecatedMessageEnum { - First, -} - -#[deprecated = "This attribute will be deleted"] -pub enum DeprecatedMessageEnumToEnum { - First, -} - -#[deprecated = "This message will be deleted"] -pub enum DeprecatedMessageEnumToDeprecatedEnum { - First, -} - -#[deprecated = "This message will change"] -pub enum DeprecatedMessageEnumToDeprecatedMessageEnum { - First, -} - -// This enum is private and should NOT be reported. - -enum DeprecatedPrivateEnum { - First, -} - -// UNIONS - -// Adding #[deprecated] to these unions should be reported. - -pub union UnionToDeprecatedUnion { - bar: u64, -} - -pub union UnionToDeprecatedMessageUnion { - bar: u64, -} - -// These unions already have the attribute and changes to the attribute should not be reported. - -#[deprecated] -pub union DeprecatedUnionToUnion { - bar: u64, -} - -#[deprecated] -pub union DeprecatedUnionToDeprecatedMessageUnion { - bar: u64, -} - -#[deprecated = "This attribute will be deleted"] -pub union DeprecatedMessageUnionToUnion { - bar: u64, -} - -#[deprecated = "This message will be deleted"] -pub union DeprecatedMessageUnionToDeprecatedUnion { - bar: u64, -} - -#[deprecated = "This message will change"] -pub union DeprecatedMessageUnionToDeprecatedMessageUnion { - bar: u64, -} - -// This union is private and should NOT be reported. - -union DeprecatedPrivateUnion { - bar: u64, -} +pub mod enums; +pub mod structs; +pub mod unions; diff --git a/test_crates/type_marked_deprecated/old/src/structs.rs b/test_crates/type_marked_deprecated/old/src/structs.rs new file mode 100644 index 00000000..4a8a5cd9 --- /dev/null +++ b/test_crates/type_marked_deprecated/old/src/structs.rs @@ -0,0 +1,43 @@ +// Adding #[deprecated] to these structs should be reported. + +pub struct StructToDeprecatedStruct { + bar: u64, +} + +pub struct StructToDeprecatedMessageStruct { + bar: u64, +} + +// These structs already have the attribute and changes to the attribute should not be reported. + +#[deprecated] +pub struct DeprecatedStructToStruct { + bar: u64, +} + +#[deprecated] +pub struct DeprecatedStructToDeprecatedMessageStruct { + bar: u64, +} + +#[deprecated = "This attribute will be deleted"] +pub struct DeprecatedMessageStructToStruct { + bar: u64, +} + +#[deprecated = "This message will be deleted"] +pub struct DeprecatedMessageStructToDeprecatedStruct { + bar: u64, +} + +#[deprecated = "This message will change"] +pub struct DeprecatedMessageStructToDeprecatedMessageStruct { + bar: u64, +} + +// This struct is private and should NOT be reported. + +struct DeprecatedPrivateStruct { + bar: u64, +} + diff --git a/test_crates/type_marked_deprecated/old/src/unions.rs b/test_crates/type_marked_deprecated/old/src/unions.rs new file mode 100644 index 00000000..21b8514e --- /dev/null +++ b/test_crates/type_marked_deprecated/old/src/unions.rs @@ -0,0 +1,42 @@ +// Adding #[deprecated] to these unions should be reported. + +pub union UnionToDeprecatedUnion { + bar: u64, +} + +pub union UnionToDeprecatedMessageUnion { + bar: u64, +} + +// These unions already have the attribute and changes to the attribute should not be reported. + +#[deprecated] +pub union DeprecatedUnionToUnion { + bar: u64, +} + +#[deprecated] +pub union DeprecatedUnionToDeprecatedMessageUnion { + bar: u64, +} + +#[deprecated = "This attribute will be deleted"] +pub union DeprecatedMessageUnionToUnion { + bar: u64, +} + +#[deprecated = "This message will be deleted"] +pub union DeprecatedMessageUnionToDeprecatedUnion { + bar: u64, +} + +#[deprecated = "This message will change"] +pub union DeprecatedMessageUnionToDeprecatedMessageUnion { + bar: u64, +} + +// This union is private and should NOT be reported. + +union DeprecatedPrivateUnion { + bar: u64, +} \ No newline at end of file diff --git a/test_outputs/type_marked_deprecated.output.ron b/test_outputs/type_marked_deprecated.output.ron index 396fc4db..db574343 100644 --- a/test_outputs/type_marked_deprecated.output.ron +++ b/test_outputs/type_marked_deprecated.output.ron @@ -1,51 +1,55 @@ { "./test_crates/type_marked_deprecated/": [ { - "name": String("StructToDeprecatedStruct"), + "name": String("EnumToDeprecatedEnum"), "new_attr": String("#[deprecated]"), - "owner_type": String("Struct"), + "owner_type": String("Enum"), "path": List([ String("type_marked_deprecated"), - String("StructToDeprecatedStruct"), + String("enums"), + String("EnumToDeprecatedEnum"), ]), - "span_begin_line": Uint64(7), - "span_filename": String("src/lib.rs"), + "span_begin_line": Uint64(5), + "span_filename": String("src/enums.rs"), "visibility_limit": String("public"), }, { - "name": String("StructToDeprecatedMessageStruct"), + "name": String("EnumToDeprecatedMessageEnum"), "new_attr": String("#[deprecated = \"This attribute was added\"]"), - "owner_type": String("Struct"), + "owner_type": String("Enum"), "path": List([ String("type_marked_deprecated"), - String("StructToDeprecatedMessageStruct"), + String("enums"), + String("EnumToDeprecatedMessageEnum"), ]), - "span_begin_line": Uint64(12), - "span_filename": String("src/lib.rs"), + "span_begin_line": Uint64(10), + "span_filename": String("src/enums.rs"), "visibility_limit": String("public"), }, { - "name": String("EnumToDeprecatedEnum"), + "name": String("StructToDeprecatedStruct"), "new_attr": String("#[deprecated]"), - "owner_type": String("Enum"), + "owner_type": String("Struct"), "path": List([ String("type_marked_deprecated"), - String("EnumToDeprecatedEnum"), + String("structs"), + String("StructToDeprecatedStruct"), ]), - "span_begin_line": Uint64(69), - "span_filename": String("src/lib.rs"), + "span_begin_line": Uint64(5), + "span_filename": String("src/structs.rs"), "visibility_limit": String("public"), }, { - "name": String("EnumToDeprecatedMessageEnum"), + "name": String("StructToDeprecatedMessageStruct"), "new_attr": String("#[deprecated = \"This attribute was added\"]"), - "owner_type": String("Enum"), + "owner_type": String("Struct"), "path": List([ String("type_marked_deprecated"), - String("EnumToDeprecatedMessageEnum"), + String("structs"), + String("StructToDeprecatedMessageStruct"), ]), - "span_begin_line": Uint64(74), - "span_filename": String("src/lib.rs"), + "span_begin_line": Uint64(10), + "span_filename": String("src/structs.rs"), "visibility_limit": String("public"), }, ] From cec04b9ed68bad7c54f5a6444c9aa5be5302d9a7 Mon Sep 17 00:00:00 2001 From: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> Date: Sun, 12 Feb 2023 09:31:24 -0500 Subject: [PATCH 9/9] Apply suggestions from code review --- test_crates/type_marked_deprecated/new/src/unions.rs | 2 +- test_crates/type_marked_deprecated/old/src/unions.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test_crates/type_marked_deprecated/new/src/unions.rs b/test_crates/type_marked_deprecated/new/src/unions.rs index dc3cf4e0..7adc62e8 100644 --- a/test_crates/type_marked_deprecated/new/src/unions.rs +++ b/test_crates/type_marked_deprecated/new/src/unions.rs @@ -53,4 +53,4 @@ union DeprecatedPrivateUnion { #[deprecated] pub union DeprecatedNewUnion { bar: u64, -} \ No newline at end of file +} diff --git a/test_crates/type_marked_deprecated/old/src/unions.rs b/test_crates/type_marked_deprecated/old/src/unions.rs index 21b8514e..74fc5432 100644 --- a/test_crates/type_marked_deprecated/old/src/unions.rs +++ b/test_crates/type_marked_deprecated/old/src/unions.rs @@ -39,4 +39,4 @@ pub union DeprecatedMessageUnionToDeprecatedMessageUnion { union DeprecatedPrivateUnion { bar: u64, -} \ No newline at end of file +}