about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAaron Hill <aa1ronham@gmail.com>2020-08-05 20:19:56 -0400
committerAaron Hill <aa1ronham@gmail.com>2020-08-05 20:22:55 -0400
commitab766f0511fa0a735997b2a442744af71d8e6be0 (patch)
treeccfcdcaa86f9fbbbf8648236d283dd3b8abbbd58
parentdb870ea71b6dcc7a91b999420b88f41d3cdd13e1 (diff)
downloadrust-ab766f0511fa0a735997b2a442744af71d8e6be0.tar.gz
rust-ab766f0511fa0a735997b2a442744af71d8e6be0.zip
Handle projection predicates in the param env for auto-trait docs
Fixes #72213

Any predicates in the param env are guaranteed to hold, so we don't need
to do any additional processing of them if we come across them as
sub-obligations of a different predicate. This allows us to avoid adding
the same predicate to the computed ParamEnv multiple times (but with
different regions each time), which causes an ambiguity error during
fulfillment.
-rw-r--r--src/librustc_trait_selection/traits/auto_trait.rs7
-rw-r--r--src/test/rustdoc/synthetic_auto/issue-72213-projection-lifetime.rs25
2 files changed, 32 insertions, 0 deletions
diff --git a/src/librustc_trait_selection/traits/auto_trait.rs b/src/librustc_trait_selection/traits/auto_trait.rs
index 05a0c52badb..820f8716f05 100644
--- a/src/librustc_trait_selection/traits/auto_trait.rs
+++ b/src/librustc_trait_selection/traits/auto_trait.rs
@@ -270,6 +270,13 @@ impl AutoTraitFinder<'tcx> {
     ) -> Option<(ty::ParamEnv<'tcx>, ty::ParamEnv<'tcx>)> {
         let tcx = infcx.tcx;
 
+        // Don't try to proess any nested obligations involving predicates
+        // that are already in the `ParamEnv` (modulo regions): we already
+        // know that they must hold.
+        for predicate in param_env.caller_bounds() {
+            fresh_preds.insert(self.clean_pred(infcx, predicate));
+        }
+
         let mut select = SelectionContext::with_negative(&infcx, true);
 
         let mut already_visited = FxHashSet::default();
diff --git a/src/test/rustdoc/synthetic_auto/issue-72213-projection-lifetime.rs b/src/test/rustdoc/synthetic_auto/issue-72213-projection-lifetime.rs
new file mode 100644
index 00000000000..6f66b8e5563
--- /dev/null
+++ b/src/test/rustdoc/synthetic_auto/issue-72213-projection-lifetime.rs
@@ -0,0 +1,25 @@
+// Regression test for issue #72213
+// Tests that we don't ICE when we have projection predicates
+// in our initial ParamEnv
+
+pub struct Lines<'a, L>
+where
+    L: Iterator<Item = &'a ()>,
+{
+    words: std::iter::Peekable<Words<'a, L>>,
+}
+
+pub struct Words<'a, L> {
+    _m: std::marker::PhantomData<&'a L>,
+}
+
+impl<'a, L> Iterator for Words<'a, L>
+where
+    L: Iterator<Item = &'a ()>,
+{
+    type Item = ();
+
+    fn next(&mut self) -> Option<Self::Item> {
+        unimplemented!()
+    }
+}