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

could not find markdown in source in cargo doc from comments in proc macro #92789

Closed
ids1024 opened this issue Jan 11, 2022 · 3 comments · Fixed by #94478
Closed

could not find markdown in source in cargo doc from comments in proc macro #92789

ids1024 opened this issue Jan 11, 2022 · 3 comments · Fixed by #94478
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Comments

@ids1024
Copy link
Contributor

ids1024 commented Jan 11, 2022

Invoking this proc macro and running cargo doc rusults in a crash the the error could not find markdown in source:

#[proc_macro]
pub fn foo(_: TokenStream) -> TokenStream {
    "/// https://foobar.com\npub struct Foo;".parse().unwrap()
}

If this code were written directly rather than generated by a proc macro, this would produce warning: this URL is not a hyperlink. But I guess when it goes through a proc macro it can't generate correct span information for the warning and crashes.

I originally noticed this with the schemafy::schemafy! macro.

Meta

rustc --version --verbose:

rustc 1.60.0-nightly (89b9f7b28 2022-01-10)
Backtrace

thread 'rustc' panicked at 'could not find markdown in source', src/librustdoc/passes/mod.rs:181:48
stack backtrace:
   0: rust_begin_unwind
             at /rustc/89b9f7b284aacc5f8613438b80e4dd7bdd10549e/library/std/src/panicking.rs:498:5
   1: core::panicking::panic_fmt
             at /rustc/89b9f7b284aacc5f8613438b80e4dd7bdd10549e/library/core/src/panicking.rs:110:14
   2: core::panicking::panic_display
             at /rustc/89b9f7b284aacc5f8613438b80e4dd7bdd10549e/library/core/src/panicking.rs:65:5
   3: core::panicking::panic_str
             at /rustc/89b9f7b284aacc5f8613438b80e4dd7bdd10549e/library/core/src/panicking.rs:56:5
   4: core::option::expect_failed
             at /rustc/89b9f7b284aacc5f8613438b80e4dd7bdd10549e/library/core/src/option.rs:1817:5
   5: rustdoc::passes::source_span_for_markdown_range
   6: <rustdoc::passes::bare_urls::BareUrlsLinter as rustdoc::visit::DocVisitor>::visit_item
   7: <rustdoc::passes::bare_urls::BareUrlsLinter as rustdoc::visit::DocVisitor>::visit_inner_recur
   8: <rustdoc::passes::bare_urls::BareUrlsLinter as rustdoc::visit::DocVisitor>::visit_item
   9: rustdoc::passes::bare_urls::check_bare_urls
  10: <rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#8}>
  11: rustdoc::core::run_global_ctxt
  12: <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}>
  13: <rustc_interface::passes::QueryContext>::enter::<rustdoc::main_options::{closure#0}::{closure#0}::{closure#1}, core::result::Result<(), rustc_errors::ErrorReported>>
  14: <rustc_interface::interface::Compiler>::enter::<rustdoc::main_options::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorReported>>
  15: 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}>
  16: rustc_interface::interface::create_compiler_and_run::<core::result::Result<(), rustc_errors::ErrorReported>, rustdoc::main_options::{closure#0}>
  17: rustdoc::main_options
  18: <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 `proc-macro-bug`

Caused by:
  process didn't exit successfully: `rustdoc --edition=2021 --crate-type lib --crate-name proc_macro_bug src/lib.rs -o /home/ian/src/proc-macro-bug/target/doc --error-format=json --json=diagnostic-rendered-ansi,future-incompat -C metadata=f8594ed8329b26d0 -L dependency=/home/ian/src/proc-macro-bug/target/debug/deps --extern macros=/home/ian/src/proc-macro-bug/target/debug/deps/libmacros-4807c026ed1d48b2.so --crate-version 0.1.0` (exit status: 1)

@ids1024 ids1024 added the C-bug Category: This is a bug. label Jan 11, 2022
@camelid camelid added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 25, 2022
@toksdotdev
Copy link

Were you able to resolve this? Also ran into a similar issue when using the schemafy proc maco.

@ids1024
Copy link
Contributor Author

ids1024 commented Feb 28, 2022

I couldn't seem to work around it by adding an #[allow], so I've just edited the schema file.

@GuillaumeGomez
Copy link
Member

I have a fix for this issue in #94478.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this issue Mar 1, 2022
…a-doc-link, r=notriddle

Fix panic when handling intra doc links generated from macro

Fixes rust-lang#78591.
Fixes rust-lang#92789.

r? `@notriddle`
@bors bors closed this as completed in 64e16d3 Mar 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants