Patch variance bug: appearing in a binding is an invariant position (at least right now).

This commit is contained in:
Niko Matsakis 2015-01-12 10:20:14 -05:00
parent 47c2d31038
commit 7bd19112ee
2 changed files with 30 additions and 0 deletions

View File

@ -818,6 +818,12 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
trait_def.generics.regions.get_slice(subst::TypeSpace),
trait_ref.substs(),
variance);
let projections = data.projection_bounds_with_self_ty(self.tcx(),
self.tcx().types.err);
for projection in projections.iter() {
self.add_constraints_from_ty(generics, projection.0.ty, self.invariant);
}
}
ty::ty_param(ref data) => {

View File

@ -0,0 +1,24 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that Cell is considered invariant with respect to its
// type.
use std::cell::Cell;
// For better or worse, associated types are invariant, and hence we
// get an invariant result for `'a`.
#[rustc_variance]
struct Foo<'a> { //~ ERROR regions=[[o];[];[]]
x: Box<Fn(i32) -> &'a i32 + 'static>
}
fn main() {
}