Introduce basic Reborrow tests
This commit is contained in:
parent
fce8c13f77
commit
35bae9df1d
12 changed files with 215 additions and 0 deletions
13
tests/ui/reborrow/custom_mut.rs
Normal file
13
tests/ui/reborrow/custom_mut.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#![feature(reborrow)]
|
||||
use std::marker::Reborrow;
|
||||
|
||||
struct CustomMut<'a, T>(&'a mut T);
|
||||
impl<'a, T> Reborrow for CustomMut<'a, T> {}
|
||||
|
||||
fn method(a: CustomMut<'_, ()>) {}
|
||||
|
||||
fn main() {
|
||||
let a = CustomMut(&mut ());
|
||||
let _ = method(a);
|
||||
let _ = method(a); //~ERROR use of moved value: `a`
|
||||
}
|
||||
29
tests/ui/reborrow/custom_mut.stderr
Normal file
29
tests/ui/reborrow/custom_mut.stderr
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
error[E0382]: use of moved value: `a`
|
||||
--> $DIR/custom_mut.rs:12:20
|
||||
|
|
||||
LL | let a = CustomMut(&mut ());
|
||||
| - move occurs because `a` has type `CustomMut<'_, ()>`, which does not implement the `Copy` trait
|
||||
LL | let _ = method(a);
|
||||
| - value moved here
|
||||
LL | let _ = method(a);
|
||||
| ^ value used here after move
|
||||
|
|
||||
note: consider changing this parameter type in function `method` to borrow instead if owning the value isn't necessary
|
||||
--> $DIR/custom_mut.rs:7:14
|
||||
|
|
||||
LL | fn method(a: CustomMut<'_, ()>) {}
|
||||
| ------ ^^^^^^^^^^^^^^^^^ this parameter takes ownership of the value
|
||||
| |
|
||||
| in this function
|
||||
note: if `CustomMut<'_, ()>` implemented `Clone`, you could clone the value
|
||||
--> $DIR/custom_mut.rs:4:1
|
||||
|
|
||||
LL | struct CustomMut<'a, T>(&'a mut T);
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ consider implementing `Clone` for this type
|
||||
...
|
||||
LL | let _ = method(a);
|
||||
| - you could clone this value
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
||||
28
tests/ui/reborrow/custom_mut_coerce_shared.rs
Normal file
28
tests/ui/reborrow/custom_mut_coerce_shared.rs
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#![feature(reborrow)]
|
||||
use std::marker::{Reborrow, CoerceShared};
|
||||
|
||||
struct CustomMut<'a, T>(&'a mut T);
|
||||
impl<'a, T> Reborrow for CustomMut<'a, T> {}
|
||||
impl<'a, T> CoerceShared for CustomMut<'a, T> {
|
||||
type Target = CustomRef<'a, T>;
|
||||
}
|
||||
|
||||
struct CustomRef<'a, T>(&'a T);
|
||||
|
||||
impl<'a, T> Clone for CustomRef<'a, T> {
|
||||
fn clone(&self) -> Self {
|
||||
Self(self.0)
|
||||
}
|
||||
}
|
||||
impl<'a, T> Copy for CustomRef<'a, T> {}
|
||||
|
||||
fn method(a: CustomRef<'_, ()>) {} //~NOTE function defined here
|
||||
|
||||
fn main() {
|
||||
let a = CustomMut(&mut ());
|
||||
method(a);
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE expected `CustomRef<'_, ()>`, found `CustomMut<'_, ()>`
|
||||
//~| NOTE arguments to this function are incorrect
|
||||
//~| NOTE expected struct `CustomRef<'_, ()>`
|
||||
}
|
||||
19
tests/ui/reborrow/custom_mut_coerce_shared.stderr
Normal file
19
tests/ui/reborrow/custom_mut_coerce_shared.stderr
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/custom_mut_coerce_shared.rs:23:12
|
||||
|
|
||||
LL | method(a);
|
||||
| ------ ^ expected `CustomRef<'_, ()>`, found `CustomMut<'_, ()>`
|
||||
| |
|
||||
| arguments to this function are incorrect
|
||||
|
|
||||
= note: expected struct `CustomRef<'_, ()>`
|
||||
found struct `CustomMut<'_, ()>`
|
||||
note: function defined here
|
||||
--> $DIR/custom_mut_coerce_shared.rs:19:4
|
||||
|
|
||||
LL | fn method(a: CustomRef<'_, ()>) {}
|
||||
| ^^^^^^ --------------------
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
7
tests/ui/reborrow/option_mut.rs
Normal file
7
tests/ui/reborrow/option_mut.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
fn method(a: Option<& mut ()>) {}
|
||||
|
||||
fn main() {
|
||||
let a = Some(&mut ());
|
||||
let _ = method(a);
|
||||
let _ = method(a); //~ERROR use of moved value: `a`
|
||||
}
|
||||
21
tests/ui/reborrow/option_mut.stderr
Normal file
21
tests/ui/reborrow/option_mut.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error[E0382]: use of moved value: `a`
|
||||
--> $DIR/option_mut.rs:6:20
|
||||
|
|
||||
LL | let a = Some(&mut ());
|
||||
| - move occurs because `a` has type `Option<&mut ()>`, which does not implement the `Copy` trait
|
||||
LL | let _ = method(a);
|
||||
| - value moved here
|
||||
LL | let _ = method(a);
|
||||
| ^ value used here after move
|
||||
|
|
||||
note: consider changing this parameter type in function `method` to borrow instead if owning the value isn't necessary
|
||||
--> $DIR/option_mut.rs:1:14
|
||||
|
|
||||
LL | fn method(a: Option<& mut ()>) {}
|
||||
| ------ ^^^^^^^^^^^^^^^^ this parameter takes ownership of the value
|
||||
| |
|
||||
| in this function
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
||||
11
tests/ui/reborrow/option_mut_coerce_shared.rs
Normal file
11
tests/ui/reborrow/option_mut_coerce_shared.rs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fn method(a: Option<&()>) {} //~NOTE function defined here
|
||||
|
||||
fn main() {
|
||||
let a = Some(&mut ());
|
||||
method(a);
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE arguments to this function are incorrect
|
||||
//~| NOTE types differ in mutability
|
||||
//~| NOTE expected enum `Option<&()>`
|
||||
//~| NOTE found enum `Option<&mut ()>`
|
||||
}
|
||||
23
tests/ui/reborrow/option_mut_coerce_shared.stderr
Normal file
23
tests/ui/reborrow/option_mut_coerce_shared.stderr
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/option_mut_coerce_shared.rs:5:12
|
||||
|
|
||||
LL | method(a);
|
||||
| ------ ^ types differ in mutability
|
||||
| |
|
||||
| arguments to this function are incorrect
|
||||
|
|
||||
= note: expected enum `Option<&()>`
|
||||
found enum `Option<&mut ()>`
|
||||
note: function defined here
|
||||
--> $DIR/option_mut_coerce_shared.rs:1:4
|
||||
|
|
||||
LL | fn method(a: Option<&()>) {}
|
||||
| ^^^^^^ --------------
|
||||
help: try using `.as_deref()` to convert `Option<&mut ()>` to `Option<&()>`
|
||||
|
|
||||
LL | method(a.as_deref());
|
||||
| +++++++++++
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
10
tests/ui/reborrow/pin_mut.rs
Normal file
10
tests/ui/reborrow/pin_mut.rs
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
use std::pin::Pin;
|
||||
|
||||
fn method(a: Pin<& mut ()>) {}
|
||||
|
||||
fn main() {
|
||||
let a = &mut ();
|
||||
let a = Pin::new(a);
|
||||
let _ = method(a);
|
||||
let _ = method(a); //~ERROR use of moved value: `a`
|
||||
}
|
||||
21
tests/ui/reborrow/pin_mut.stderr
Normal file
21
tests/ui/reborrow/pin_mut.stderr
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
error[E0382]: use of moved value: `a`
|
||||
--> $DIR/pin_mut.rs:9:20
|
||||
|
|
||||
LL | let a = Pin::new(a);
|
||||
| - move occurs because `a` has type `Pin<&mut ()>`, which does not implement the `Copy` trait
|
||||
LL | let _ = method(a);
|
||||
| - value moved here
|
||||
LL | let _ = method(a);
|
||||
| ^ value used here after move
|
||||
|
|
||||
note: consider changing this parameter type in function `method` to borrow instead if owning the value isn't necessary
|
||||
--> $DIR/pin_mut.rs:3:14
|
||||
|
|
||||
LL | fn method(a: Pin<& mut ()>) {}
|
||||
| ------ ^^^^^^^^^^^^^ this parameter takes ownership of the value
|
||||
| |
|
||||
| in this function
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0382`.
|
||||
14
tests/ui/reborrow/pin_mut_coerce_shared.rs
Normal file
14
tests/ui/reborrow/pin_mut_coerce_shared.rs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
use std::pin::Pin;
|
||||
|
||||
fn method(a: Pin<&()>) {} //~NOTE function defined here
|
||||
|
||||
fn main() {
|
||||
let a = &mut ();
|
||||
let a = Pin::new(a);
|
||||
method(a);
|
||||
//~^ ERROR mismatched types
|
||||
//~| NOTE arguments to this function are incorrect
|
||||
//~| NOTE types differ in mutability
|
||||
//~| NOTE expected struct `Pin<&()>`
|
||||
//~| NOTE found struct `Pin<&mut ()>`
|
||||
}
|
||||
19
tests/ui/reborrow/pin_mut_coerce_shared.stderr
Normal file
19
tests/ui/reborrow/pin_mut_coerce_shared.stderr
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
error[E0308]: mismatched types
|
||||
--> $DIR/pin_mut_coerce_shared.rs:8:12
|
||||
|
|
||||
LL | method(a);
|
||||
| ------ ^ types differ in mutability
|
||||
| |
|
||||
| arguments to this function are incorrect
|
||||
|
|
||||
= note: expected struct `Pin<&()>`
|
||||
found struct `Pin<&mut ()>`
|
||||
note: function defined here
|
||||
--> $DIR/pin_mut_coerce_shared.rs:3:4
|
||||
|
|
||||
LL | fn method(a: Pin<&()>) {}
|
||||
| ^^^^^^ -----------
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0308`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue