-
Notifications
You must be signed in to change notification settings - Fork 13k
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: don't crash when an external trait's docs needs to import another trait #48415
rustdoc: don't crash when an external trait's docs needs to import another trait #48415
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
r=me but needs a test |
The test I had was pub trait Foo {
/// [x](::Bar)
fn foo();
}
pub trait Bar {
/// [x](::Foo)
fn foo();
} and then pub use aux::Foo;
pub use aux::Bar; |
I have a test at https://github.com/manishearth/rust/tree/rustdoc-trait-ice , but haven't run it yet |
The test i wrote up was: /// Woah, this trait links to [OtherTrait](OtherTrait)!
pub trait SomeTrait {}
/// Woah, this trait links to [SomeTrait](SomeTrait)!
pub trait OtherTrait {} #[doc(inline)]
pub use issue_48414::{SomeTrait, OtherTrait}; ...which still stack-overflows. |
wooooooooooo |
It turns out, i wrote a |
@bors r+ |
📌 Commit 8872e7b has been approved by |
…-traits, r=Manishearth rustdoc: don't crash when an external trait's docs needs to import another trait Fixes rust-lang#48414 When resolving intra-paths for an item, rustdoc needs to have information about their items on hand, for proper bookkeeping. When loading a path for an external item, it needs to load these items from their host crate, since their information isn't otherwise available. This includes resolving paths for those docs. which can cause this process to recurse. Rustdoc keeps a map of external traits in a `RefCell<HashMap<DefId, Trait>>`, and it keeps a borrow of this active when importing an external trait. In the linked crash, this led to a RefCell borrow error, panic, and ICE. This PR manually releases the borrow while importing the trait, and also keeps a list of traits being imported at the given moment. The latter keeps rustdoc from infinitely recursing as it tries to import the same trait repeatedly.
Fixes #48414
When resolving intra-paths for an item, rustdoc needs to have information about their items on hand, for proper bookkeeping. When loading a path for an external item, it needs to load these items from their host crate, since their information isn't otherwise available. This includes resolving paths for those docs. which can cause this process to recurse. Rustdoc keeps a map of external traits in a
RefCell<HashMap<DefId, Trait>>
, and it keeps a borrow of this active when importing an external trait. In the linked crash, this led to a RefCell borrow error, panic, and ICE.This PR manually releases the borrow while importing the trait, and also keeps a list of traits being imported at the given moment. The latter keeps rustdoc from infinitely recursing as it tries to import the same trait repeatedly.