|
| 1 | +// Copyright 2016 The Rust Project Developers. See the COPYRIGHT |
| 2 | +// file at the top-level directory of this distribution and at |
| 3 | +// http://rust-lang.org/COPYRIGHT. |
| 4 | +// |
| 5 | +// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or |
| 6 | +// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license |
| 7 | +// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your |
| 8 | +// option. This file may not be copied, modified, or distributed |
| 9 | +// except according to those terms. |
| 10 | + |
| 11 | +// Regression test for issue #47139: |
| 12 | +// |
| 13 | +// Coherence was encountering an (unnecessary) overflow trying to |
| 14 | +// decide if the two impls of dummy overlap. |
| 15 | +// |
| 16 | +// The overflow went something like: |
| 17 | +// |
| 18 | +// - `&'a ?T: Insertable` ? |
| 19 | +// - let ?T = Option<?U> ? |
| 20 | +// - `Option<?U>: Insertable` ? |
| 21 | +// - `Option<&'a ?U>: Insertable` ? |
| 22 | +// - `&'a ?U: Insertable` ? |
| 23 | +// |
| 24 | +// While somewhere in the middle, a projection would occur, which |
| 25 | +// broke cycle detection. |
| 26 | +// |
| 27 | +// It turned out that this cycle was being kicked off due to some |
| 28 | +// extended diagnostic attempts in coherence, so removing those |
| 29 | +// sidestepped the issue for now. |
| 30 | + |
| 31 | +#![allow(dead_code)] |
| 32 | + |
| 33 | +pub trait Insertable { |
| 34 | + type Values; |
| 35 | + |
| 36 | + fn values(self) -> Self::Values; |
| 37 | +} |
| 38 | + |
| 39 | +impl<T> Insertable for Option<T> |
| 40 | + where |
| 41 | + T: Insertable, |
| 42 | + T::Values: Default, |
| 43 | +{ |
| 44 | + type Values = T::Values; |
| 45 | + |
| 46 | + fn values(self) -> Self::Values { |
| 47 | + self.map(Insertable::values).unwrap_or_default() |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +impl<'a, T> Insertable for &'a Option<T> |
| 52 | + where |
| 53 | + Option<&'a T>: Insertable, |
| 54 | +{ |
| 55 | + type Values = <Option<&'a T> as Insertable>::Values; |
| 56 | + |
| 57 | + fn values(self) -> Self::Values { |
| 58 | + self.as_ref().values() |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +impl<'a, T> Insertable for &'a [T] |
| 63 | +{ |
| 64 | + type Values = Self; |
| 65 | + |
| 66 | + fn values(self) -> Self::Values { |
| 67 | + self |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +trait Unimplemented { } |
| 72 | + |
| 73 | +trait Dummy { } |
| 74 | + |
| 75 | +struct Foo<T> { t: T } |
| 76 | + |
| 77 | +impl<'a, U> Dummy for Foo<&'a U> |
| 78 | + where &'a U: Insertable |
| 79 | +{ |
| 80 | +} |
| 81 | + |
| 82 | +impl<T> Dummy for T |
| 83 | + where T: Unimplemented |
| 84 | +{ } |
| 85 | + |
| 86 | +fn main() { |
| 87 | +} |
0 commit comments