Skip to content

cargo doc cannot find library from its examples #5936

@CasperN

Description

@CasperN

I tried to have cargo doc make documentation for the examples in my crate. I expected that adding doc=true to an example declared in my cargo.toml makes this happen. Instead, cargo doc fails and cannot find the library that the examples are in.

In my example below, cargo run --example one runs successfully but cargo doc fails with

error[E0463]: can't find crate for `test_doc`
 --> examples/one.rs:1:1
  |
1 | extern crate test_doc;
  | ^^^^^^^^^^^^^^^^^^^^^^ can't find crate

error: Could not document `test_doc`.

Code:

test_doc/examples/one.rs

extern crate test_doc;
fn main() {
    test_doc::hello();
}

test_doc/src/lib.rs

pub fn hello() {
    println!("hello world");
}

test_doc/Cargo.toml

[package]
name = "test_doc"
version = "0.1.0"

[[example]]
name = "one"
doc = true

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-examplesArea: example targetsC-bugCategory: bugCommand-docS-triageStatus: This issue is waiting on initial triage.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions