Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New lint: trait removed supertrait #470

Merged
merged 15 commits into from
Jun 17, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
108 changes: 54 additions & 54 deletions Cargo.lock

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

62 changes: 62 additions & 0 deletions src/lints/trait_removed_supertrait.ron
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
SemverQuery(
id: "trait_removed_supertrait",
human_readable_name: "supertrait removed or renamed",
description: "It is a breaking change to loosen generic bounds on a type since this can break users expecting the tightened bounds.",
era marked this conversation as resolved.
Show resolved Hide resolved
required_update: Major,
reference_link: None,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance we can find something to cite here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I should have asked about this earlier, on the semver reference does not seem to be an entry for this lint.

There is this that is somewhat similar but it's definitely not the exact case nor does the explanation help (IMHO).

The documentation about supertraits helps to understand what is breaking indirectly.

Is it worth adding any of those links?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the docs link for supertraits is the best option. It's not perfect, but it's certainly better than nothing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I will add it :)

query: r#"{
era marked this conversation as resolved.
Show resolved Hide resolved
CrateDiff {
baseline {
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"]) @output
importable_path {
path @output @tag
}


era marked this conversation as resolved.
Show resolved Hide resolved
supertrait {
trait {
importable_path {
trait_path: path @output @tag
}
}
}
}
}
}
current {
item {
... on Trait {
visibility_limit @filter(op: "=", value: ["$public"])
name @output

importable_path {
path @filter(op: "=", value: ["%path"])
}

supertrait @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
trait {
importable_path {
path @filter(op: "=", value: ["%trait_path"])
}
}
}

span_: span @optional {
filename @output
begin_line @output
}

era marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}
}"#,
arguments: {
"public": "public",
"zero": 0,
},
error_message: "A supertrait was removed from a trait.",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps tweak this to include a hint of why this might be a problem. Feel free to use some of the language from the description field.

per_result_error_template: Some("supertrait {{trait_path}} for trait {{name}} in file {{span_filename}}:{{span_begin_line}}"),
era marked this conversation as resolved.
Show resolved Hide resolved
)
1 change: 1 addition & 0 deletions src/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,5 @@ add_lints!(
variant_marked_non_exhaustive,
enum_tuple_variant_field_missing,
enum_tuple_variant_field_added,
trait_removed_supertrait,
);
7 changes: 7 additions & 0 deletions test_crates/trait_removed_supertrait/new/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
publish = false
name = "trait_removed_supertrait"
version = "0.1.0"
edition = "2021"

[dependencies]
5 changes: 5 additions & 0 deletions test_crates/trait_removed_supertrait/new/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pub trait SuperTrait {}

pub trait BaseTrait {}

pub trait CorrectTrait : SuperTrait {}
Loading