From 6d54672acf431ceae0b057f45e0351e84793d9f2 Mon Sep 17 00:00:00 2001 From: Aaron Hill Date: Tue, 11 Dec 2018 14:18:30 -0500 Subject: Fix stack overflow when finding blanket impls Currently, SelectionContext tries to prevent stack overflow by keeping track of the current recursion depth. However, this depth tracking is only used when performing normal section (which includes confirmation). No such tracking is performed for evaluate_obligation_recursively, which can allow a stack overflow to occur. To fix this, this commit tracks the current predicate evaluation depth. This is done separately from the existing obligation depth tracking: an obligation overflow can occur across multiple calls to 'select' (e.g. when fulfilling a trait), while a predicate evaluation overflow can only happen as a result of a deep recursive call stack. Fixes #56701 --- src/test/rustdoc/issue-56701.rs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/test/rustdoc/issue-56701.rs (limited to 'src/test/rustdoc') diff --git a/src/test/rustdoc/issue-56701.rs b/src/test/rustdoc/issue-56701.rs new file mode 100644 index 00000000000..6fb30a4ff4c --- /dev/null +++ b/src/test/rustdoc/issue-56701.rs @@ -0,0 +1,34 @@ +// This shouldn't cause a stack overflow when rustdoc is run + +use std::ops::Deref; +use std::ops::DerefMut; + +pub trait SimpleTrait { + type SimpleT; +} + +impl> SimpleTrait for Outer { + type SimpleT = Inner::SimpleT; +} + +pub trait AnotherTrait { + type AnotherT; +} + +impl>> AnotherTrait for Simple { + type AnotherT = T; +} + +pub struct Unrelated>>(UnrelatedT); + +impl>> Deref for Unrelated { + type Target = Vec; + + fn deref(&self) -> &Self::Target { + &self.0 + } +} + + +pub fn main() { } + -- cgit 1.4.1-3-g733a5