-
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add
trait_added_supertrait
(#892)
* feat: add trait_added_supertrait * review * typo and std supertraits * add std to core supertrait test * bless tests * Update src/lints/trait_added_supertrait.ron Co-authored-by: Max Carr <m@mcarr.one> --------- Co-authored-by: Predrag Gruevski <2348618+obi1kenobi@users.noreply.github.com> Co-authored-by: Max Carr <m@mcarr.one>
- Loading branch information
1 parent
1a56407
commit 44aea25
Showing
7 changed files
with
221 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,58 @@ | ||
SemverQuery( | ||
id: "trait_added_supertrait", | ||
human_readable_name: "non-sealed trait added new supertraits", | ||
description: "A non-sealed trait added one or more supertraits, which breaks downstream implementations of the trait", | ||
required_update: Major, | ||
lint_level: Deny, | ||
reference_link: Some("https://doc.rust-lang.org/cargo/reference/semver.html#generic-bounds-tighten"), | ||
query: r#" | ||
{ | ||
CrateDiff { | ||
current { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) | ||
importable_path { | ||
path @output @tag | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
supertrait { | ||
supertrait: name @output @tag | ||
} | ||
span_: span @optional { | ||
filename @output | ||
begin_line @output | ||
} | ||
} | ||
} | ||
} | ||
baseline { | ||
item { | ||
... on Trait { | ||
visibility_limit @filter(op: "=", value: ["$public"]) @output | ||
sealed @filter(op: "!=", value: ["$true"]) | ||
importable_path { | ||
path @filter(op: "=", value: ["%path"]) | ||
public_api @filter(op: "=", value: ["$true"]) | ||
} | ||
supertrait @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) { | ||
name @filter(op: "=", value: ["%supertrait"]) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
}"#, | ||
arguments: { | ||
"public": "public", | ||
"true": true, | ||
"zero": 0, | ||
}, | ||
error_message: "A non-sealed trait added one or more supertraits, which breaks downstream implementations of the trait", | ||
per_result_error_template: Some("trait {{join \"::\" path}} gained {{supertrait}} 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_added_supertrait" | ||
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,23 @@ | ||
pub trait TraitOne {} | ||
pub trait TraitTwo {} | ||
|
||
mod sealed { | ||
pub trait Sealed {} | ||
} | ||
|
||
pub trait Unchanged {} | ||
pub trait UnchangedSealed: sealed::Sealed {} | ||
|
||
pub trait WillGainOne: TraitOne {} | ||
pub trait WillGainOneSealed: TraitOne + sealed::Sealed {} | ||
|
||
pub trait WillGainAnotherOne: TraitOne + TraitTwo {} | ||
pub trait WillGainAnotherOneSealed: TraitOne + TraitTwo + sealed::Sealed {} | ||
|
||
pub trait WillGainStdOne: Sync {} | ||
pub trait WillGainStdTwo: core::fmt::Debug {} | ||
pub trait WillGainStdThree: PartialEq { | ||
fn make_me_non_object_safe() -> Self; | ||
} | ||
|
||
pub trait WillChangeStdToCore: core::fmt::Debug {} |
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_added_supertrait" | ||
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,23 @@ | ||
pub trait TraitOne {} | ||
pub trait TraitTwo {} | ||
|
||
mod sealed { | ||
pub trait Sealed {} | ||
} | ||
|
||
pub trait Unchanged {} | ||
pub trait UnchangedSealed: sealed::Sealed {} | ||
|
||
pub trait WillGainOne {} | ||
pub trait WillGainOneSealed: sealed::Sealed {} | ||
|
||
pub trait WillGainAnotherOne: TraitOne {} | ||
pub trait WillGainAnotherOneSealed: TraitOne + sealed::Sealed {} | ||
|
||
pub trait WillGainStdOne {} | ||
pub trait WillGainStdTwo {} | ||
pub trait WillGainStdThree { | ||
fn make_me_non_object_safe() -> Self; | ||
} | ||
|
||
pub trait WillChangeStdToCore: std::fmt::Debug {} |
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,102 @@ | ||
{ | ||
"./test_crates/trait_added_supertrait/": [ | ||
{ | ||
"path": List([ | ||
String("trait_added_supertrait"), | ||
String("WillGainOne"), | ||
]), | ||
"span_begin_line": Uint64(11), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("TraitOne"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"path": List([ | ||
String("trait_added_supertrait"), | ||
String("WillGainAnotherOne"), | ||
]), | ||
"span_begin_line": Uint64(14), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("TraitTwo"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"path": List([ | ||
String("trait_added_supertrait"), | ||
String("WillGainStdOne"), | ||
]), | ||
"span_begin_line": Uint64(17), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("Sync"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"path": List([ | ||
String("trait_added_supertrait"), | ||
String("WillGainStdTwo"), | ||
]), | ||
"span_begin_line": Uint64(18), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("Debug"), | ||
"visibility_limit": String("public"), | ||
}, | ||
{ | ||
"path": List([ | ||
String("trait_added_supertrait"), | ||
String("WillGainStdThree"), | ||
]), | ||
"span_begin_line": Uint64(19), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("PartialEq"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
"./test_crates/trait_associated_const_added/": [ | ||
{ | ||
"path": List([ | ||
String("trait_associated_const_added"), | ||
String("WillGainConstWithoutDefaultAndSeal"), | ||
]), | ||
"span_begin_line": Uint64(16), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("Sealed"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
"./test_crates/trait_associated_type_added/": [ | ||
{ | ||
"path": List([ | ||
String("trait_associated_type_added"), | ||
String("WillGainTypeWithoutDefaultAndSeal"), | ||
]), | ||
"span_begin_line": Uint64(19), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("Sealed"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
"./test_crates/trait_method_added/": [ | ||
{ | ||
"path": List([ | ||
String("trait_method_added"), | ||
String("WillGainMethodWithoutDefaultAndSeal"), | ||
]), | ||
"span_begin_line": Uint64(20), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("Sealed"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
"./test_crates/trait_newly_sealed/": [ | ||
{ | ||
"path": List([ | ||
String("trait_newly_sealed"), | ||
String("TraitBecomesSealed"), | ||
]), | ||
"span_begin_line": Uint64(7), | ||
"span_filename": String("src/lib.rs"), | ||
"supertrait": String("Sealed"), | ||
"visibility_limit": String("public"), | ||
}, | ||
], | ||
} |