diff options
Diffstat (limited to '')
-rw-r--r-- | src/test/ui/regions/regions-variance-invariant-use-contravariant.rs | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/test/ui/regions/regions-variance-invariant-use-contravariant.rs b/src/test/ui/regions/regions-variance-invariant-use-contravariant.rs new file mode 100644 index 000000000..a81aaa9c7 --- /dev/null +++ b/src/test/ui/regions/regions-variance-invariant-use-contravariant.rs @@ -0,0 +1,24 @@ +// Test that an invariant region parameter used in a contravariant way +// yields an error. +// +// Note: see variance-regions-*.rs for the tests that check that the +// variance inference works in the first place. + +struct Invariant<'a> { + f: &'a mut &'a isize +} + +fn use_<'short,'long>(c: Invariant<'long>, + s: &'short isize, + l: &'long isize, + _where:Option<&'short &'long ()>) { + + // Test whether Invariant<'long> <: Invariant<'short>. Since + // 'short <= 'long, this would be true if the Invariant type were + // contravariant with respect to its parameter 'a. + + let _: Invariant<'short> = c; + //~^ ERROR lifetime may not live long enough +} + +fn main() { } |