Skip to content

Commit c48f46b

Browse files
committed
add regression test
Fixes #47139
1 parent da569fa commit c48f46b

File tree

2 files changed

+162
-0
lines changed

2 files changed

+162
-0
lines changed

src/test/run-pass/issue-47139-1.rs

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
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+
}

src/test/run-pass/issue-47139-2.rs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
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+
// Same as issue-47139-1.rs, but the impls of dummy are in the
14+
// opposite order. This influenced the way that coherence ran and in
15+
// some cases caused the overflow to occur when it wouldn't otherwise.
16+
// In an effort to make the regr test more robust, I am including both
17+
// orderings.
18+
19+
#![allow(dead_code)]
20+
21+
pub trait Insertable {
22+
type Values;
23+
24+
fn values(self) -> Self::Values;
25+
}
26+
27+
impl<T> Insertable for Option<T>
28+
where
29+
T: Insertable,
30+
T::Values: Default,
31+
{
32+
type Values = T::Values;
33+
34+
fn values(self) -> Self::Values {
35+
self.map(Insertable::values).unwrap_or_default()
36+
}
37+
}
38+
39+
impl<'a, T> Insertable for &'a Option<T>
40+
where
41+
Option<&'a T>: Insertable,
42+
{
43+
type Values = <Option<&'a T> as Insertable>::Values;
44+
45+
fn values(self) -> Self::Values {
46+
self.as_ref().values()
47+
}
48+
}
49+
50+
impl<'a, T> Insertable for &'a [T]
51+
{
52+
type Values = Self;
53+
54+
fn values(self) -> Self::Values {
55+
self
56+
}
57+
}
58+
59+
trait Unimplemented { }
60+
61+
trait Dummy { }
62+
63+
struct Foo<T> { t: T }
64+
65+
impl<T> Dummy for T
66+
where T: Unimplemented
67+
{ }
68+
69+
impl<'a, U> Dummy for Foo<&'a U>
70+
where &'a U: Insertable
71+
{
72+
}
73+
74+
fn main() {
75+
}

0 commit comments

Comments
 (0)