summaryrefslogtreecommitdiffstats
path: root/tests/ui/regions/regions-variance-contravariant-use-contravariant.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/regions/regions-variance-contravariant-use-contravariant.rs')
-rw-r--r--tests/ui/regions/regions-variance-contravariant-use-contravariant.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/tests/ui/regions/regions-variance-contravariant-use-contravariant.rs b/tests/ui/regions/regions-variance-contravariant-use-contravariant.rs
new file mode 100644
index 000000000..e63778670
--- /dev/null
+++ b/tests/ui/regions/regions-variance-contravariant-use-contravariant.rs
@@ -0,0 +1,27 @@
+// run-pass
+#![allow(dead_code)]
+#![allow(unused_variables)]
+// Test that a type which is contravariant with respect to its region
+// parameter compiles successfully when used in a contravariant way.
+//
+// Note: see ui/variance/variance-regions-*.rs for the tests that check that the
+// variance inference works in the first place.
+
+// pretty-expanded FIXME #23616
+
+struct Contravariant<'a> {
+ f: &'a isize
+}
+
+fn use_<'a>(c: Contravariant<'a>) {
+ let x = 3;
+
+ // 'b winds up being inferred to this call.
+ // Contravariant<'a> <: Contravariant<'call> is true
+ // if 'call <= 'a, which is true, so no error.
+ collapse(&x, c);
+
+ fn collapse<'b>(x: &'b isize, c: Contravariant<'b>) { }
+}
+
+pub fn main() {}