diff options
| author | Niko Matsakis <niko@alum.mit.edu> | 2015-01-12 10:20:14 -0500 |
|---|---|---|
| committer | Niko Matsakis <niko@alum.mit.edu> | 2015-01-28 05:15:24 -0500 |
| commit | 7bd19112ee30925b636ebbe26de9e043b47cb67f (patch) | |
| tree | f62ea9f5f740e67dfc76838efdbb01ae5da98231 | |
| parent | 47c2d3103874b2f07d91179fc13609904cd9639b (diff) | |
| download | rust-7bd19112ee30925b636ebbe26de9e043b47cb67f.tar.gz rust-7bd19112ee30925b636ebbe26de9e043b47cb67f.zip | |
Patch variance bug: appearing in a binding is an invariant position (at least right now).
| -rw-r--r-- | src/librustc_typeck/variance.rs | 6 | ||||
| -rw-r--r-- | src/test/compile-fail/variance-object-types.rs | 24 |
2 files changed, 30 insertions, 0 deletions
diff --git a/src/librustc_typeck/variance.rs b/src/librustc_typeck/variance.rs index ed8a50110e5..63ad47ff31f 100644 --- a/src/librustc_typeck/variance.rs +++ b/src/librustc_typeck/variance.rs @@ -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) => { diff --git a/src/test/compile-fail/variance-object-types.rs b/src/test/compile-fail/variance-object-types.rs new file mode 100644 index 00000000000..972ec96f5f2 --- /dev/null +++ b/src/test/compile-fail/variance-object-types.rs @@ -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() { +} |
