introduce new subtyping
This commit is contained in:
parent
b913df06f2
commit
d9afd2bb38
16 changed files with 1015 additions and 120 deletions
27
src/test/ui/nll/relate_tys/hr-fn-aaa-as-aba.rs
Normal file
27
src/test/ui/nll/relate_tys/hr-fn-aaa-as-aba.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2017 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test that the NLL `relate_tys` code correctly deduces that a
|
||||
// function returning either argument CANNOT be upcast to one
|
||||
// that returns always its first argument.
|
||||
//
|
||||
// compile-flags:-Zno-leak-check
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
fn make_it() -> for<'a> fn(&'a u32, &'a u32) -> &'a u32 {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a: for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 = make_it();
|
||||
//~^ ERROR higher-ranked subtype error
|
||||
drop(a);
|
||||
}
|
||||
8
src/test/ui/nll/relate_tys/hr-fn-aaa-as-aba.stderr
Normal file
8
src/test/ui/nll/relate_tys/hr-fn-aaa-as-aba.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: higher-ranked subtype error
|
||||
--> $DIR/hr-fn-aaa-as-aba.rs:24:58
|
||||
|
|
||||
LL | let a: for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 = make_it();
|
||||
| ^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
38
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.rs
Normal file
38
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
// Copyright 2017 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test an interesting corner case: a fn that takes two arguments that
|
||||
// are references with the same lifetime is in fact equivalent to a fn
|
||||
// that takes two references with distinct lifetimes. This is true
|
||||
// because the two functions can call one another -- effectively, the
|
||||
// single lifetime `'a` is just inferred to be the intersection of the
|
||||
// two distinct lifetimes.
|
||||
//
|
||||
// compile-flags:-Zno-leak-check
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
use std::cell::Cell;
|
||||
|
||||
fn make_cell_aa() -> Cell<for<'a> fn(&'a u32, &'a u32)> {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn aa_eq_ab() {
|
||||
let a: Cell<for<'a, 'b> fn(&'a u32, &'b u32)> = make_cell_aa();
|
||||
//~^ ERROR higher-ranked subtype error
|
||||
//
|
||||
// FIXME -- this .. arguably ought to be accepted. However, the
|
||||
// current leak check also rejects this example, and it's kind of
|
||||
// a pain to support it. There are some comments in `relate_tys`
|
||||
drop(a);
|
||||
}
|
||||
|
||||
fn main() { }
|
||||
8
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.stderr
Normal file
8
src/test/ui/nll/relate_tys/hr-fn-aau-eq-abu.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: higher-ranked subtype error
|
||||
--> $DIR/hr-fn-aau-eq-abu.rs:29:53
|
||||
|
|
||||
LL | let a: Cell<for<'a, 'b> fn(&'a u32, &'b u32)> = make_cell_aa();
|
||||
| ^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
27
src/test/ui/nll/relate_tys/hr-fn-aba-as-aaa.rs
Normal file
27
src/test/ui/nll/relate_tys/hr-fn-aba-as-aaa.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2017 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 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// Test that the NLL `relate_tys` code correctly deduces that a
|
||||
// function returning always its first argument can be upcast to one
|
||||
// that returns either first or second argument.
|
||||
//
|
||||
// compile-pass
|
||||
// compile-flags:-Zno-leak-check
|
||||
|
||||
#![feature(nll)]
|
||||
|
||||
fn make_it() -> for<'a, 'b> fn(&'a u32, &'b u32) -> &'a u32 {
|
||||
panic!()
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a: for<'a> fn(&'a u32, &'a u32) -> &'a u32 = make_it();
|
||||
drop(a);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue