Skip to content

Commit

Permalink
Do not consider #[doc(hidden)] items part of the public API. (#576)
Browse files Browse the repository at this point in the history
* Do not consider `#[doc(hidden)]` items part of the public API.

* Set `continue-on-error: true` and use nightly temporarily so that CI runs everything.

* Check whether associated items are public API as well.

* Fix deprecations query.

* Add tests for `#[doc(hidden)]` on structs, enums, variants, fields.

* Add test cases for module contents and associated items being hidden.

* Add test coverage for traits and trait associated items.

* Update to latest adapter versions and drop rustdoc v24.

* Require minimum Rust 1.71 to work.
  • Loading branch information
obi1kenobi authored Nov 8, 2023
1 parent add43f4 commit abc6a57
Show file tree
Hide file tree
Showing 92 changed files with 1,009 additions and 73 deletions.
18 changes: 11 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ jobs:
# IMPORTANT: When updating the versions here, make sure you also update
# the `fails-on-too-old-rustc` job and its error message to
# to account for the raised minimum required version.
toolchain: ["1.70", "1.71", "1.72", "stable", "beta"]
toolchain: ["1.71", "1.72", "stable", "beta"]
experimental: [false]
include:
- toolchain: "nightly"
Expand Down Expand Up @@ -330,7 +330,7 @@ jobs:
id: toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: "1.70" # Rust 1.70 uses rustdoc v24
toolchain: "1.73" # Rust 1.73 uses rustdoc v26
rustflags: ""
cache: false

Expand Down Expand Up @@ -364,11 +364,15 @@ jobs:
- name: Install newer rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: "1.72" # Rust 1.72 uses rustdoc v26
# Make sure this version matches the env var below.
toolchain: "nightly" # Rust 1.75-nightly uses rustdoc v27

rustflags: ""
cache: false

- name: Check with older rustdoc version cached
env:
NEWER_RUST_VERSION: "nightly" # Make sure this matches the version installed just above.
run: |
# Use a separate workspace, to avoid contaminating the cache for Swatinem/rust-cache@v2
cp -R subject subject-new
Expand All @@ -385,9 +389,9 @@ jobs:
export OLD_RUSTDOC_VERSION="$(jq .format_version subject-new/target/semver-checks/cache/registry-libp2p_core-0_37_0.json)"
# Run cargo-semver-checks with the older cached file.
# In a prior step, we installed stable Rust, so we'll set that as the default
# In a prior step, we installed a newer Rust, so we'll set that as the default
# for cargo-semver-checks to invoke here.
rustup override set stable
rustup override set "$NEWER_RUST_VERSION"
bins/cargo-semver-checks semver-checks check-release --manifest-path="subject-new/core/Cargo.toml" --verbose
export NEW_RUSTDOC_VERSION="$(jq .format_version subject-new/target/semver-checks/cache/registry-libp2p_core-0_37_0.json)"
Expand Down Expand Up @@ -1606,7 +1610,7 @@ jobs:
id: toolchain
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
toolchain: "1.67"
toolchain: "1.70"
rustflags: ""
cache: false

Expand Down Expand Up @@ -1649,7 +1653,7 @@ jobs:
- name: Check output
run: |
cd semver
EXPECTED="$(echo -e "Error: rustc version is not high enough: >=1.68.0 needed, got 1.67.1")"
EXPECTED="$(echo -e "Error: rustc version is not high enough: >=1.71.0 needed, got 1.70.0")"
RESULT="$(cat output | grep Error)"
diff <(echo "$RESULT") <(echo "$EXPECTED")
Expand Down
62 changes: 21 additions & 41 deletions Cargo.lock

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

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rust-version = "1.70"

[dependencies]
trustfall = "0.6.0"
trustfall_rustdoc = { version = "0.13.1", default-features = false, features = ["v24", "v26", "v27"] }
trustfall_rustdoc = { version = "0.13.1", default-features = false, features = ["v26", "v27"] }
clap = { version = "4.0.0", features = ["derive", "cargo"] }
serde_json = "1.0.82"
anyhow = "1.0.58"
Expand Down
2 changes: 1 addition & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ impl GlobalConfig {
}
})),
handlebars: make_handlebars_registry(),
minimum_rustc_version: semver::Version::new(1, 68, 0),
minimum_rustc_version: semver::Version::new(1, 71, 0),
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/lints/auto_trait_impl_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SemverQuery(
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
impl {
Expand Down Expand Up @@ -44,6 +45,7 @@ SemverQuery(
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
impl @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
Expand Down Expand Up @@ -71,6 +73,7 @@ SemverQuery(
"public": "public",
"zero": 0,
"false": false,
"true": true,
"auto_traits": [
["core", "marker", "Send"],
["core", "marker", "Sync"],
Expand Down
3 changes: 3 additions & 0 deletions src/lints/constructible_struct_adds_field.ron
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SemverQuery(
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
field {
Expand Down Expand Up @@ -52,6 +53,7 @@ SemverQuery(
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
# 2. It needs to not have had any non-public fields.
Expand All @@ -72,6 +74,7 @@ SemverQuery(
arguments: {
"public": "public",
"non_exhaustive": "#[non_exhaustive]",
"true": true,
"zero": 0,
},
error_message: "A pub struct constructible with a struct literal has a new pub field. Existing struct literals must be updated to include the new field.",
Expand Down
3 changes: 3 additions & 0 deletions src/lints/constructible_struct_adds_private_field.ron
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ SemverQuery(
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
field {
Expand Down Expand Up @@ -52,6 +53,7 @@ SemverQuery(
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
# 2. It needs to not have had any non-public fields.
Expand All @@ -72,6 +74,7 @@ SemverQuery(
arguments: {
"public": "public",
"non_exhaustive": "#[non_exhaustive]",
"true": true,
"zero": 0,
},
error_message: "A struct constructible with a struct literal has a new non-public field. It can no longer be constructed using a struct literal outside of its crate.",
Expand Down
3 changes: 3 additions & 0 deletions src/lints/constructible_struct_changed_type.ron
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ More info: https://github.com/obi1kenobi/cargo-semver-checks/issues/297
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
}
}
Expand All @@ -50,6 +51,7 @@ More info: https://github.com/obi1kenobi/cargo-semver-checks/issues/297
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
Expand All @@ -64,6 +66,7 @@ More info: https://github.com/obi1kenobi/cargo-semver-checks/issues/297
arguments: {
"public": "public",
"non_exhaustive": "#[non_exhaustive]",
"true": true,
"zero": 0,
},
error_message: "A struct became an enum or union, and is no longer publicly constructible with a struct literal.",
Expand Down
3 changes: 3 additions & 0 deletions src/lints/derive_trait_impl_removed.ron
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ SemverQuery(
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
impl {
Expand Down Expand Up @@ -52,6 +53,7 @@ SemverQuery(
importable_path @fold @transform(op: "count") @filter(op: ">", value: ["$zero"]) {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
impl @fold @transform(op: "count") @filter(op: "=", value: ["$zero"]) {
Expand Down Expand Up @@ -87,6 +89,7 @@ SemverQuery(
"public": "public",
"zero": 0,
"false": false,
"true": true,
"structural_eq": ["core", "marker", "StructuralEq"],
},
error_message: "A public type has stopped deriving one or more traits. This can break downstream code that depends on those types implementing those traits.",
Expand Down
3 changes: 3 additions & 0 deletions src/lints/enum_marked_non_exhaustive.ron
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ SemverQuery(
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
Expand All @@ -35,6 +36,7 @@ SemverQuery(
importable_path {
path @filter(op: "=", value: ["%path"])
public_api @filter(op: "=", value: ["$true"])
}
}
}
Expand All @@ -44,6 +46,7 @@ SemverQuery(
arguments: {
"public": "public",
"non_exhaustive": "#[non_exhaustive]",
"true": true,
},
error_message: "A public enum has been marked #[non_exhaustive]. Pattern-matching on it outside of its crate must now include a wildcard pattern like `_`, or it will fail to compile.",
per_result_error_template: Some("enum {{name}} in {{span_filename}}:{{span_begin_line}}"),
Expand Down
2 changes: 2 additions & 0 deletions src/lints/enum_missing.ron
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ SemverQuery(
importable_path {
path @output @tag
public_api @filter(op: "=", value: ["$true"])
}
span_: span @optional {
Expand All @@ -40,6 +41,7 @@ SemverQuery(
arguments: {
"public": "public",
"zero": 0,
"true": true,
},
error_message: "A publicly-visible enum cannot be imported by its prior path. A `pub use` may have been removed, or the enum itself may have been renamed or removed entirely.",
per_result_error_template: Some("enum {{join \"::\" path}}, previously in file {{span_filename}}:{{span_begin_line}}"),
Expand Down
Loading

0 comments on commit abc6a57

Please sign in to comment.