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

Infinite loop in get_all_import_attributes #107350

Closed
Jake-Shadle opened this issue Jan 27, 2023 · 3 comments · Fixed by #107357
Closed

Infinite loop in get_all_import_attributes #107350

Jake-Shadle opened this issue Jan 27, 2023 · 3 comments · Fixed by #107357
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

@Jake-Shadle
Copy link

I tried this code:

pub mod oops {
    pub use crate::oops::OhNo;

    mod inner {
        pub enum OhNo {
            Item = 1,
        }
    }

    pub use inner::*;
}

I expected to see this happen: rustdoc successfully documents our code

Instead, this happened: rustdoc infinitely loops inside get_all_import_attributes

Meta

rustc --version --verbose:

rustc 1.67.0 (fc594f156 2023-01-24)
binary: rustc
commit-hash: fc594f15669680fa70d255faec3ca3fb507c3405
commit-date: 2023-01-24
host: x86_64-unknown-linux-gnu
release: 1.67.0
LLVM version: 15.0.6
Backtrace

 thread #2, name = 'rustc', stop reason = signal SIGSTOP
    frame #0: 0x00007f1856b981ed librustc_driver-2e8cbd5b30733393.so`<rustc_middle::hir::map::Map>::get_if_local + 461
    frame #1: 0x00005623c1409031 rustdoc`rustdoc::clean::get_all_import_attributes + 145
    frame #2: 0x00005623c13861f5 rustdoc`<rustdoc::core::DocContext>::with_param_env::<alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::clean::clean_maybe_renamed_item::{closure#1}> + 3205
    frame #3: 0x00005623c13f5c2c rustdoc`<&mut rustdoc::clean::clean_doc_module::{closure#2} as core::ops::function::FnOnce<(&(&rustc_hir::hir::Item, core::option::Option<rustc_span::symbol::Symbol>, core::option::Option<rustc_hir::hir_id::HirId>),)>>::call_once + 188
    frame #4: 0x00005623c121c154 rustdoc`<alloc::vec::Vec<rustdoc::clean::types::Item> as alloc::vec::spec_extend::SpecExtend<rustdoc::clean::types::Item, core::iter::adapters::flatten::FlatMap<core::slice::iter::Iter<(&rustc_hir::hir::Item, core::option::Option<rustc_span::symbol::Symbol>, core::option::Option<rustc_hir::hir_id::HirId>)>, alloc::vec::Vec<rustdoc::clean::types::Item>, rustdoc::clean::clean_doc_module::{closure#2}>>>::spec_extend + 596
    frame #5: 0x00005623c13fa862 rustdoc`rustdoc::clean::clean_doc_module + 370
    frame #6: 0x00005623c13f548b rustdoc`<&mut rustdoc::clean::clean_doc_module::{closure#1} as core::ops::function::FnMut<(&rustdoc::visit_ast::Module,)>>::call_mut + 267
    frame #7: 0x00005623c121b62e rustdoc`<alloc::vec::Vec<rustdoc::clean::types::Item> as alloc::vec::spec_extend::SpecExtend<rustdoc::clean::types::Item, core::iter::adapters::filter_map::FilterMap<core::slice::iter::Iter<rustdoc::visit_ast::Module>, rustdoc::clean::clean_doc_module::{closure#1}>>>::spec_extend + 94
    frame #8: 0x00005623c13fa813 rustdoc`rustdoc::clean::clean_doc_module + 291
    frame #9: 0x00005623c11359be rustdoc`rustdoc::clean::utils::krate + 2718
    frame #10: 0x00005623c12ecb24 rustdoc`<rustc_session::session::Session>::time::<rustdoc::clean::types::Crate, rustdoc::core::run_global_ctxt::{closure#4}> + 116
    frame #11: 0x00005623c138b7b4 rustdoc`rustdoc::core::run_global_ctxt + 2228
    frame #12: 0x00005623c12eec54 rustdoc`<rustc_interface::passes::QueryContext>::enter::<rustdoc::main_args::{closure#1}::{closure#0}::{closure#1}, core::result::Result<(), rustc_errors::ErrorGuaranteed>> + 468
    frame #13: 0x00005623c115253a rustdoc`<rustc_interface::interface::Compiler>::enter::<rustdoc::main_args::{closure#1}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>> + 714
    frame #14: 0x00005623c128d20a rustdoc`rustc_span::with_source_map::<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}::{closure#0}> + 458
    frame #15: 0x00005623c1254615 rustdoc`<scoped_tls::ScopedKey<rustc_span::SessionGlobals>>::set::<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>> + 1493
    frame #16: 0x00005623c129e8f0 rustdoc`std::sys_common::backtrace::__rust_begin_short_backtrace::<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>> + 128
    frame #17: 0x00005623c13f18ff rustdoc`<<std::thread::Builder>::spawn_unchecked_<rustc_interface::util::run_in_thread_pool_with_globals<rustc_interface::interface::run_compiler<core::result::Result<(), rustc_errors::ErrorGuaranteed>, rustdoc::main_args::{closure#1}>::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#0}::{closure#0}, core::result::Result<(), rustc_errors::ErrorGuaranteed>>::{closure#1} as core::ops::function::FnOnce<()>>::call_once::{shim:vtable#0} + 207
    frame #18: 0x00007f1855572803 libstd-2a15b3cd0948397b.so`std::sys::unix::thread::Thread::new::thread_start::h1541b4390bbc26ca [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::ha93239d92e7b610d at boxed.rs:2000:9
    frame #19: 0x00007f18555727fd libstd-2a15b3cd0948397b.so`std::sys::unix::thread::Thread::new::thread_start::h1541b4390bbc26ca [inlined] _$LT$alloc..boxed..Box$LT$F$C$A$GT$$u20$as$u20$core..ops..function..FnOnce$LT$Args$GT$$GT$::call_once::hebda57b0236de612 at boxed.rs:2000:9
    frame #20: 0x00007f18555727f6 libstd-2a15b3cd0948397b.so`std::sys::unix::thread::Thread::new::thread_start::h1541b4390bbc26ca at thread.rs:108:17
    frame #21: 0x00007f185531412d libc.so.6`start_thread + 717
    frame #22: 0x00007f1855395bc0 libc.so.6`__clone3 + 48

@Jake-Shadle Jake-Shadle added the C-bug Category: This is a bug. label Jan 27, 2023
@GuillaumeGomez GuillaumeGomez added the T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. label Jan 27, 2023
@GuillaumeGomez
Copy link
Member

It was fixed in 1.68 apparently since I get this with beta and nightly:

error[E0432]: unresolved import `inner`
  --> bar.rs:12:13
   |
12 |     pub use inner::*;
   |             ^^^^^ help: a similar path exists: `self::inner`

error[E0432]: unresolved import `crate::oops::OhNo`
 --> bar.rs:4:13
  |
4 |     pub use crate::oops::OhNo;
  |             ^^^^^^^^^^^^^^^^^ no `OhNo` in `oops`
  |
help: consider importing this enum instead
  |
4 |     pub use oops::inner::OhNo;
  |             ~~~~~~~~~~~~~~~~~

error: Compilation failed, aborting rustdoc

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0432`.

I'll add a regression test just in case.

@GuillaumeGomez
Copy link
Member

GuillaumeGomez commented Jan 27, 2023

Ah nevermind, with this code (added a self:: as suggested by the error) I can trigger the infinite loop:

pub mod oops {
    pub use crate::oops::OhNo;

    mod inner {
        pub enum OhNo {
            Item = 1,
        }
    }

    pub use self::inner::*;
}

I think I know what's wrong. Fix should arrive shortly.

@GuillaumeGomez
Copy link
Member

Fix is in #107357.

@bors bors closed this as completed in c64f4c4 Jan 27, 2023
Mark-Simulacrum pushed a commit to Mark-Simulacrum/rust that referenced this issue Feb 14, 2023
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.

2 participants