{"id":"6dd2be052399d1fd","repo":"rust-lang/cargo","slug":"cannot-open-specified-crate-s-documentation-no-do","errorCode":null,"errorMessage":"cannot open specified crate's documentation: no documentation generated","messagePattern":"cannot open specified crate's documentation: no documentation generated","errorType":"exception","errorClass":"anyhow::Error","httpStatus":null,"severity":"error","filePath":"src/ops/cargo_doc.rs","lineNumber":67,"sourceCode":"    /// Whether to attempt to open the browser after compiling the docs\n    pub open_result: bool,\n    /// Same as `rustdoc --output-format`\n    pub output_format: OutputFormat,\n    /// Options to pass through to the compiler\n    pub compile_opts: ops::CompileOptions,\n}\n\n/// Main method for `cargo doc`.\npub fn doc(ws: &Workspace<'_>, options: &DocOptions) -> CargoResult<()> {\n    let compilation = ops::compile(ws, &options.compile_opts)?;\n\n    if ws.gctx().cli_unstable().rustdoc_mergeable_info {\n        merge_cross_crate_info(ws, &compilation)?;\n    }\n\n    if options.open_result {\n        let name = &compilation.root_crate_names.get(0).ok_or_else(|| {\n            anyhow::anyhow!(\n                \"cannot open specified crate's documentation: no documentation generated\"\n            )\n        })?;\n        let kind = options.compile_opts.build_config.single_requested_kind()?;\n\n        let path = path_by_output_format(&compilation, &kind, &name, &options.output_format);\n\n        if path.exists() {\n            util::open::open(&path, ws.gctx())?;\n        }\n    } else if ws.gctx().shell().verbosity() == Verbosity::Verbose {\n        for name in &compilation.root_crate_names {\n            for kind in &options.compile_opts.build_config.requested_kinds {\n                let path =\n                    path_by_output_format(&compilation, &kind, &name, &options.output_format);\n                if path.exists() {\n                    let mut shell = ws.gctx().shell();\n                    let link = shell.err_file_hyperlink(&path);","sourceCodeStart":49,"sourceCodeEnd":85,"githubUrl":"https://github.com/rust-lang/cargo/blob/0e07a155371a6ce88ae53a2c00df940280c09a67/src/ops/cargo_doc.rs#L49-L85","documentation":"Thrown in ops::doc (src/ops/cargo_doc.rs:65-70) when --open was requested but compilation.root_crate_names is empty, i.e. no documentation output was produced to open. Cargo then cannot find a root crate name to build the doc path.","triggerScenarios":"`cargo doc --open` when there are no targets that generate documentation (e.g. a package whose targets were all filtered out, no lib and doc disabled for bins, or a prior compile step produced no root names). The get(0) returns None and ok_or_else fires.","commonSituations":"Running `cargo doc --open` on a binary-only package with `document-private-items` off / no doc output. A combination of target filters that exclude everything. Doc generation skipped due to a separate error that left root_crate_names empty.","solutions":["Drop target filters that removed all doc-able targets, or run `cargo doc --open` with no extra filters.","Ensure the package has a library target (src/lib.rs) so docs are produced.","If documenting a binary, pass `--document-private-items` (or use -Z rustdoc flags as appropriate).","First run `cargo doc` (without --open) and confirm output appears under target/doc."],"exampleFix":"# before\ncargo doc --open --bins        # nothing to open\n\n# after\ncargo doc --open               # document the library and open it","handlingStrategy":"validation","validationCode":"// Only request --open when there is at least one documented root target.\nfn has_doc_root(pkg: &cargo::core::Package) -> bool {\n    pkg.targets().iter().any(|t| t.is_lib() || t.is_bin())\n}\n// if !members.any(has_doc_root) { skip --open }","typeGuard":"fn can_open_docs(compilation: &ops::Compilation) -> bool {\n    !compilation.root_crate_names.is_empty()\n}","tryCatchPattern":"match ops::doc(ws, &opts) {\n    Err(e) if e.to_string().contains(\"no documentation generated\") => {\n        eprintln!(\"nothing to open; drop target filters or add a [lib]\");\n        return Err(e);\n    }\n    r => r,\n}","preventionTips":["Run `cargo doc` once without --open to confirm output exists.","Ensure the package has a library target before --open."],"tags":["cargo","documentation","rustdoc","cli","doc"],"analyzedSha":"0e07a155371a6ce88ae53a2c00df940280c09a67","analyzedAt":"2026-08-06T01:46:58.334Z","schemaVersion":2}