From d98449d110fe49355ae265623a5bbf6796525c92 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Wed, 21 Feb 2018 17:44:49 -0600 Subject: [PATCH 1/4] manually release `cx.external_traits` while building the new trait --- src/librustdoc/clean/inline.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 9aba399b3b0..c09c6eab4d2 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -494,7 +494,11 @@ 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) { + return; + } + + let trait_ = build_external_trait(cx, did); + + cx.external_traits.borrow_mut().insert(did, trait_); } From ef30a8fd1cd1efa1086a82976873490518fcb323 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Wed, 21 Feb 2018 18:33:42 -0600 Subject: [PATCH 2/4] track extern traits being inlined --- src/librustdoc/clean/inline.rs | 7 ++++++- src/librustdoc/core.rs | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index c09c6eab4d2..458c655df1d 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 81babd803a5..e5d696882ab 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(), From bca3b31ab94c49ff32758690a0eeed29fe87ccf5 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Wed, 21 Feb 2018 19:57:48 -0600 Subject: [PATCH 3/4] proper early-bail condition --- src/librustdoc/clean/inline.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/librustdoc/clean/inline.rs b/src/librustdoc/clean/inline.rs index 458c655df1d..7b0073dc65c 100644 --- a/src/librustdoc/clean/inline.rs +++ b/src/librustdoc/clean/inline.rs @@ -494,7 +494,7 @@ 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; From 8872e7b593e0e7a6c5fdf519beb878b74be994e8 Mon Sep 17 00:00:00 2001 From: QuietMisdreavus Date: Wed, 21 Feb 2018 19:58:20 -0600 Subject: [PATCH 4/4] add test for issue 48414 ICE --- src/test/rustdoc/auxiliary/issue-48414.rs | 15 +++++++++++++++ src/test/rustdoc/issue-48414.rs | 21 +++++++++++++++++++++ 2 files changed, 36 insertions(+) create mode 100644 src/test/rustdoc/auxiliary/issue-48414.rs create mode 100644 src/test/rustdoc/issue-48414.rs diff --git a/src/test/rustdoc/auxiliary/issue-48414.rs b/src/test/rustdoc/auxiliary/issue-48414.rs new file mode 100644 index 00000000000..7e0edf76f6a --- /dev/null +++ b/src/test/rustdoc/auxiliary/issue-48414.rs @@ -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 or the MIT license +// , 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 {} diff --git a/src/test/rustdoc/issue-48414.rs b/src/test/rustdoc/issue-48414.rs new file mode 100644 index 00000000000..0136f9c4759 --- /dev/null +++ b/src/test/rustdoc/issue-48414.rs @@ -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 or the MIT license +// , 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};