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

Adding doc(hidden) non-defaulted item is permissible if other doc(hidden) non-defaulted items exist #997

Open
1 task
jswrenn opened this issue Nov 20, 2024 · 1 comment
Labels
A-lint Area: new or existing lint C-bug Category: doesn't meet expectations

Comments

@jswrenn
Copy link

jswrenn commented Nov 20, 2024

Which lint or lints are the issue

trait_associated_type_added

Known issues that might be causing this

  • Is the flagged item defined in another crate, or a re-export of such an item? (#638)

Steps to reproduce the bug with the above code

We are experiencing this issue with the KnownLayout trait in zerocopy, specifically from this commit: google/zerocopy@b573d83

In isolation, this bug may be reproduced by defining a trait with doc(hidden) non-defaulted items:

trait KnownLayout {
    #[doc(hidden)]
    fn only_derive_is_allowed_to_implement_this_trait()
    where
        Self: Sized;
}

Then, add an associated type:

  trait KnownLayout {
+     type MaybeUninit;
  
      #[doc(hidden)]
      fn only_derive_is_allowed_to_implement_this_trait()
      where
          Self: Sized;
  }

Actual Behaviour

cargo-semver-checks registers this delta as a breaking change.

Expected Behaviour

Because MyTrait already contains doc(hidden) non-defaulted items, its consumers have opted out of SemVer stability. In practice, this situation arises when the trait is documented as being implementable by a particular proc macro (e.g., zerocopy's KnownLayout, so no breakage occurs for any users who are respecting this contract.

Verbose Lint Output

$ cargo semver-checks check-release --package zerocopy --only-explicit-features --features __internal_use_only_features_that_work_on_stable --verbose
     Parsing zerocopy v0.8.10 (current)
             Features: __internal_use_only_features_that_work_on_stable
    Updating crates.io index
     Locking 6 packages to latest compatible versions
 Documenting zerocopy v0.8.10 (/home/ubuntu/projects/zerocopy)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.92s
      Parsed [   1.189s] (current)
     Parsing zerocopy v0.8.10 (baseline)
             Features: __internal_use_only_features_that_work_on_stable
   Compiling proc-macro2 v1.0.89
   Compiling unicode-ident v1.0.14
   Compiling zerocopy v0.8.10
   Compiling quote v1.0.37
   Compiling syn v2.0.87
   Compiling zerocopy-derive v0.8.10
 Documenting zerocopy v0.8.10
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 4.00s
      Parsed [   4.324s] (baseline)
    Checking zerocopy v0.8.10 -> v0.8.10 (no change)
    Starting 94 checks, 0 unnecessary on 72 threads
        PASS [   0.018s]       major        auto_trait_impl_removed
        PASS [   0.002s]       major        constructible_struct_adds_field
        PASS [   0.006s]       major        constructible_struct_adds_private_field
        PASS [   0.003s]       major        constructible_struct_changed_type
        PASS [   0.011s]       major        declarative_macro_missing
        PASS [   0.026s]       major        derive_trait_impl_removed
        PASS [   0.002s]       major        enum_marked_non_exhaustive
        PASS [   0.003s]       major        enum_missing
        PASS [   0.002s]       minor        enum_must_use_added
        PASS [   0.004s]       major        enum_no_repr_variant_discriminant_changed
        PASS [   0.002s]       major        enum_now_doc_hidden
        PASS [   0.005s]       major        enum_repr_int_changed
        PASS [   0.003s]       major        enum_repr_int_removed
        PASS [   0.003s]       major        enum_repr_transparent_removed
        PASS [   0.003s]       major        enum_struct_variant_field_added
        PASS [   0.003s]       major        enum_struct_variant_field_missing
        PASS [   0.003s]       major        enum_struct_variant_field_now_doc_hidden
        PASS [   0.003s]       major        enum_tuple_variant_changed_kind
        PASS [   0.004s]       major        enum_tuple_variant_field_added
        PASS [   0.003s]       major        enum_tuple_variant_field_missing
        PASS [   0.003s]       major        enum_tuple_variant_field_now_doc_hidden
        PASS [   0.003s]       major        enum_unit_variant_changed_kind
        PASS [   0.004s]       major        enum_variant_added
        PASS [   0.003s]       major        enum_variant_marked_non_exhaustive
        PASS [   0.003s]       major        enum_variant_missing
        PASS [   0.003s]       major        exported_function_changed_abi
        PASS [   0.004s]       major        function_abi_no_longer_unwind
        PASS [   0.003s]       major        function_changed_abi
        PASS [   0.002s]       major        function_const_removed
        PASS [   0.003s]       major        function_export_name_changed
        PASS [   0.003s]       major        function_missing
        PASS [   0.004s]       minor        function_must_use_added
        PASS [   0.003s]       major        function_now_doc_hidden
        PASS [   0.003s]       major        function_parameter_count_changed
        PASS [   0.003s]       major        function_unsafe_added
        PASS [   0.005s]       major        inherent_associated_const_now_doc_hidden
        PASS [   0.006s]       major        inherent_associated_pub_const_missing
        PASS [   0.015s]       major        inherent_method_const_removed
        PASS [   0.010s]       major        inherent_method_missing
        PASS [   0.011s]       minor        inherent_method_must_use_added
        PASS [   0.010s]       major        inherent_method_now_doc_hidden
        PASS [   0.017s]       major        inherent_method_unsafe_added
        PASS [   0.019s]       major        method_parameter_count_changed
        PASS [   0.002s]       major        module_missing
        PASS [   0.004s]       major        non_exhaustive_struct_changed_type
        PASS [   0.002s]       major        pub_module_level_const_missing
        PASS [   0.003s]       major        pub_module_level_const_now_doc_hidden
        PASS [   0.002s]       major        pub_static_missing
        PASS [   0.002s]       major        pub_static_mut_now_immutable
        PASS [   0.002s]       major        pub_static_now_doc_hidden
        PASS [   0.004s]       major        repr_c_removed
        PASS [   0.004s]       major        repr_packed_added
        PASS [   0.005s]       major        repr_packed_removed
        PASS [   0.008s]       major        sized_impl_removed
        PASS [   0.004s]       major        struct_marked_non_exhaustive
        PASS [   0.003s]       major        struct_missing
        PASS [   0.004s]       minor        struct_must_use_added
        PASS [   0.004s]       major        struct_now_doc_hidden
        PASS [   0.003s]       major        struct_pub_field_missing
        PASS [   0.003s]       major        struct_pub_field_now_doc_hidden
        PASS [   0.004s]       major        struct_repr_transparent_removed
        PASS [   0.004s]       major        struct_with_no_pub_fields_changed_type
        PASS [   0.004s]       major        struct_with_pub_fields_changed_type
        PASS [   0.004s]       major        trait_added_supertrait
        PASS [   0.004s]       major        trait_associated_const_added
        PASS [   0.002s]       major        trait_associated_const_default_removed
        PASS [   0.003s]       major        trait_associated_const_now_doc_hidden
        FAIL [   0.003s]       major        trait_associated_type_added
        PASS [   0.002s]       major        trait_associated_type_default_removed
        PASS [   0.003s]       major        trait_associated_type_now_doc_hidden
        PASS [   0.003s]       major        trait_method_added
        PASS [   0.005s]       major        trait_method_default_impl_removed
        PASS [   0.002s]       major        trait_method_missing
        PASS [   0.003s]       major        trait_method_now_doc_hidden
        PASS [   0.002s]       major        trait_method_unsafe_added
        PASS [   0.003s]       major        trait_method_unsafe_removed
        PASS [   0.003s]       major        trait_missing
        PASS [   0.003s]       minor        trait_must_use_added
        PASS [   0.003s]       major        trait_newly_sealed
        PASS [   0.002s]       major        trait_no_longer_object_safe
        PASS [   0.003s]       major        trait_now_doc_hidden
        PASS [   0.003s]       major        trait_removed_associated_constant
        PASS [   0.002s]       major        trait_removed_associated_type
        PASS [   0.004s]       major        trait_removed_supertrait
        PASS [   0.003s]       major        trait_unsafe_added
        PASS [   0.002s]       major        trait_unsafe_removed
        PASS [   0.001s]       major        tuple_struct_to_plain_struct
        PASS [   0.002s]       minor        type_marked_deprecated
        PASS [   0.002s]       major        union_field_missing
        PASS [   0.002s]       major        union_missing
        PASS [   0.004s]       minor        union_must_use_added
        PASS [   0.002s]       major        union_now_doc_hidden
        PASS [   0.003s]       major        union_pub_field_now_doc_hidden
        PASS [   0.003s]       major        unit_struct_changed_kind
     Checked [   0.032s] 94 checks: 93 pass, 1 fail, 0 warn, 0 skip

--- failure trait_associated_type_added: non-sealed public trait added associated type without default value ---

Description:
A non-sealed trait has gained an associated type without a default value, which breaks downstream implementations of the trait
        ref: https://doc.rust-lang.org/cargo/reference/semver.html#trait-new-item-no-default
       impl: https://github.com/obi1kenobi/cargo-semver-checks/tree/v0.36.0/src/lints/trait_associated_type_added.ron

Failed in:
  trait associated type zerocopy::KnownLayout::MaybeUninit in file /home/ubuntu/projects/zerocopy/src/lib.rs:742

     Summary semver requires new major version: 1 major and 0 minor checks failed
    Finished [   5.608s] zerocopy

Generated System Information

System information:

Software version

cargo-semver-checks 0.36.0

Operating system

Linux 5.15.0-1064-aws

Command-line

/home/ubuntu/.cargo/bin/cargo-semver-checks semver-checks --bugreport 

cargo version

> cargo -V 
cargo 1.83.0-nightly (80d82ca22 2024-09-27)

Compile time information

  • Profile: release
  • Target triple: x86_64-unknown-linux-gnu
  • Family: unix
  • OS: linux
  • Architecture: x86_64
  • Pointer width: 64
  • Endian: little
  • CPU features: fxsr,sse,sse2
  • Host: x86_64-unknown-linux-gnu

Cargo build configuration:

[build]
rustflags = ["--cfg=zerocopy_unstable"]
rustdocflags = ["--cfg=zerocopy_unstable"]

[doc]
browser = ["/home/ubuntu/.vscode-server/cli/servers/Stable-4849ca9bdf9666755eb463db297b69e5385090e3/server/bin/helpers/browser.sh"]

Build Configuration

No response

Additional Context

google/zerocopy#2055 (comment)

@obi1kenobi
Copy link
Owner

Thanks! This is an instance of a broader issue around sealed traits and SemVer. It's definitely fixable, though will require some (relatively intricate) new analysis.

I made #999 for the broader problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-lint Area: new or existing lint C-bug Category: doesn't meet expectations
Projects
None yet
Development

No branches or pull requests

2 participants