diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index c09c6eab4d25..458c655df1d8 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -494,11 +494,16 @@ fn separate_supertrait_bounds(mut g: clean::Generics) } pub fn record_extern_trait(cx: &DocContext, did: DefId) { - if cx.external_traits.borrow().contains_key(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); } diff --git a/src/librustdoc/core.rs b/src/librustdoc/core.rs index 81babd803a5e..e5d696882ab8 100644 --- a/src/librustdoc/core.rs +++ b/src/librustdoc/core.rs @@ -58,6 +58,9 @@ pub struct DocContext<'a, 'tcx: 'a, 'rcx: 'a> { pub renderinfo: RefCell, /// Later on moved through `clean::Crate` into `html::render::CACHE_KEY` pub external_traits: RefCell>, + /// Used while populating `external_traits` to ensure we don't process the same trait twice at + /// the same time. + pub active_extern_traits: RefCell>, // The current set of type and lifetime substitutions, // for expanding type aliases at the HIR level: @@ -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(),