Skip to content

Commit

Permalink
Added public API sealed in trait_newly_sealed (#1160)
Browse files Browse the repository at this point in the history
Resolves #1115

---------

Co-authored-by: Predrag Gruevski <[email protected]>
  • Loading branch information
geetanshjuneja and obi1kenobi authored Feb 25, 2025
1 parent 203bef6 commit f559342
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/lints/trait_newly_sealed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SemverQuery(
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"]) @output
unconditionally_sealed @filter(op: "!=", value: ["$true"])
public_api_sealed @filter(op: "!=", value: ["$true"])
importable_path {
path @output @tag
Expand All @@ -25,7 +25,7 @@ SemverQuery(
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"])
unconditionally_sealed @filter(op: "=", value: ["$true"])
public_api_sealed @filter(op: "=", value: ["$true"])
name @output
importable_path {
Expand Down
8 changes: 8 additions & 0 deletions test_crates/trait_newly_sealed/new/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ pub trait TraitBecomesPublicAndSealed: private::Sealed {}
// and should be the only violation that's reported:
// Thus being newly sealed is not the main problem
trait TraitBecomesPrivateAndSealed: private::Sealed {}

// This trait was public API sealed to begin with.
// Here it becomes unconditionally sealed, which we shouldn't flag.
// The only breakage is among uses that went beyond the public API.
pub trait PublicAPISealed: private::Sealed {
#[doc(hidden)]
type Hidden;
}
8 changes: 8 additions & 0 deletions test_crates/trait_newly_sealed/old/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,11 @@ trait TraitBecomesPublicAndSealed {}
// and should be the only violation that's reported:
// Thus being newly sealed is not the main problem
pub trait TraitBecomesPrivateAndSealed {}

// This trait is public API sealed.
// In the new code, it becomes unconditionally sealed, which we shouldn't flag.
// The only breakage is among uses that went beyond the public API.
pub trait PublicAPISealed {
#[doc(hidden)]
type Hidden;
}
59 changes: 59 additions & 0 deletions test_outputs/query_execution/trait_newly_sealed.snap
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("WillGainADocHiddenConst"),
"path": List([
String("trait_associated_const_added"),
String("WillGainADocHiddenConst"),
]),
"span_begin_line": Uint64(46),
"span_end_line": Uint64(51),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
"./test_crates/trait_associated_type_added/": [
{
Expand All @@ -28,6 +39,17 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("WillGainADocHiddenType"),
"path": List([
String("trait_associated_type_added"),
String("WillGainADocHiddenType"),
]),
"span_begin_line": Uint64(51),
"span_end_line": Uint64(56),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
"./test_crates/trait_method_added/": [
{
Expand All @@ -41,6 +63,17 @@ expression: "&query_execution_results"
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
{
"name": String("WIllGainDocHiddenMethodWithoutDefault"),
"path": List([
String("trait_method_added"),
String("WIllGainDocHiddenMethodWithoutDefault"),
]),
"span_begin_line": Uint64(24),
"span_end_line": Uint64(27),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
"./test_crates/trait_method_default_impl_removed/": [
{
Expand All @@ -66,6 +99,19 @@ expression: "&query_execution_results"
"visibility_limit": String("public"),
},
],
"./test_crates/trait_method_now_doc_hidden/": [
{
"name": String("PublicTrait"),
"path": List([
String("trait_method_now_doc_hidden"),
String("PublicTrait"),
]),
"span_begin_line": Uint64(12),
"span_end_line": Uint64(17),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
"./test_crates/trait_newly_sealed/": [
{
"name": String("TraitBecomesSealed"),
Expand All @@ -90,4 +136,17 @@ expression: "&query_execution_results"
"visibility_limit": String("public"),
},
],
"./test_crates/trait_now_doc_hidden/": [
{
"name": String("PublicTraitHiddenVariant"),
"path": List([
String("trait_now_doc_hidden"),
String("PublicTraitHiddenVariant"),
]),
"span_begin_line": Uint64(49),
"span_end_line": Uint64(55),
"span_filename": String("src/lib.rs"),
"visibility_limit": String("public"),
},
],
}

0 comments on commit f559342

Please sign in to comment.