Skip to content

Compilation error with cargo doc and --generate-link-to-definition #107063

Closed
@fpoli

Description

@fpoli
Contributor

I tried generating the documentation with links to definitions of a crate depending on socket2:

cargo init
cargo add socket2@0.4.7
RUSTDOCFLAGS="--generate-link-to-definition -Zunstable-options" cargo +nightly-2023-01-15 doc

I expected the cargo doc above to succeed, because cargo build succeeds.

Instead, I get some compilation errors:

   Compiling libc v0.2.139
 Documenting libc v0.2.139
    Checking socket2 v0.4.7
 Documenting socket2 v0.4.7
error[E0433]: failed to resolve: could not resolve path `sys::socketpair`
   --> /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.7/src/socket.rs:172:9
    |
172 |         sys::socketpair(domain.0, ty.0, protocol)
    |         ^^^^^^^^^^^^^^^ could not resolve path `sys::socketpair`
    |
    = note: this error was originally ignored because you are running `rustdoc`
    = note: try running again with `rustc` or `cargo check` and you may get a more detailed error

error[E0433]: failed to resolve: could not resolve path `sys::keepalive_time`
    --> /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.7/src/socket.rs:1663:9
     |
1663 |         sys::keepalive_time(self.as_raw())
     |         ^^^^^^^^^^^^^^^^^^^ could not resolve path `sys::keepalive_time`
     |
     = note: this error was originally ignored because you are running `rustdoc`
     = note: try running again with `rustc` or `cargo check` and you may get a more detailed error

For more information about this error, try `rustc --explain E0433`.
error: could not document `socket2`

Meta

rustc +nightly-2023-01-15 --version --verbose:

rustc 1.68.0-nightly (afaf3e07a 2023-01-14)
binary: rustc
commit-hash: afaf3e07aaa7ca9873bdb439caec53faffa4230c
commit-date: 2023-01-14
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6

I can also reproduce this issue with +nightly:

rustc 1.68.0-nightly (b70baa4f9 2022-12-14)
binary: rustc
commit-hash: b70baa4f922a1809d79caeaeb902800c3be283b9
commit-date: 2022-12-14
host: x86_64-unknown-linux-gnu
release: 1.68.0-nightly
LLVM version: 15.0.6

Activity

albertlarsan68

albertlarsan68 commented on Jan 19, 2023

@albertlarsan68
Member

Can you try running RUSTFLAGS="--cfg doc" cargo +nightly build or share the source code please ?

fpoli

fpoli commented on Jan 19, 2023

@fpoli
ContributorAuthor

Output of RUSTFLAGS="--cfg doc" cargo +nightly build:

   Compiling libc v0.2.139
   Compiling socket2 v0.4.7
error[E0425]: cannot find function `socketpair` in module `sys`
   --> /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.7/src/socket.rs:172:14
    |
172 |         sys::socketpair(domain.0, ty.0, protocol)
    |              ^^^^^^^^^^ not found in `sys`
    |
help: consider importing this function
    |
9   | use libc::socketpair;
    |
help: if you import `socketpair`, refer to it directly
    |
172 -         sys::socketpair(domain.0, ty.0, protocol)
172 +         socketpair(domain.0, ty.0, protocol)
    |

error[E0425]: cannot find function `keepalive_time` in module `sys`
    --> /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/socket2-0.4.7/src/socket.rs:1663:14
     |
1663 |         sys::keepalive_time(self.as_raw())
     |              ^^^^^^^^^^^^^^ help: a constant with a similar name exists: `KEEPALIVE_TIME`
     |
    ::: /home/fpoli/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.139/src/unix/linux_like/mod.rs:964:1
     |
964  | pub const TCP_KEEPIDLE: ::c_int = 4;
     | ------------------------------- similarly named constant `KEEPALIVE_TIME` defined here

For more information about this error, try `rustc --explain E0425`.
error: could not compile `socket2` due to 2 previous errors

The crate is just what cargo init && cargo add socket2@0.4.7 crates. Do you need the lock file?

albertlarsan68

albertlarsan68 commented on Jan 19, 2023

@albertlarsan68
Member

This means that the bug is in the socket2 crate or in one of the dependencies, try searching for similar issues in their issue tracker or reporting it to them.

fpoli

fpoli commented on Jan 19, 2023

@fpoli
ContributorAuthor

This means that the bug is in the socket2 crate or in one of the dependencies, try searching for similar issues in their issue tracker or reporting it to them.

Thanks. I'll do that.

albertlarsan68

albertlarsan68 commented on Jan 19, 2023

@albertlarsan68
Member

However, what is more concerning is this output:

964  | pub const TCP_KEEPIDLE: ::c_int = 4;
     | ------------------------------- similarly named constant `KEEPALIVE_TIME` defined here
fpoli

fpoli commented on Jan 19, 2023

@fpoli
ContributorAuthor

Oh, that's indeed weird. It's probably because socket2 imports the constant with a different name.

use libc::TCP_KEEPIDLE as KEEPALIVE_TIME;
albertlarsan68

albertlarsan68 commented on Jan 19, 2023

@albertlarsan68
Member

It seems related to #21934

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @fpoli@albertlarsan68

        Issue actions

          Compilation error with cargo doc and --generate-link-to-definition · Issue #107063 · rust-lang/rust