Skip to content

Commit f6859b0

Browse files
pnkfelixbrson
authored andcommitted
Some tests to check that lifetime parametric fn's do not trip up LLVM.
1 parent 45d365a commit f6859b0

File tree

2 files changed

+54
-0
lines changed

2 files changed

+54
-0
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// This tests for an ICE (and, if ignored, subsequent LLVM abort) when
12+
// a lifetime-parametric fn is passed into a context whose expected
13+
// type has a differing lifetime parameterization.
14+
15+
struct A<'a> {
16+
_a: &'a i32,
17+
}
18+
19+
fn call<T>(s: T, functions: &Vec<for <'n> fn(&'n T)>) {
20+
for function in functions {
21+
function(&s);
22+
}
23+
}
24+
25+
fn f(a: &A) { println!("a holds {}", a._a); }
26+
27+
fn main() {
28+
let a = A { _a: &10 };
29+
30+
let vec: Vec<for <'u,'v> fn(&'u A<'v>)> = vec![f];
31+
call(a, &vec);
32+
}

Diff for: src/test/run-pass/issue-36744-without-calls.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Tests for an LLVM abort when storing a lifetime-parametric fn into
12+
// context that is expecting one that is not lifetime-parametric
13+
// (i.e. has no `for <'_>`).
14+
15+
pub struct A<'a>(&'a ());
16+
pub struct S<T>(T);
17+
18+
pub fn bad<'s>(v: &mut S<fn(A<'s>)>, y: S<for<'b> fn(A<'b>)>) {
19+
*v = y;
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)