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

rustdoc panics when resolving intra doc link #93428

Closed
Shemnei opened this issue Jan 28, 2022 · 2 comments · Fixed by #93441
Closed

rustdoc panics when resolving intra doc link #93428

Shemnei opened this issue Jan 28, 2022 · 2 comments · Fixed by #93441
Assignees
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Milestone

Comments

@Shemnei
Copy link

Shemnei commented Jan 28, 2022

Running cargo +nightly doc on the crate off-rs fails with a (semi-unrelated) panic.
This currently also fails to build on docs.rs: https://docs.rs/crate/off-rs/0.1.3/builds/500166

This started to occur with the latest nightly version (rustc 1.60.0-nightly (21b4a9cfd 2022-01-27)).

Probable cause

The issue is probably related to the following doc comment line: https://github.com/michidk/off-rs/blob/6a0146d4f2cadb1e46ce8849abd0269cd97d3528/src/parser/options.rs#L7.
Specifically the intra doc link causes rustdoc to fail.

/// When these limits are exceeded during the [`parse`](`crate::parser::Parser::parse`)

When this line is replaced with the follwing (adding an anonymous lifetime) line rustdoc finishes successfully:

/// When these limits are exceeded during the [`parse`](`crate::parser::Parser::<'_>::parse`)

Minimal viable example

The example below will also panic

  • The intra doc link beeing in an extra module is important as it otherwise will not panic but succeed
  • It must be [`crate:: ...`], with [`super:: ...`] it will succeed.
pub struct Test<'a> {
    data: &'a (),
}

impl<'a> Test<'a> {
    pub fn do_test(&self) {}
}

pub mod demo {
    //! [`crate::Test::do_test`]
}

Related

Related issues:

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (21b4a9cfd 2022-01-27)
binary: rustc
commit-hash: 21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093
commit-date: 2022-01-27
host: x86_64-unknown-linux-gnu
release: 1.60.0-nightly
LLVM version: 13.0.0
Backtrace

docs.rs error: https://docs.rs/crate/off-rs/0.1.3/builds/500166

RUST_BACKTRACE=1 cargo +nightly doc:

 Documenting off-rs v0.1.3 (/home/mtx/tmp/off-rs)
thread 'rustc' panicked at 'no entry found for key', src/librustdoc/passes/collect_intra_doc_links.rs:929:16
stack backtrace:
   0: rust_begin_unwind
             at /rustc/21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093/library/std/src/panicking.rs:577:5
   1: core::panicking::panic_fmt
             at /rustc/21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093/library/core/src/panicking.rs:135:14
   2: core::panicking::panic_display
             at /rustc/21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093/library/core/src/panicking.rs:65:5
   3: core::panicking::panic_str
             at /rustc/21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093/library/core/src/panicking.rs:56:5
   4: core::option::expect_failed
             at /rustc/21b4a9cfdcbb1e76f4b36b5c3cfd64d627285093/library/core/src/option.rs:1840:5
   5: rustdoc::passes::collect_intra_doc_links::resolve_associated_trait_item
   6: <rustdoc::passes::collect_intra_doc_links::LinkCollector>::resolve_associated_item
   7: <rustdoc::passes::collect_intra_doc_links::LinkCollector>::resolve
   8: <rustdoc::passes::collect_intra_doc_links::LinkCollector>::resolve_link
   9: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_item
  10: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_inner_recur
  11: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_item
  12: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_inner_recur
  13: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_item
  14: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_inner_recur
  15: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_item
  16: rustdoc::passes::collect_intra_doc_links::collect_intra_doc_links
  17: <rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#8}>
  18: rustdoc::core::run_global_ctxt
  19: <rustc_session::session::Session>::time::<(rustdoc::clean::types::Crate, rustdoc::config::RenderOptions, rustdoc::formats::cache::Cache), rustdoc::main_options::{closure#0}::{closure#0}::{closure#1}::{closure#0}>
  20: <rustc_interface::interface::Compiler>::enter::<rustdoc::main_options::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
  21: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>::{closure#1}>
  22: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>
  23: rustdoc::main_options
  24: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustdoc::main_args::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

error: internal compiler error: unexpected panic

error: Unrecognized option: 'crate-version'

error: could not document `off-rs`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2021 --crate-type lib --crate-name off_rs src/lib.rs -o /home/mtx/tmp/off-rs/target/doc --error-format=json --json=diagnostic-rendered-ansi,artifacts,future-incompat -C metadata=d6899838058215b9 -L dependency=/home/mtx/tmp/off-rs/target/debug/deps --crate-version 0.1.3` (exit status: 1)

@Shemnei Shemnei added the C-bug Category: This is a bug. label Jan 28, 2022
@jyn514 jyn514 added the regression-from-stable-to-nightly Performance or correctness regression from stable to nightly. label Jan 28, 2022
@rustbot rustbot added the I-prioritize Issue: Indicates that prioritization has been requested for this issue. label Jan 28, 2022
@jyn514 jyn514 added A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name I-prioritize Issue: Indicates that prioritization has been requested for this issue. and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 28, 2022
@notriddle notriddle self-assigned this Jan 28, 2022
@scottlamb
Copy link

Same no entry found for key error with retina 0.6.7 and nightly locally and on docs.rs. But not only could I not track it down to a particular doc link, it still crashes after I remove all doc comments altogether (no more lines matching ^\s*//[/!] in my working copy; no #[doc("...")] either).

On rustdoc 1.60.0-nightly (6abb6385b 2022-01-26):

[slamb@slamb-workstation ~/git/retina]$ RUST_BACKTRACE=1 cargo +nightly doc
 Documenting retina v0.3.7 (/home/slamb/git/retina)
thread 'rustc' panicked at 'no entry found for key', src/librustdoc/passes/collect_intra_doc_links.rs:929:16
stack backtrace:
   0: rust_begin_unwind
             at /rustc/6abb6385b2cb7249f67b9b3ce7522527767dd907/library/std/src/panicking.rs:577:5
   1: core::panicking::panic_fmt
             at /rustc/6abb6385b2cb7249f67b9b3ce7522527767dd907/library/core/src/panicking.rs:135:14
   2: core::panicking::panic_display
             at /rustc/6abb6385b2cb7249f67b9b3ce7522527767dd907/library/core/src/panicking.rs:65:5
   3: core::panicking::panic_str
             at /rustc/6abb6385b2cb7249f67b9b3ce7522527767dd907/library/core/src/panicking.rs:56:5
   4: core::option::expect_failed
             at /rustc/6abb6385b2cb7249f67b9b3ce7522527767dd907/library/core/src/option.rs:1840:5
   5: rustdoc::passes::collect_intra_doc_links::resolve_associated_trait_item
   6: <rustdoc::passes::collect_intra_doc_links::LinkCollector>::resolve_associated_item
   7: <rustdoc::passes::collect_intra_doc_links::LinkCollector>::resolve
   8: <rustdoc::passes::collect_intra_doc_links::LinkCollector>::resolve_link
   9: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_item
  10: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_inner_recur
  11: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_item
  12: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_inner_recur
  13: <rustdoc::passes::collect_intra_doc_links::LinkCollector as rustdoc::visit::DocVisitor>::visit_item
  14: rustdoc::passes::collect_intra_doc_links::collect_intra_doc_links
  15: <rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#8}>
  16: rustdoc::core::run_global_ctxt
  17: <rustc_session::session::Session>::time::<(rustdoc::clean::types::Crate, rustdoc::config::RenderOptions, rustdoc::formats::cache::Cache), rustdoc::main_options::{closure#0}::{closure#0}::{closure#1}::{closure#0}>
  18: <rustc_interface::interface::Compiler>::enter::<rustdoc::main_options::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
  19: rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorReported>, rustc_interface::interface::create_compiler_and_run<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>::{closure#1}>
  20: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>
  21: rustdoc::main_options
  22: <scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::util::setup_callbacks_and_run_in_thread_pool_with_globals<rustdoc::main_args::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.

@camelid camelid added P-critical Critical priority and removed I-prioritize Issue: Indicates that prioritization has been requested for this issue. labels Jan 29, 2022
@camelid
Copy link
Member

camelid commented Jan 29, 2022

Assigning priority as discussed in the prioritization working group.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Jan 29, 2022
…oc-links-very-early, r=petrochenkov

rustdoc: load the set of in-scope traits for modules with no docstring

Fixes rust-lang#93428

This fix is a response to a couple of special cases related to the `module_id`, which is eventually used for trait candidates:

  * The module id is always set to the current crate, when checking `crate::`.

    Normally, the set of in-scope traits would be set in `load_links_in_attrs`, but if there are no doc comments, then that loop will never run.

  * the module id is set to the parent module, when resolving a module that is spelled like this:

        // Notice how we use an outlined doc comment here!
        // [`Test::my_fn`]
        mod something {
        }

    As with the above problem with `crate::`, we need to make sure the module gets its traits in scope resolved, even if it has no doc comments of its own.
@bors bors closed this as completed in 3903ca1 Jan 30, 2022
@camelid camelid added this to the 1.60.0 milestone Jan 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-intra-doc-links Area: Intra-doc links, the ability to link to items in docs by name C-bug Category: This is a bug. P-critical Critical priority regression-from-stable-to-nightly Performance or correctness regression from stable to nightly.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants