]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/type-check-pointer-comparisons.rs
Rollup merge of #83807 - sjakobi:77548-remove-ignore-annotations, r=Mark-Simulacrum
[rust.git] / src / test / ui / nll / type-check-pointer-comparisons.rs
1 #![feature(nll)]
2
3 // Check that we assert that pointers have a common subtype for comparisons
4
5 fn compare_const<'a, 'b>(x: *const &mut &'a i32, y: *const &mut &'b i32) {
6     x == y;
7     //~^ ERROR lifetime may not live long enough
8     //~| ERROR lifetime may not live long enough
9 }
10
11 fn compare_mut<'a, 'b>(x: *mut &'a i32, y: *mut &'b i32) {
12     x == y;
13     //~^ ERROR lifetime may not live long enough
14     //~| ERROR lifetime may not live long enough
15 }
16
17 fn compare_fn_ptr<'a, 'b, 'c>(f: fn(&'c mut &'a i32), g: fn(&'c mut &'b i32)) {
18     f == g;
19     //~^ ERROR lifetime may not live long enough
20     //~| ERROR lifetime may not live long enough
21 }
22
23 fn compare_hr_fn_ptr<'a>(f: fn(&'a i32), g: fn(&i32)) {
24     // Ideally this should compile with the operands swapped as well, but HIR
25     // type checking prevents it (and stops compilation) for now.
26     f == g; // OK
27 }
28
29 fn compare_const_fn_ptr<'a>(f: *const fn(&'a i32), g: *const fn(&i32)) {
30     f == g; // OK
31 }
32
33 fn main() {}