Skip to content

Commit

Permalink
Detect and don't report non-breaking renaming re-exports. (#330)
Browse files Browse the repository at this point in the history
* Detect and don't report non-breaking renaming re-exports.

Only use importable names to match items across versions.

* Add crates experiencing false-positives to regression suite.
  • Loading branch information
obi1kenobi authored Jan 29, 2023
1 parent 3d0a336 commit 7d18362
Show file tree
Hide file tree
Showing 46 changed files with 291 additions and 87 deletions.
46 changes: 46 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- lint
- rust-tests
- run-on-rust-libp2p
- run-on-libp2p-dcutr-relay
- run-on-core-graphics
- run-on-bevy-core
- run-on-bevy-gltf
Expand Down Expand Up @@ -140,6 +141,51 @@ jobs:
- name: Run semver-checks (alternative command)
run: cargo run semver-checks check-release --manifest-path="subject/core/Cargo.toml" --package="libp2p-core"

run-on-libp2p-dcutr-relay:
# Run cargo-semver-checks on a crate with no semver violations,
# to make sure there are no false-positives.
#
# cargo-semver-checks previously reported false-positives here
# due to renaming re-exports causing confusion about which types match each other:
# https://github.com/obi1kenobi/cargo-semver-checks/issues/202
# https://github.com/libp2p/rust-libp2p/pull/2647#issuecomment-1340254920
name: Run cargo-semver-checks on libp2p-dcutr 1.62.0 and libp2p-relay 0.14.0
runs-on: ubuntu-latest
steps:
- name: Checkout cargo-semver-checks
uses: actions/checkout@v3
with:
persist-credentials: false

- name: Checkout rust-libp2p
uses: actions/checkout@v3
with:
persist-credentials: false
repository: 'libp2p/rust-libp2p'
ref: 'be0b62a78fe9d72811b9eda742137cc8ddc4da35'
path: 'subject'

- name: Install rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
profile: minimal
override: true

# rust-libp2p requires protobuf-compiler.
- name: Install protobuf-compiler
run: sudo apt install protobuf-compiler

- uses: Swatinem/rust-cache@v2
with:
key: libp2p-dcutr-relay

- name: Run semver-checks on libp2p-dcutr
run: cargo run semver-checks check-release --manifest-path="subject/protocols/dcutr/Cargo.toml"

- name: Run semver-checks on libp2p-relay
run: cargo run semver-checks check-release --manifest-path="subject/protocols/relay/Cargo.toml"

run-on-core-graphics:
# Run cargo-semver-checks on a crate with no semver violations,
# to make sure there are no false-positives.
Expand Down
3 changes: 1 addition & 2 deletions src/lints/auto_trait_impl_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ SemverQuery(
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output @tag
importable_path {
path @output @tag
Expand Down Expand Up @@ -41,7 +40,7 @@ SemverQuery(
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/constructible_struct_adds_field.ron
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SemverQuery(
# clearly stated that they don't consider the struct exhaustive anymore.
attrs @filter(op: "not_contains", value: ["$non_exhaustive"])
struct_name: name @output @tag
struct_name: name @output
struct_type @output @tag
importable_path {
Expand All @@ -45,7 +45,6 @@ SemverQuery(
# 2. It needs to not have had any non-public fields.
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%struct_name"])
struct_type @filter(op: "=", value: ["%struct_type"])
# 1. It needs to not have been marked `#[non_exhaustive]`.
Expand Down
3 changes: 1 addition & 2 deletions src/lints/constructible_struct_adds_private_field.ron
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SemverQuery(
# clearly stated that they don't consider the struct exhaustive anymore.
attrs @filter(op: "not_contains", value: ["$non_exhaustive"])
struct_name: name @output @tag
struct_name: name @output
struct_type @output @tag
importable_path {
Expand All @@ -45,7 +45,6 @@ SemverQuery(
# 2. It needs to not have had any non-public fields.
... on Struct {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%struct_name"])
struct_type @filter(op: "=", value: ["%struct_type"])
# 1. It needs to not have been marked `#[non_exhaustive]`.
Expand Down
3 changes: 1 addition & 2 deletions src/lints/constructible_struct_changed_type.ron
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ More info: https://github.com/obi1kenobi/cargo-semver-checks/issues/297
... on Struct {
struct_typename: __typename @tag @output
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output @tag
struct_type @output
# If the struct is non-exhaustive, it can't be constructed using a literal.
Expand All @@ -47,7 +46,7 @@ More info: https://github.com/obi1kenobi/cargo-semver-checks/issues/297
current_typename: __typename @filter(op: "!=", value: ["%struct_typename"])
@output
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/derive_trait_impl_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ SemverQuery(
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output @tag
importable_path {
path @output @tag
Expand Down Expand Up @@ -49,7 +48,7 @@ SemverQuery(
item {
... on ImplOwner {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
importable_path @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_marked_non_exhaustive.ron
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output @tag
name @output
attrs @filter(op: "contains", value: ["$non_exhaustive"])
Expand All @@ -37,7 +37,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
attrs @filter(op: "not_contains", value: ["$non_exhaustive"])
importable_path {
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output @tag
name @output
importable_path {
path @output @tag
Expand All @@ -28,7 +28,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_must_use_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @tag @output
name @output
importable_path {
path @tag @output
Expand All @@ -38,7 +38,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
7 changes: 3 additions & 4 deletions src/lints/enum_repr_c_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output
attribute {
old_attr: raw_attribute @output
content {
Expand All @@ -37,8 +36,8 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
attribute @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
content {
base @filter(op: "=", value: ["$repr"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_repr_int_changed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output
attribute {
old_attr: raw_attribute @output
Expand All @@ -38,7 +37,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_repr_int_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @tag @output
attribute {
old_attr: raw_attribute @output
Expand All @@ -37,7 +36,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_struct_variant_field_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
enum_name: name @output @tag
enum_name: name @output
importable_path {
path @output @tag
Expand Down Expand Up @@ -44,7 +44,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%enum_name"])
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
5 changes: 2 additions & 3 deletions src/lints/enum_struct_variant_field_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
enum_name: name @output @tag
importable_path {
path @output @tag
Expand All @@ -37,7 +36,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%enum_name"])
enum_name: name @output
importable_path {
path @filter(op: "=", value: ["%path"])
Expand All @@ -46,7 +45,7 @@ SemverQuery(
variant {
... on StructVariant {
name @filter(op: "=", value: ["%variant_name"])
field @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
name @filter(op: "=", value: ["%field_name"])
}
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_variant_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ SemverQuery(
current {
item {
... on Enum {
enum_name: name @output @tag
enum_name: name @output
visibility_limit @filter(op: "=", value: ["$public"]) @output
attrs @filter(op: "not_contains", value: ["$non_exhaustive"])
Expand All @@ -32,7 +32,6 @@ SemverQuery(
baseline {
item {
... on Enum {
name @filter(op: "=", value: ["%enum_name"])
visibility_limit @filter(op: "=", value: ["$public"])
attrs @filter(op: "not_contains", value: ["$non_exhaustive"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/enum_variant_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"]) @output
enum_name: name @output @tag
importable_path {
path @output @tag
Expand All @@ -32,7 +31,7 @@ SemverQuery(
item {
... on Enum {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%enum_name"])
enum_name: name @output
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/function_const_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ SemverQuery(
... on Function {
visibility_limit @filter(op: "=", value: ["$public"]) @output
const @filter(op: "=", value: ["$true"])
name @output @tag
importable_path {
path @output @tag
Expand All @@ -24,7 +23,7 @@ SemverQuery(
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
const @filter(op: "!=", value: ["$true"])
importable_path {
Expand Down
3 changes: 1 addition & 2 deletions src/lints/function_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SemverQuery(
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output @tag
name @output
importable_path {
path @output @tag
Expand All @@ -28,7 +28,6 @@ SemverQuery(
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/function_must_use_added.ron
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ SemverQuery(
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
name @tag @output
name @output
importable_path {
path @tag @output
Expand All @@ -38,7 +38,6 @@ SemverQuery(
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @filter(op: "=", value: ["%name"])
importable_path {
path @filter(op: "=", value: ["%path"])
Expand Down
3 changes: 1 addition & 2 deletions src/lints/function_parameter_count_changed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ SemverQuery(
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"]) @output
name @output @tag
importable_path {
path @output @tag
Expand All @@ -25,7 +24,7 @@ SemverQuery(
item {
... on Function {
visibility_limit @filter(op: "=", value: ["$public"])
name @filter(op: "=", value: ["%name"])
name @output
current_parameter_: parameter @fold @transform(op: "count") @filter(op: "!=", value: ["%parameters"]) @output
Expand Down
Loading

0 comments on commit 7d18362

Please sign in to comment.