diff --git a/src/lints/declarative_macro_missing.ron b/src/lints/declarative_macro_missing.ron index 4cdfdf5c..7ce6f463 100644 --- a/src/lints/declarative_macro_missing.ron +++ b/src/lints/declarative_macro_missing.ron @@ -12,9 +12,13 @@ SemverQuery( item { ... on Macro { visibility_limit @filter(op: "=", value: ["$public"]) - public_api_eligible @filter(op: "=", value: ["$true"]) name @output @tag + importable_path { + path @output @tag + public_api @filter(op: "=", value: ["$true"]) + } + span_: span @optional { filename @output begin_line @output @@ -22,10 +26,26 @@ SemverQuery( } } } - current @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { - item { + current { + # There is no exported macro at that path anymore (hidden or not). + item @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { + ... on Macro { + importable_path { + path @filter(op: "=", value: ["%path"]) + } + } + } + + # There is also no macro under the same name that is *not* exported, + # nor exportable (in a way that fixes the breakage) + # just by adding `#[macro_export]`. + # This is to differentiate from the `macro_no_longer_exported` and + # `macro_now_doc_hidden` lints. + item @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { ... on Macro { name @filter(op: "=", value: ["%name"]) + public_api_eligible @filter(op: "!=", value: ["$true"]) + doc_hidden @filter(op: "!=", value: ["$true"]) } } } @@ -36,8 +56,8 @@ SemverQuery( "zero": 0, "true": true, }, - error_message: "A `macro_rules` declarative macro cannot be invoked by its prior name. The macro may have been renamed or removed entirely.", - per_result_error_template: Some("macro_rules! {{name}}, previously in file {{span_filename}}:{{span_begin_line}}"), + error_message: "A `macro_rules!` declarative macro cannot be invoked by its prior name. The macro may have been renamed or removed entirely.", + per_result_error_template: Some("macro {{name}}, previously in file {{span_filename}}:{{span_begin_line}}"), witness: ( hint_template: r#"{{name}}!(...);"# ), diff --git a/src/lints/macro_no_longer_exported.ron b/src/lints/macro_no_longer_exported.ron index 1047295c..75951fff 100644 --- a/src/lints/macro_no_longer_exported.ron +++ b/src/lints/macro_no_longer_exported.ron @@ -12,7 +12,11 @@ SemverQuery( item { ... on Macro { name @output @tag - public_api_eligible @filter(op: "=", value: ["$true"]) + + importable_path { + path @output @tag + public_api @filter(op: "=", value: ["$true"]) + } span_: span @optional { filename @output @@ -26,7 +30,10 @@ SemverQuery( item @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { ... on Macro { name @filter(op: "=", value: ["%name"]) - public_api_eligible @filter(op: "=", value: ["$true"]) + + importable_path { + path @filter(op: "=", value: ["%path"]) + } } } @@ -54,7 +61,7 @@ SemverQuery( "true": true, "zero": 0, }, - error_message: "A macro that was previously exported with #[macro_export] is no longer exported. This breaks downstream code that used the macro.", + error_message: "A `macro_rules!` declarative macro that was previously exported with `#[macro_export]` is no longer exported. This breaks downstream code that used the macro.", per_result_error_template: Some("macro {{name}} in {{span_filename}}:{{span_begin_line}}"), witness: Some(( hint_template: r#"{{name}}!(...);"#, diff --git a/src/lints/macro_now_doc_hidden.ron b/src/lints/macro_now_doc_hidden.ron index 32170c0e..2394ea57 100644 --- a/src/lints/macro_now_doc_hidden.ron +++ b/src/lints/macro_now_doc_hidden.ron @@ -12,7 +12,11 @@ SemverQuery( item { ... on Macro { name @output @tag - public_api_eligible @filter(op: "=", value: ["$true"]) + + importable_path { + path @output @tag + public_api @filter(op: "=", value: ["$true"]) + } } } } @@ -20,8 +24,12 @@ SemverQuery( item { ... on Macro { name @filter(op: "=", value: ["%name"]) - doc_hidden @filter(op: "=", value: ["$true"]) - public_api_eligible @filter(op: "!=", value: ["$true"]) + + importable_path { + path @filter(op: "=", value: ["%path"]) + public_api @filter(op: "!=", value: ["$true"]) + } + span_: span @optional { filename @output begin_line @output @@ -34,7 +42,7 @@ SemverQuery( arguments: { "true": true, }, - error_message: "A macro that was previously part of the public API is now #[doc(hidden)].", + error_message: "A `macro_rules!` declarative macro that was previously part of the public API is now `#[doc(hidden)]` and not public API anymore.", per_result_error_template: Some("macro {{name}} in {{span_filename}}:{{span_begin_line}}"), witness: None, ) diff --git a/test_crates/macro_no_longer_exported/new/src/lib.rs b/test_crates/macro_no_longer_exported/new/src/lib.rs index 73e1b8bd..93ac4796 100644 --- a/test_crates/macro_no_longer_exported/new/src/lib.rs +++ b/test_crates/macro_no_longer_exported/new/src/lib.rs @@ -7,9 +7,9 @@ macro_rules! example_macro { // No longer exported but is hidden - should NOT trigger (caught by different lint) #[doc(hidden)] -macro_rules! will_be_hidden { +macro_rules! will_be_hidden_and_not_exported { () => { - println!("Will become hidden"); + println!("Will become hidden and not exported"); }; } diff --git a/test_crates/macro_no_longer_exported/old/src/lib.rs b/test_crates/macro_no_longer_exported/old/src/lib.rs index 03965feb..28422a71 100644 --- a/test_crates/macro_no_longer_exported/old/src/lib.rs +++ b/test_crates/macro_no_longer_exported/old/src/lib.rs @@ -6,9 +6,9 @@ macro_rules! example_macro { } #[macro_export] -macro_rules! will_be_hidden { +macro_rules! will_be_hidden_and_not_exported { () => { - println!("Will become hidden"); + println!("Will become hidden and not exported"); }; } diff --git a/test_outputs/query_execution/declarative_macro_missing.snap b/test_outputs/query_execution/declarative_macro_missing.snap index f68d5348..467a8f69 100644 --- a/test_outputs/query_execution/declarative_macro_missing.snap +++ b/test_outputs/query_execution/declarative_macro_missing.snap @@ -7,8 +7,23 @@ snapshot_kind: text "./test_crates/declarative_macro_missing/": [ { "name": String("will_be_removed"), + "path": List([ + String("declarative_macro_missing"), + String("will_be_removed"), + ]), "span_begin_line": Uint64(2), "span_filename": String("src/lib.rs"), }, ], + "./test_crates/macro_no_longer_exported/": [ + { + "name": String("will_be_hidden_and_not_exported"), + "path": List([ + String("macro_no_longer_exported"), + String("will_be_hidden_and_not_exported"), + ]), + "span_begin_line": Uint64(9), + "span_filename": String("src/lib.rs"), + }, + ], } diff --git a/test_outputs/query_execution/macro_no_longer_exported.snap b/test_outputs/query_execution/macro_no_longer_exported.snap index ef18f0c6..212c800e 100644 --- a/test_outputs/query_execution/macro_no_longer_exported.snap +++ b/test_outputs/query_execution/macro_no_longer_exported.snap @@ -13,6 +13,10 @@ snapshot_kind: text "non_exported_span_filename": List([ String("src/lib.rs"), ]), + "path": List([ + String("declarative_macro_missing"), + String("will_no_longer_be_exported"), + ]), "span_begin_line": Uint64(7), "span_filename": String("src/lib.rs"), }, @@ -26,6 +30,10 @@ snapshot_kind: text "non_exported_span_filename": List([ String("src/lib.rs"), ]), + "path": List([ + String("macro_no_longer_exported"), + String("example_macro"), + ]), "span_begin_line": Uint64(2), "span_filename": String("src/lib.rs"), }, @@ -39,6 +47,10 @@ snapshot_kind: text String("src/lib.rs"), String("src/lib.rs"), ]), + "path": List([ + String("macro_no_longer_exported"), + String("some_macro"), + ]), "span_begin_line": Uint64(26), "span_filename": String("src/lib.rs"), }, @@ -52,6 +64,10 @@ snapshot_kind: text "non_exported_span_filename": List([ String("src/lib.rs"), ]), + "path": List([ + String("macro_now_doc_hidden"), + String("becomes_non_exported"), + ]), "span_begin_line": Uint64(36), "span_filename": String("src/lib.rs"), }, diff --git a/test_outputs/query_execution/macro_now_doc_hidden.snap b/test_outputs/query_execution/macro_now_doc_hidden.snap index 0cf24726..7321beb2 100644 --- a/test_outputs/query_execution/macro_now_doc_hidden.snap +++ b/test_outputs/query_execution/macro_now_doc_hidden.snap @@ -7,20 +7,21 @@ snapshot_kind: text "./test_crates/declarative_macro_missing/": [ { "name": String("became_doc_hidden"), + "path": List([ + String("declarative_macro_missing"), + String("became_doc_hidden"), + ]), "span_begin_line": Uint64(7), "span_filename": String("src/lib.rs"), }, ], - "./test_crates/macro_no_longer_exported/": [ - { - "name": String("will_be_hidden"), - "span_begin_line": Uint64(10), - "span_filename": String("src/lib.rs"), - }, - ], "./test_crates/macro_now_doc_hidden/": [ { "name": String("will_be_hidden"), + "path": List([ + String("macro_now_doc_hidden"), + String("will_be_hidden"), + ]), "span_begin_line": Uint64(4), "span_filename": String("src/lib.rs"), }, diff --git a/test_outputs/witnesses/declarative_macro_missing.snap b/test_outputs/witnesses/declarative_macro_missing.snap index 5fa1acf8..11f2936d 100644 --- a/test_outputs/witnesses/declarative_macro_missing.snap +++ b/test_outputs/witnesses/declarative_macro_missing.snap @@ -8,3 +8,8 @@ snapshot_kind: text filename = 'src/lib.rs' begin_line = 2 hint = 'will_be_removed!(...);' + +[["./test_crates/macro_no_longer_exported/"]] +filename = 'src/lib.rs' +begin_line = 9 +hint = 'will_be_hidden_and_not_exported!(...);'