cleaned up some tests
This commit is contained in:
parent
8afd71079a
commit
afc64242b6
8 changed files with 57 additions and 40 deletions
|
|
@ -1,25 +0,0 @@
|
|||
struct Clam {
|
||||
x: Box<isize>,
|
||||
y: Box<isize>,
|
||||
}
|
||||
|
||||
|
||||
|
||||
struct Fish {
|
||||
a: Box<isize>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a: Clam = Clam{ x: Box::new(1), y: Box::new(2) };
|
||||
let b: Clam = Clam{ x: Box::new(10), y: Box::new(20) };
|
||||
let z: isize = a.x + b.y;
|
||||
//~^ ERROR cannot add `Box<isize>` to `Box<isize>`
|
||||
println!("{}", z);
|
||||
assert_eq!(z, 21);
|
||||
let forty: Fish = Fish{ a: Box::new(40) };
|
||||
let two: Fish = Fish{ a: Box::new(2) };
|
||||
let answer: isize = forty.a + two.a;
|
||||
//~^ ERROR cannot add `Box<isize>` to `Box<isize>`
|
||||
println!("{}", answer);
|
||||
assert_eq!(answer, 42);
|
||||
}
|
||||
35
tests/ui/autoref-autoderef/autoderef-box-no-add.rs
Normal file
35
tests/ui/autoref-autoderef/autoderef-box-no-add.rs
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
//! Tests that auto-dereferencing does not allow addition of `Box<isize>` values.
|
||||
//!
|
||||
//! This test ensures that `Box<isize>` fields in structs (`Clam` and `Fish`) are not
|
||||
//! automatically dereferenced to `isize` during addition operations, as `Box<isize>`
|
||||
//! does not implement the `Add` trait.
|
||||
|
||||
struct Clam {
|
||||
x: Box<isize>,
|
||||
y: Box<isize>,
|
||||
}
|
||||
|
||||
struct Fish {
|
||||
a: Box<isize>,
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let a: Clam = Clam {
|
||||
x: Box::new(1),
|
||||
y: Box::new(2),
|
||||
};
|
||||
let b: Clam = Clam {
|
||||
x: Box::new(10),
|
||||
y: Box::new(20),
|
||||
};
|
||||
let z: isize = a.x + b.y;
|
||||
//~^ ERROR cannot add `Box<isize>` to `Box<isize>`
|
||||
println!("{}", z);
|
||||
assert_eq!(z, 21);
|
||||
let forty: Fish = Fish { a: Box::new(40) };
|
||||
let two: Fish = Fish { a: Box::new(2) };
|
||||
let answer: isize = forty.a + two.a;
|
||||
//~^ ERROR cannot add `Box<isize>` to `Box<isize>`
|
||||
println!("{}", answer);
|
||||
assert_eq!(answer, 42);
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error[E0369]: cannot add `Box<isize>` to `Box<isize>`
|
||||
--> $DIR/autoderef-full-lval.rs:15:24
|
||||
--> $DIR/autoderef-box-no-add.rs:25:24
|
||||
|
|
||||
LL | let z: isize = a.x + b.y;
|
||||
| --- ^ --- Box<isize>
|
||||
|
|
@ -13,7 +13,7 @@ note: the foreign item type `Box<isize>` doesn't implement `Add`
|
|||
= note: not implement `Add`
|
||||
|
||||
error[E0369]: cannot add `Box<isize>` to `Box<isize>`
|
||||
--> $DIR/autoderef-full-lval.rs:21:33
|
||||
--> $DIR/autoderef-box-no-add.rs:31:33
|
||||
|
|
||||
LL | let answer: isize = forty.a + two.a;
|
||||
| ------- ^ ----- Box<isize>
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
//! Tests that bare functions implement the `FnMut` trait.
|
||||
//!
|
||||
//! See <https://github.com/rust-lang/rust/issues/15448>.
|
||||
|
||||
//@ run-pass
|
||||
|
||||
fn call_f<F:FnMut()>(mut f: F) {
|
||||
|
|
@ -1,5 +1,7 @@
|
|||
//! Test that valid large numeric literals do not trigger the `overflowing_literals` lint.
|
||||
|
||||
//@ run-pass
|
||||
// Catch mistakes in the overflowing literals lint.
|
||||
|
||||
#![deny(overflowing_literals)]
|
||||
|
||||
pub fn main() {
|
||||
|
|
@ -1,8 +1,7 @@
|
|||
//! Test that method resolution does not autoderef `Vec`
|
||||
//! into a slice or perform additional autorefs.
|
||||
|
||||
fn main() {
|
||||
|
||||
// Testing that method lookup does not automatically borrow
|
||||
// vectors to slices then automatically create a self reference.
|
||||
|
||||
let mut a = vec![0];
|
||||
a.test_mut(); //~ ERROR no method named `test_mut` found
|
||||
a.test(); //~ ERROR no method named `test` found
|
||||
|
|
@ -1,12 +1,12 @@
|
|||
error[E0599]: no method named `test_mut` found for struct `Vec<{integer}>` in the current scope
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:7:7
|
||||
--> $DIR/vec-autoderef-autoref.rs:6:7
|
||||
|
|
||||
LL | a.test_mut();
|
||||
| ^^^^^^^^
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `MyIter` defines an item `test_mut`, perhaps you need to implement it
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
|
||||
--> $DIR/vec-autoderef-autoref.rs:13:1
|
||||
|
|
||||
LL | trait MyIter {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -14,40 +14,40 @@ help: there is a method `get_mut` with a similar name, but with different argume
|
|||
--> $SRC_DIR/core/src/slice/mod.rs:LL:COL
|
||||
|
||||
error[E0599]: no method named `test` found for struct `Vec<{integer}>` in the current scope
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:8:7
|
||||
--> $DIR/vec-autoderef-autoref.rs:7:7
|
||||
|
|
||||
LL | a.test();
|
||||
| ^^^^ method not found in `Vec<{integer}>`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `MyIter` defines an item `test`, perhaps you need to implement it
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
|
||||
--> $DIR/vec-autoderef-autoref.rs:13:1
|
||||
|
|
||||
LL | trait MyIter {
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error[E0599]: no method named `test` found for array `[{integer}; 1]` in the current scope
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:10:11
|
||||
--> $DIR/vec-autoderef-autoref.rs:9:11
|
||||
|
|
||||
LL | ([1]).test();
|
||||
| ^^^^ method not found in `[{integer}; 1]`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `MyIter` defines an item `test`, perhaps you need to implement it
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
|
||||
--> $DIR/vec-autoderef-autoref.rs:13:1
|
||||
|
|
||||
LL | trait MyIter {
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error[E0599]: no method named `test` found for reference `&[{integer}; 1]` in the current scope
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:11:12
|
||||
--> $DIR/vec-autoderef-autoref.rs:10:12
|
||||
|
|
||||
LL | (&[1]).test();
|
||||
| ^^^^ method not found in `&[{integer}; 1]`
|
||||
|
|
||||
= help: items from traits can only be used if the trait is implemented and in scope
|
||||
note: `MyIter` defines an item `test`, perhaps you need to implement it
|
||||
--> $DIR/auto-ref-slice-plus-ref.rs:14:1
|
||||
--> $DIR/vec-autoderef-autoref.rs:13:1
|
||||
|
|
||||
LL | trait MyIter {
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
@ -1,3 +1,5 @@
|
|||
//! Check that a bare string literal is typed as a `&'static str` and is usable.
|
||||
|
||||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
Loading…
Add table
Add a link
Reference in a new issue