-
-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into update_path_dependency_lockfile
- Loading branch information
Showing
10 changed files
with
541 additions
and
11 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,60 @@ | ||
SemverQuery( | ||
id: "trait_method_added", | ||
human_readable_name: "pub trait method added", | ||
description: "A non-sealed public trait added a new method without a default implementation", | ||
required_update: Major, | ||
lint_level: Deny, | ||
reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
current { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
name @output | ||
importable_path { | ||
path @output @tag | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
method { | ||
method_name: name @output @tag | ||
has_body @filter(op: "!=", value: ["$true"]) | ||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
} | ||
baseline { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
sealed @filter(op: "!=", value: ["$true"]) | ||
importable_path { | ||
path @filter(op: "=", value: ["%path"]) | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
method @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
name @filter(op: "=", value: ["%method_name"]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"true": true, | ||
"public": "public", | ||
"zero": 0, | ||
}, | ||
error_message: "A non-sealed public trait added a new method without a default implementation, which breaks downstream implementations of the trait", | ||
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
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_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,49 @@ | ||
mod sealed { | ||
pub(crate) trait Sealed {} | ||
} | ||
|
||
// ---- Should be reported ---- | ||
pub trait WillGainMethodWithoutDefault { | ||
fn one_method(self); | ||
} | ||
|
||
pub trait WillGainAnotherMethodWithoutDefault { | ||
fn one_method(self); | ||
fn two_method(self); | ||
} | ||
|
||
pub trait WillGainMultipleMethodsWithoutDefault { | ||
fn one_method(self); | ||
fn two_method(self); | ||
} | ||
|
||
pub trait WillGainMethodWithoutDefaultAndSeal: sealed::Sealed { | ||
fn one_method(self); | ||
} | ||
|
||
pub trait WIllGainDocHiddenMethodWithoutDefault { | ||
#[doc(hidden)] | ||
fn one_method(self); | ||
} | ||
|
||
// ---- Should not be reported ---- | ||
pub trait WillGainMethodWithDefault { | ||
fn one_method(self) {} | ||
} | ||
|
||
pub trait WillGainAnotherMethodWithDefault { | ||
fn one_method(self); | ||
fn two_method(self) {} | ||
} | ||
|
||
pub trait WillGainMethodWithoutDefaultSealed: sealed::Sealed { | ||
fn one_method(self); | ||
} | ||
|
||
pub trait WillGainMethodWithoutDefaultAndLoseSeal { | ||
fn one_method(self); | ||
} | ||
|
||
pub trait WillKeepAMethodWithoutDefault { | ||
fn one_method(self); | ||
} |
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_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,31 @@ | ||
mod sealed { | ||
pub(crate) trait Sealed {} | ||
} | ||
|
||
// ---- Should be reported ---- | ||
pub trait WillGainMethodWithoutDefault {} | ||
|
||
pub trait WillGainAnotherMethodWithoutDefault { | ||
fn one_method(self); | ||
} | ||
|
||
pub trait WillGainMultipleMethodsWithoutDefault {} | ||
|
||
pub trait WillGainMethodWithoutDefaultAndSeal {} | ||
|
||
pub trait WIllGainDocHiddenMethodWithoutDefault {} | ||
|
||
// ---- Should not be reported ---- | ||
pub trait WillGainMethodWithDefault {} | ||
|
||
pub trait WillGainAnotherMethodWithDefault { | ||
fn one_method(self); | ||
} | ||
|
||
pub trait WillGainMethodWithoutDefaultSealed: sealed::Sealed {} | ||
|
||
pub trait WillGainMethodWithoutDefaultAndLoseSeal: sealed::Sealed {} | ||
|
||
pub trait WillKeepAMethodWithoutDefault { | ||
fn one_method(self); | ||
} |
Oops, something went wrong.