merge coercion test folders
This commit is contained in:
parent
a39c7787ba
commit
0b5007e4b7
18 changed files with 95 additions and 97 deletions
|
|
@ -1,68 +0,0 @@
|
|||
// run-pass
|
||||
#![allow(unused_braces)]
|
||||
#![allow(dead_code)]
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
// Examples from the "deref coercions" RFC, at rust-lang/rfcs#241.
|
||||
|
||||
fn use_ref<T>(_: &T) {}
|
||||
fn use_mut<T>(_: &mut T) {}
|
||||
|
||||
fn use_rc<T>(t: Rc<T>) {
|
||||
use_ref(&*t); // what you have to write today
|
||||
use_ref(&t); // what you'd be able to write
|
||||
use_ref(&&&&&&t);
|
||||
use_ref(&mut &&&&&t);
|
||||
use_ref(&&&mut &&&t);
|
||||
}
|
||||
|
||||
fn use_mut_box<T>(mut t: &mut Box<T>) {
|
||||
use_mut(&mut *t); // what you have to write today
|
||||
use_mut(t); // what you'd be able to write
|
||||
use_mut(&mut &mut &mut t);
|
||||
|
||||
use_ref(&*t); // what you have to write today
|
||||
use_ref(t); // what you'd be able to write
|
||||
use_ref(&&&&&&t);
|
||||
use_ref(&mut &&&&&t);
|
||||
use_ref(&&&mut &&&t);
|
||||
}
|
||||
|
||||
fn use_nested<T>(t: &Box<T>) {
|
||||
use_ref(&**t); // what you have to write today
|
||||
use_ref(t); // what you'd be able to write (note: recursive deref)
|
||||
use_ref(&&&&&&t);
|
||||
use_ref(&mut &&&&&t);
|
||||
use_ref(&&&mut &&&t);
|
||||
}
|
||||
|
||||
fn use_slice(_: &[u8]) {}
|
||||
fn use_slice_mut(_: &mut [u8]) {}
|
||||
|
||||
fn use_vec(mut v: Vec<u8>) {
|
||||
use_slice_mut(&mut v[..]); // what you have to write today
|
||||
use_slice_mut(&mut v); // what you'd be able to write
|
||||
use_slice_mut(&mut &mut &mut v);
|
||||
|
||||
use_slice(&v[..]); // what you have to write today
|
||||
use_slice(&v); // what you'd be able to write
|
||||
use_slice(&&&&&&v);
|
||||
use_slice(&mut &&&&&v);
|
||||
use_slice(&&&mut &&&v);
|
||||
}
|
||||
|
||||
fn use_vec_ref(v: &Vec<u8>) {
|
||||
use_slice(&v[..]); // what you have to write today
|
||||
use_slice(v); // what you'd be able to write
|
||||
use_slice(&&&&&&v);
|
||||
use_slice(&mut &&&&&v);
|
||||
use_slice(&&&mut &&&v);
|
||||
}
|
||||
|
||||
fn use_op_rhs(s: &mut String) {
|
||||
*s += {&String::from(" ")};
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
32
src/test/ui/coercion/coerce-overloaded-autoderef-fail.rs
Normal file
32
src/test/ui/coercion/coerce-overloaded-autoderef-fail.rs
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
fn borrow_mut<T>(x: &mut T) -> &mut T { x }
|
||||
fn borrow<T>(x: &T) -> &T { x }
|
||||
|
||||
fn borrow_mut2<T>(_: &mut T, _: &mut T) {}
|
||||
fn borrow2<T>(_: &mut T, _: &T) {}
|
||||
|
||||
fn double_mut_borrow<T>(x: &mut Box<T>) {
|
||||
let y = borrow_mut(x);
|
||||
let z = borrow_mut(x);
|
||||
//~^ ERROR cannot borrow `*x` as mutable more than once at a time
|
||||
drop((y, z));
|
||||
}
|
||||
|
||||
fn double_imm_borrow(x: &mut Box<i32>) {
|
||||
let y = borrow(x);
|
||||
let z = borrow(x);
|
||||
**x += 1;
|
||||
//~^ ERROR cannot assign to `**x` because it is borrowed
|
||||
drop((y, z));
|
||||
}
|
||||
|
||||
fn double_mut_borrow2<T>(x: &mut Box<T>) {
|
||||
borrow_mut2(x, x);
|
||||
//~^ ERROR cannot borrow `*x` as mutable more than once at a time
|
||||
}
|
||||
|
||||
fn double_borrow2<T>(x: &mut Box<T>) {
|
||||
borrow2(x, x);
|
||||
//~^ ERROR cannot borrow `*x` as mutable because it is also borrowed as immutable
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0499]: cannot borrow `*x` as mutable more than once at a time
|
||||
--> $DIR/coerce-overloaded-autoderef.rs:9:24
|
||||
--> $DIR/coerce-overloaded-autoderef-fail.rs:9:24
|
||||
|
|
||||
LL | let y = borrow_mut(x);
|
||||
| - first mutable borrow occurs here
|
||||
|
|
@ -10,7 +10,7 @@ LL | drop((y, z));
|
|||
| - first borrow later used here
|
||||
|
||||
error[E0506]: cannot assign to `**x` because it is borrowed
|
||||
--> $DIR/coerce-overloaded-autoderef.rs:17:5
|
||||
--> $DIR/coerce-overloaded-autoderef-fail.rs:17:5
|
||||
|
|
||||
LL | let y = borrow(x);
|
||||
| - borrow of `**x` occurs here
|
||||
|
|
@ -22,7 +22,7 @@ LL | drop((y, z));
|
|||
| - borrow later used here
|
||||
|
||||
error[E0499]: cannot borrow `*x` as mutable more than once at a time
|
||||
--> $DIR/coerce-overloaded-autoderef.rs:23:20
|
||||
--> $DIR/coerce-overloaded-autoderef-fail.rs:23:20
|
||||
|
|
||||
LL | borrow_mut2(x, x);
|
||||
| ----------- - ^ second mutable borrow occurs here
|
||||
|
|
@ -31,7 +31,7 @@ LL | borrow_mut2(x, x);
|
|||
| first borrow later used by call
|
||||
|
||||
error[E0502]: cannot borrow `*x` as mutable because it is also borrowed as immutable
|
||||
--> $DIR/coerce-overloaded-autoderef.rs:28:5
|
||||
--> $DIR/coerce-overloaded-autoderef-fail.rs:28:5
|
||||
|
|
||||
LL | borrow2(x, x);
|
||||
| -------^^^^-^
|
||||
|
|
@ -1,32 +1,68 @@
|
|||
fn borrow_mut<T>(x: &mut T) -> &mut T { x }
|
||||
fn borrow<T>(x: &T) -> &T { x }
|
||||
// run-pass
|
||||
#![allow(unused_braces)]
|
||||
#![allow(dead_code)]
|
||||
// pretty-expanded FIXME #23616
|
||||
|
||||
fn borrow_mut2<T>(_: &mut T, _: &mut T) {}
|
||||
fn borrow2<T>(_: &mut T, _: &T) {}
|
||||
use std::rc::Rc;
|
||||
|
||||
fn double_mut_borrow<T>(x: &mut Box<T>) {
|
||||
let y = borrow_mut(x);
|
||||
let z = borrow_mut(x);
|
||||
//~^ ERROR cannot borrow `*x` as mutable more than once at a time
|
||||
drop((y, z));
|
||||
// Examples from the "deref coercions" RFC, at rust-lang/rfcs#241.
|
||||
|
||||
fn use_ref<T>(_: &T) {}
|
||||
fn use_mut<T>(_: &mut T) {}
|
||||
|
||||
fn use_rc<T>(t: Rc<T>) {
|
||||
use_ref(&*t); // what you have to write today
|
||||
use_ref(&t); // what you'd be able to write
|
||||
use_ref(&&&&&&t);
|
||||
use_ref(&mut &&&&&t);
|
||||
use_ref(&&&mut &&&t);
|
||||
}
|
||||
|
||||
fn double_imm_borrow(x: &mut Box<i32>) {
|
||||
let y = borrow(x);
|
||||
let z = borrow(x);
|
||||
**x += 1;
|
||||
//~^ ERROR cannot assign to `**x` because it is borrowed
|
||||
drop((y, z));
|
||||
fn use_mut_box<T>(mut t: &mut Box<T>) {
|
||||
use_mut(&mut *t); // what you have to write today
|
||||
use_mut(t); // what you'd be able to write
|
||||
use_mut(&mut &mut &mut t);
|
||||
|
||||
use_ref(&*t); // what you have to write today
|
||||
use_ref(t); // what you'd be able to write
|
||||
use_ref(&&&&&&t);
|
||||
use_ref(&mut &&&&&t);
|
||||
use_ref(&&&mut &&&t);
|
||||
}
|
||||
|
||||
fn double_mut_borrow2<T>(x: &mut Box<T>) {
|
||||
borrow_mut2(x, x);
|
||||
//~^ ERROR cannot borrow `*x` as mutable more than once at a time
|
||||
fn use_nested<T>(t: &Box<T>) {
|
||||
use_ref(&**t); // what you have to write today
|
||||
use_ref(t); // what you'd be able to write (note: recursive deref)
|
||||
use_ref(&&&&&&t);
|
||||
use_ref(&mut &&&&&t);
|
||||
use_ref(&&&mut &&&t);
|
||||
}
|
||||
|
||||
fn double_borrow2<T>(x: &mut Box<T>) {
|
||||
borrow2(x, x);
|
||||
//~^ ERROR cannot borrow `*x` as mutable because it is also borrowed as immutable
|
||||
fn use_slice(_: &[u8]) {}
|
||||
fn use_slice_mut(_: &mut [u8]) {}
|
||||
|
||||
fn use_vec(mut v: Vec<u8>) {
|
||||
use_slice_mut(&mut v[..]); // what you have to write today
|
||||
use_slice_mut(&mut v); // what you'd be able to write
|
||||
use_slice_mut(&mut &mut &mut v);
|
||||
|
||||
use_slice(&v[..]); // what you have to write today
|
||||
use_slice(&v); // what you'd be able to write
|
||||
use_slice(&&&&&&v);
|
||||
use_slice(&mut &&&&&v);
|
||||
use_slice(&&&mut &&&v);
|
||||
}
|
||||
|
||||
fn use_vec_ref(v: &Vec<u8>) {
|
||||
use_slice(&v[..]); // what you have to write today
|
||||
use_slice(v); // what you'd be able to write
|
||||
use_slice(&&&&&&v);
|
||||
use_slice(&mut &&&&&v);
|
||||
use_slice(&&&mut &&&v);
|
||||
}
|
||||
|
||||
fn use_op_rhs(s: &mut String) {
|
||||
*s += {&String::from(" ")};
|
||||
}
|
||||
|
||||
pub fn main() {}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
#![feature(never_type)]
|
||||
|
||||
fn foo(x: usize, y: !, z: usize) { }
|
||||
|
||||
fn cast_a() {
|
||||
let y = {return; 22} as !;
|
||||
//~^ ERROR non-primitive cast
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
error[E0605]: non-primitive cast: `i32` as `!`
|
||||
--> $DIR/coerce-to-bang-cast.rs:6:13
|
||||
--> $DIR/coerce-to-bang-cast.rs:4:13
|
||||
|
|
||||
LL | let y = {return; 22} as !;
|
||||
| ^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
|
||||
|
||||
error[E0605]: non-primitive cast: `i32` as `!`
|
||||
--> $DIR/coerce-to-bang-cast.rs:11:13
|
||||
--> $DIR/coerce-to-bang-cast.rs:9:13
|
||||
|
|
||||
LL | let y = 22 as !;
|
||||
| ^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue