Skip to content

Commit

Permalink
Update to adapter w/ sealed trait analysis & update lints to match.
Browse files Browse the repository at this point in the history
  • Loading branch information
obi1kenobi committed Aug 19, 2024
1 parent c0ea8df commit cdd1407
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 55 deletions.
78 changes: 39 additions & 39 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version = "1.77"

[dependencies]
trustfall = "0.7.1"
trustfall_rustdoc = { version = "0.15.3", default-features = false, features = ["v28", "v29", "v30", "v32", "v33"] }
trustfall_rustdoc = { version = "0.16.0", default-features = false, features = ["v28", "v29", "v30", "v32", "v33"] }
clap = { version = "4.0.0", features = ["derive", "cargo"] }
serde_json = "1.0.82"
anyhow = "1.0.58"
Expand Down
8 changes: 1 addition & 7 deletions src/lints/trait_method_unsafe_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,13 @@ SemverQuery(
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"]) @output
sealed @filter(op: "!=", value: ["$true"])
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
supertrait @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
trait {
importable_path @fold @transform(op: "count") @filter(op: "=", value: ["$zero"])
}
}
method {
unsafe @filter(op: "=", value: ["$true"])
public_api_eligible @filter(op: "=", value: ["$true"])
Expand Down Expand Up @@ -60,7 +55,6 @@ SemverQuery(
arguments: {
"true": true,
"public": "public",
"zero": 0,
},
error_message: "A publicly-visible trait method is no longer `unsafe`, so implementations must remove the `unsafe` qualifier.",
per_result_error_template: Some("trait method <{{join \"::\" path}}>::{{method_name}} in file {{span_filename}}:{{span_begin_line}}"),
Expand Down
3 changes: 2 additions & 1 deletion src/lints/trait_unsafe_added.ron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SemverQuery(
id: "trait_unsafe_added",
human_readable_name: "pub trait became unsafe",
description: "A public trait became unsafe.",
description: "A public trait became unsafe, requiring `unsafe impl` blocks to implement it.",
required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#implementing-an-unsafe-trait"),
Expand All @@ -13,6 +13,7 @@ SemverQuery(
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"]) @output
unsafe @filter(op: "!=", value: ["$true"])
sealed @filter(op: "!=", value: ["$true"])
importable_path {
path @output @tag
Expand Down
3 changes: 2 additions & 1 deletion src/lints/trait_unsafe_removed.ron
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
SemverQuery(
id: "trait_unsafe_removed",
human_readable_name: "pub unsafe trait became safe",
description: "A public unsafe trait became safe.",
description: "A public unsealed unsafe trait became safe, so its `unsafe impl` blocks must be changed to regular `impl`.",
required_update: Major,
lint_level: Deny,
reference_link: Some("https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#implementing-an-unsafe-trait"),
Expand All @@ -13,6 +13,7 @@ SemverQuery(
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"]) @output
unsafe @filter(op: "=", value: ["$true"])
sealed @filter(op: "!=", value: ["$true"])
importable_path {
path @output @tag
Expand Down
3 changes: 0 additions & 3 deletions test_crates/trait_method_unsafe_removed/new/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,3 @@ mod private {
trait Sealed {}

pub trait Unsealed {}

// TODO: Try a sealed trait using a private supertrait
// /~https://github.com/rust-lang/rust/issues/119280#issuecomment-1868582786
3 changes: 0 additions & 3 deletions test_crates/trait_method_unsafe_removed/old/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,3 @@ mod private {
trait Sealed {}

pub trait Unsealed {}

// TODO: Try a sealed trait using a private supertrait
// /~https://github.com/rust-lang/rust/issues/119280#issuecomment-1868582786
7 changes: 7 additions & 0 deletions test_crates/trait_unsafe_added/new/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ pub unsafe trait UnsafeTrait {}

// Normal trait, doesn't get changed.
pub trait NormalTrait {}

mod private {
pub trait Sealed {}
}

// Sealed trait, becoming unsafe doesn't matter since it cannot be implemented downstream.
pub unsafe trait SealedTrait: private::Sealed {}
7 changes: 7 additions & 0 deletions test_crates/trait_unsafe_added/old/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ pub unsafe trait UnsafeTrait {}

// Normal trait, doesn't get changed.
pub trait NormalTrait {}

mod private {
pub trait Sealed {}
}

// Sealed trait, becoming unsafe doesn't matter since it cannot be implemented downstream.
pub trait SealedTrait: private::Sealed {}
7 changes: 7 additions & 0 deletions test_crates/trait_unsafe_removed/new/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ trait TraitBecomesPrivateAndSafe {}

// Private trait becomes safe, shouldn't get reported.
trait PrivateTraitBecomesSafe {}

mod private {
pub trait Sealed {}
}

// Sealed trait, becoming safe doesn't matter since it cannot be implemented downstream.
pub trait SealedTrait: private::Sealed {}
7 changes: 7 additions & 0 deletions test_crates/trait_unsafe_removed/old/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,10 @@ pub unsafe trait TraitBecomesPrivateAndSafe {}

// Private trait becomes safe, shouldn't get reported.
unsafe trait PrivateTraitBecomesSafe {}

mod private {
pub trait Sealed {}
}

// Sealed trait, becoming safe doesn't matter since it cannot be implemented downstream.
pub unsafe trait SealedTrait: private::Sealed {}

0 comments on commit cdd1407

Please sign in to comment.