Skip to content

Commit f532e7d

Browse files
committed
Patch variance bug: appearing in a binding is an invariant position (at least right now).
1 parent c71a1ea commit f532e7d

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

src/librustc_typeck/variance.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -814,6 +814,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
814814
trait_def.generics.regions.get_slice(subst::TypeSpace),
815815
trait_ref.substs(),
816816
variance);
817+
818+
let projections = data.projection_bounds_with_self_ty(self.tcx(),
819+
self.tcx().types.err);
820+
for projection in projections.iter() {
821+
self.add_constraints_from_ty(generics, projection.0.ty, self.invariant);
822+
}
817823
}
818824

819825
ty::ty_param(ref data) => {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2012 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+
// Test that Cell is considered invariant with respect to its
12+
// type.
13+
14+
use std::cell::Cell;
15+
16+
// For better or worse, associated types are invariant, and hence we
17+
// get an invariant result for `'a`.
18+
#[rustc_variance]
19+
struct Foo<'a> { //~ ERROR regions=[[o];[];[]]
20+
x: Box<Fn(i32) -> &'a i32 + 'static>
21+
}
22+
23+
fn main() {
24+
}

0 commit comments

Comments
 (0)