Skip to content

Commit 89afda7

Browse files
committed
Ignore bivariant parameters in test_type_match.
1 parent f8a2e49 commit 89afda7

File tree

2 files changed

+71
-2
lines changed

2 files changed

+71
-2
lines changed

Diff for: compiler/rustc_infer/src/infer/outlives/test_type_match.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -155,14 +155,17 @@ impl<'tcx> TypeRelation<'tcx> for Match<'tcx> {
155155
bug!()
156156
}
157157

158+
#[instrument(level = "trace", skip(self))]
158159
fn relate_with_variance<T: Relate<'tcx>>(
159160
&mut self,
160-
_: ty::Variance,
161+
variance: ty::Variance,
161162
_: ty::VarianceDiagInfo<'tcx>,
162163
a: T,
163164
b: T,
164165
) -> RelateResult<'tcx, T> {
165-
self.relate(a, b)
166+
// Opaque types substs have lifetime parameters.
167+
// We must not check them to be equal, as we never insert anything to make them so.
168+
if variance != ty::Bivariant { self.relate(a, b) } else { Ok(a) }
166169
}
167170

168171
#[instrument(skip(self), level = "debug")]

Diff for: src/test/ui/impl-trait/issues/issue-104815.rs

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
// check-pass
2+
3+
struct It;
4+
5+
struct Data {
6+
items: Vec<It>,
7+
}
8+
9+
impl Data {
10+
fn new() -> Self {
11+
Self {
12+
items: vec![It, It],
13+
}
14+
}
15+
16+
fn content(&self) -> impl Iterator<Item = &It> {
17+
self.items.iter()
18+
}
19+
}
20+
21+
struct Container<'a> {
22+
name: String,
23+
resolver: Box<dyn Resolver + 'a>,
24+
}
25+
26+
impl<'a> Container<'a> {
27+
fn new<R: Resolver + 'a>(name: &str, resolver: R) -> Self {
28+
Self {
29+
name: name.to_owned(),
30+
resolver: Box::new(resolver),
31+
}
32+
}
33+
}
34+
35+
trait Resolver {}
36+
37+
impl<R: Resolver> Resolver for &R {}
38+
39+
impl Resolver for It {}
40+
41+
fn get<'a>(mut items: impl Iterator<Item = &'a It>) -> impl Resolver + 'a {
42+
items.next().unwrap()
43+
}
44+
45+
fn get2<'a, 'b: 'b>(mut items: impl Iterator<Item = &'a It>) -> impl Resolver + 'a {
46+
items.next().unwrap()
47+
}
48+
49+
fn main() {
50+
let data = Data::new();
51+
let resolver = get(data.content());
52+
53+
let _ = ["a", "b"]
54+
.iter()
55+
.map(|&n| Container::new(n, &resolver))
56+
.map(|c| c.name)
57+
.collect::<Vec<_>>();
58+
59+
let resolver = get2(data.content());
60+
61+
let _ = ["a", "b"]
62+
.iter()
63+
.map(|&n| Container::new(n, &resolver))
64+
.map(|c| c.name)
65+
.collect::<Vec<_>>();
66+
}

0 commit comments

Comments
 (0)