From 3925b4d5c94c10f6e3cff05afcb5866d62a7235c Mon Sep 17 00:00:00 2001 From: Brian Koropoff Date: Sat, 13 Dec 2014 14:42:38 -0800 Subject: [PATCH] Add regression test for #19791 --- src/test/run-pass/type-id-higher-rank.rs | 85 ++++++++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 src/test/run-pass/type-id-higher-rank.rs diff --git a/src/test/run-pass/type-id-higher-rank.rs b/src/test/run-pass/type-id-higher-rank.rs new file mode 100644 index 0000000000000..efda7771403a3 --- /dev/null +++ b/src/test/run-pass/type-id-higher-rank.rs @@ -0,0 +1,85 @@ +// Copyright 2014 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test that type IDs correctly account for higher-rank lifetimes +// Also acts as a regression test for an ICE (issue #19791) + +#![feature(unboxed_closures)] + +use std::intrinsics::TypeId; + +fn main() { + // Bare fns + { + let a = TypeId::of::(); + let b = TypeId::of:: fn(&'static int, &'a int)>(); + let c = TypeId::of:: fn(&'a int, &'b int)>(); + let d = TypeId::of:: fn(&'b int, &'a int)>(); + assert!(a != b); + assert!(a != c); + assert!(a != d); + assert!(b != c); + assert!(b != d); + assert_eq!(c, d); + + // Make sure De Bruijn indices are handled correctly + let e = TypeId::of:: fn(fn(&'a int) -> &'a int)>(); + let f = TypeId::of:: fn(&'a int) -> &'a int)>(); + assert!(e != f); + } + // Stack closures + { + let a = TypeId::of::<|&'static int, &'static int|>(); + let b = TypeId::of:: |&'static int, &'a int|>(); + let c = TypeId::of:: |&'a int, &'b int|>(); + let d = TypeId::of:: |&'b int, &'a int|>(); + assert!(a != b); + assert!(a != c); + assert!(a != d); + assert!(b != c); + assert!(b != d); + assert_eq!(c, d); + + // Make sure De Bruijn indices are handled correctly + let e = TypeId::of:: |(|&'a int| -> &'a int)|>(); + let f = TypeId::of::<|for<'a> |&'a int| -> &'a int|>(); + assert!(e != f); + } + // Boxed unboxed closures + { + let a = TypeId::of::>(); + let b = TypeId::of:: Fn(&'static int, &'a int)>>(); + let c = TypeId::of:: Fn(&'a int, &'b int)>>(); + let d = TypeId::of:: Fn(&'b int, &'a int)>>(); + assert!(a != b); + assert!(a != c); + assert!(a != d); + assert!(b != c); + assert!(b != d); + assert_eq!(c, d); + + // Make sure De Bruijn indices are handled correctly + let e = TypeId::of:: Fn(Box &'a int>)>>(); + let f = TypeId::of:: Fn(&'a int) -> &'a int>)>>(); + assert!(e != f); + } + // Raw unboxed closures + // Note that every unboxed closure has its own anonymous type, + // so no two IDs should equal each other, even when compatible + { + let a = id(|&: _: &int, _: &int| {}); + let b = id(|&: _: &int, _: &int| {}); + assert!(a != b); + } + + fn id(_: T) -> TypeId { + TypeId::of::() + } +}