-
-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
9 changed files
with
182 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
SemverQuery( | ||
id: "trait_method_unsafe_added", | ||
human_readable_name: "pub trait method became unsafe", | ||
description: "A method in a public trait became unsafe", | ||
required_update: Major, | ||
reference_link: Some("https://doc.rust-lang.org/book/ch19-01-unsafe-rust.html#calling-an-unsafe-function-or-method"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
baseline { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
importable_path { | ||
path @output @tag | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
method { | ||
unsafe @filter(op: "!=", value: ["$true"]) | ||
public_api_eligible @filter(op: "=", value: ["$true"]) | ||
method_name: name @output @tag | ||
} | ||
} | ||
} | ||
} | ||
current { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
importable_path { | ||
path @filter(op: "=", value: ["%path"]) | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
method { | ||
unsafe @filter(op: "=", value: ["$true"]) | ||
public_api_eligible @filter(op: "=", value: ["$true"]) | ||
name @filter(op: "=", value: ["%method_name"]) | ||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"true": true, | ||
"public": "public", | ||
}, | ||
error_message: "A publicly-visible trait method became `unsafe`, so implementing it now requires an `unsafe` qualifier.", | ||
per_result_error_template: Some("trait method <{{join \"::\" path}}>::{{method_name}} in file {{span_filename}}:{{span_begin_line}}"), | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
publish = false | ||
name = "trait_method_unsafe_added" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Method of public trait becomes unsafe, should get reported. | ||
pub trait PubTrait { | ||
unsafe fn becomes_unsafe(); | ||
fn stays_safe(); | ||
unsafe fn stays_unsafe(); | ||
} | ||
|
||
// Method of trait that was not publicly-visible becomes unsafe, shouldn't get | ||
// reported. | ||
pub trait TraitBecomesPublic { | ||
unsafe fn becomes_unsafe(); | ||
} | ||
|
||
// Method of trait that is publicly-visible becomes unsafe while trait becomes | ||
// private. The trait becoming private should be the only violation that's | ||
// reported. | ||
trait TraitBecomesPrivate { | ||
unsafe fn becomes_unsafe(); | ||
} | ||
|
||
// Method of trait becomes unsafe while trait also becomes unsafe. Method should | ||
// get reported along with trait. | ||
pub unsafe trait TraitBecomesUnsafe { | ||
unsafe fn becomes_unsafe(); | ||
} | ||
|
||
// Private trait's method becomes unsafe, shouldn't get reported. | ||
trait PrivateTrait { | ||
unsafe fn becomes_unsafe(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[package] | ||
publish = false | ||
name = "trait_method_unsafe_added" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
// Method of public trait becomes unsafe, should get reported. | ||
pub trait PubTrait { | ||
fn becomes_unsafe(); | ||
fn stays_safe(); | ||
unsafe fn stays_unsafe(); | ||
} | ||
|
||
// Method of trait that was not publicly-visible becomes unsafe, shouldn't get | ||
// reported. | ||
trait TraitBecomesPublic { | ||
fn becomes_unsafe(); | ||
} | ||
|
||
// Method of trait that is publicly-visible becomes unsafe while trait becomes | ||
// private. The trait becoming private should be the only violation that's | ||
// reported. | ||
pub trait TraitBecomesPrivate { | ||
fn becomes_unsafe(); | ||
} | ||
|
||
// Method of trait becomes unsafe while trait also becomes unsafe. Method should | ||
// get reported along with trait. | ||
pub trait TraitBecomesUnsafe { | ||
fn becomes_unsafe(); | ||
} | ||
|
||
// Private trait's method becomes unsafe, shouldn't get reported. | ||
trait PrivateTrait { | ||
fn becomes_unsafe(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"./test_crates/trait_method_unsafe_added/": [ | ||
{ | ||
"method_name": String("becomes_unsafe"), | ||
"path": List([ | ||
String("trait_method_unsafe_added"), | ||
String("PubTrait"), | ||
]), | ||
"span_begin_line": Uint64(3), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"method_name": String("becomes_unsafe"), | ||
"path": List([ | ||
String("trait_method_unsafe_added"), | ||
String("TraitBecomesUnsafe"), | ||
]), | ||
"span_begin_line": Uint64(24), | ||
"span_filename": String("src/lib.rs"), | ||
"visibility_limit": String("public"), | ||
} | ||
], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters