Skip to content

rustdoc: don't crash when an external trait's docs needs to import another trait #48415

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

Merged
merged 4 commits into from
Feb 25, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions src/librustdoc/clean/inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -494,7 +494,16 @@ fn separate_supertrait_bounds(mut g: clean::Generics)
}

pub fn record_extern_trait(cx: &DocContext, did: DefId) {
cx.external_traits.borrow_mut().entry(did).or_insert_with(|| {
build_external_trait(cx, did)
});
if cx.external_traits.borrow().contains_key(&did) ||
cx.active_extern_traits.borrow().contains(&did)
{
return;
}

cx.active_extern_traits.borrow_mut().push(did);

let trait_ = build_external_trait(cx, did);

cx.external_traits.borrow_mut().insert(did, trait_);
cx.active_extern_traits.borrow_mut().remove_item(&did);
}
4 changes: 4 additions & 0 deletions src/librustdoc/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> {
pub renderinfo: RefCell<RenderInfo>,
/// Later on moved through `clean::Crate` into `html::render::CACHE_KEY`
pub external_traits: RefCell<FxHashMap<DefId, clean::Trait>>,
/// Used while populating `external_traits` to ensure we don't process the same trait twice at
/// the same time.
pub active_extern_traits: RefCell<Vec<DefId>>,
// The current set of type and lifetime substitutions,
// for expanding type aliases at the HIR level:

Expand Down Expand Up @@ -236,6 +239,7 @@ pub fn run_core(search_paths: SearchPaths,
populated_all_crate_impls: Cell::new(false),
access_levels: RefCell::new(access_levels),
external_traits: Default::default(),
active_extern_traits: Default::default(),
renderinfo: Default::default(),
ty_substs: Default::default(),
lt_substs: Default::default(),
Expand Down
15 changes: 15 additions & 0 deletions src/test/rustdoc/auxiliary/issue-48414.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

/// Woah, this trait links to [OtherTrait](OtherTrait)!
pub trait SomeTrait {}

/// Woah, this trait links to [SomeTrait](SomeTrait)!
pub trait OtherTrait {}
21 changes: 21 additions & 0 deletions src/test/rustdoc/issue-48414.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// aux-build:issue-48414.rs

// ICE when resolving paths for a trait that linked to another trait, when both were in an external
// crate

#![crate_name = "base"]

extern crate issue_48414;

#[doc(inline)]
pub use issue_48414::{SomeTrait, OtherTrait};