Rollup merge of #141974 - Kivooeo:tf4, r=jieyouxu
`tests/ui`: A New Order [4/N] > [!NOTE] > > Intermediate commits are intended to help review, but will be squashed prior to merge. r? ``@jieyouxu`` added stderr tag for commit which means it included generated stderr
This commit is contained in:
commit
93e29190a0
13 changed files with 98 additions and 170 deletions
|
|
@ -1,13 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
pub fn main() {
|
||||
let c: char = 'x';
|
||||
let d: char = 'x';
|
||||
assert_eq!(c, 'x');
|
||||
assert_eq!('x', c);
|
||||
assert_eq!(c, c);
|
||||
assert_eq!(c, d);
|
||||
assert_eq!(d, c);
|
||||
assert_eq!(d, 'x');
|
||||
assert_eq!('x', d);
|
||||
}
|
||||
|
|
@ -1,54 +0,0 @@
|
|||
trait Noisy {
|
||||
fn speak(&mut self);
|
||||
}
|
||||
|
||||
struct Cat {
|
||||
meows : usize,
|
||||
|
||||
how_hungry : isize,
|
||||
name : String,
|
||||
}
|
||||
|
||||
impl Cat {
|
||||
pub fn eat(&mut self) -> bool {
|
||||
if self.how_hungry > 0 {
|
||||
println!("OM NOM NOM");
|
||||
self.how_hungry -= 2;
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
println!("Not hungry!");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Noisy for Cat {
|
||||
fn speak(&mut self) { self.meow(); }
|
||||
|
||||
}
|
||||
|
||||
impl Cat {
|
||||
fn meow(&mut self) {
|
||||
println!("Meow");
|
||||
self.meows += 1;
|
||||
if self.meows % 5 == 0 {
|
||||
self.how_hungry += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn cat(in_x : usize, in_y : isize, in_name: String) -> Cat {
|
||||
Cat {
|
||||
meows: in_x,
|
||||
how_hungry: in_y,
|
||||
name: in_name
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
fn main() {
|
||||
let nyan: Box<dyn Noisy> = Box::new(cat(0, 2, "nyan".to_string())) as Box<dyn Noisy>;
|
||||
nyan.eat(); //~ ERROR no method named `eat` found
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
error[E0599]: no method named `eat` found for struct `Box<dyn Noisy>` in the current scope
|
||||
--> $DIR/class-cast-to-trait.rs:53:8
|
||||
|
|
||||
LL | nyan.eat();
|
||||
| ^^^ method not found in `Box<dyn Noisy>`
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
trait Animal {
|
||||
fn eat(&self);
|
||||
}
|
||||
|
||||
struct Cat {
|
||||
meows: usize,
|
||||
}
|
||||
|
||||
impl Animal for Cat {
|
||||
//~^ ERROR not all trait items implemented, missing: `eat`
|
||||
}
|
||||
|
||||
fn cat(in_x : usize) -> Cat {
|
||||
Cat {
|
||||
meows: in_x
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let nyan = cat(0);
|
||||
}
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
error[E0046]: not all trait items implemented, missing: `eat`
|
||||
--> $DIR/class-method-missing.rs:9:1
|
||||
|
|
||||
LL | fn eat(&self);
|
||||
| -------------- `eat` from trait
|
||||
...
|
||||
LL | impl Animal for Cat {
|
||||
| ^^^^^^^^^^^^^^^^^^^ missing `eat` in implementation
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0046`.
|
||||
|
|
@ -1,60 +0,0 @@
|
|||
//@ run-pass
|
||||
|
||||
#![allow(non_snake_case)]
|
||||
#![allow(dead_code)]
|
||||
#![allow(unused_variables)]
|
||||
// Test that the lifetime of rvalues in for loops is extended
|
||||
// to the for loop itself.
|
||||
static mut FLAGS: u64 = 0;
|
||||
|
||||
struct Box<T> { f: T }
|
||||
struct AddFlags { bits: u64 }
|
||||
|
||||
fn AddFlags(bits: u64) -> AddFlags {
|
||||
AddFlags { bits: bits }
|
||||
}
|
||||
|
||||
fn arg(exp: u64, _x: &AddFlags) {
|
||||
check_flags(exp);
|
||||
}
|
||||
|
||||
fn pass<T>(v: T) -> T {
|
||||
v
|
||||
}
|
||||
|
||||
fn check_flags(exp: u64) {
|
||||
unsafe {
|
||||
let x = FLAGS;
|
||||
FLAGS = 0;
|
||||
println!("flags {}, expected {}", x, exp);
|
||||
assert_eq!(x, exp);
|
||||
}
|
||||
}
|
||||
|
||||
impl AddFlags {
|
||||
fn check_flags(&self, exp: u64) -> &AddFlags {
|
||||
check_flags(exp);
|
||||
self
|
||||
}
|
||||
|
||||
fn bits(&self) -> u64 {
|
||||
self.bits
|
||||
}
|
||||
}
|
||||
|
||||
impl Drop for AddFlags {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
FLAGS = FLAGS + self.bits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() {
|
||||
// The array containing [AddFlags] should not be dropped until
|
||||
// after the for loop:
|
||||
for x in &[AddFlags(1)] {
|
||||
check_flags(0);
|
||||
}
|
||||
check_flags(1);
|
||||
}
|
||||
33
tests/ui/drop/for-expr-temporary-drop-scope.rs
Normal file
33
tests/ui/drop/for-expr-temporary-drop-scope.rs
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
//! Check that temporaries in the for into-iterable expr are not dropped
|
||||
//! until the end of the for expr.
|
||||
|
||||
//@ run-pass
|
||||
|
||||
static mut FLAGS: u64 = 0;
|
||||
|
||||
struct AddFlags {
|
||||
bits: u64,
|
||||
}
|
||||
|
||||
impl Drop for AddFlags {
|
||||
fn drop(&mut self) {
|
||||
unsafe {
|
||||
FLAGS += self.bits;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn check_flags(expected: u64) {
|
||||
unsafe {
|
||||
let actual = FLAGS;
|
||||
FLAGS = 0;
|
||||
assert_eq!(actual, expected, "flags {}, expected {}", actual, expected);
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
for _ in &[AddFlags { bits: 1 }] {
|
||||
check_flags(0);
|
||||
}
|
||||
check_flags(1);
|
||||
}
|
||||
|
|
@ -1,3 +1,7 @@
|
|||
//! Check that trying to cast an enum with a Drop impl to an integer is rejected.
|
||||
//!
|
||||
//! Issue: <https://github.com/rust-lang/rust/issues/35941>
|
||||
|
||||
enum E {
|
||||
A = 0,
|
||||
}
|
||||
|
|
@ -1,5 +1,5 @@
|
|||
error: cannot cast enum `E` into integer `u32` because it implements `Drop`
|
||||
--> $DIR/cenum_impl_drop_cast.rs:13:13
|
||||
--> $DIR/enum-drop-cast-error.rs:17:13
|
||||
|
|
||||
LL | let i = e as u32;
|
||||
| ^^^^^^^^
|
||||
20
tests/ui/privacy/trait-object-method-error.rs
Normal file
20
tests/ui/privacy/trait-object-method-error.rs
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
//! Trait objects only allow access to methods defined in the trait.
|
||||
|
||||
trait MyTrait {
|
||||
fn trait_method(&mut self);
|
||||
}
|
||||
|
||||
struct ImplType;
|
||||
|
||||
impl MyTrait for ImplType {
|
||||
fn trait_method(&mut self) {}
|
||||
}
|
||||
|
||||
impl ImplType {
|
||||
fn struct_impl_method(&mut self) {}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let obj: Box<dyn MyTrait> = Box::new(ImplType);
|
||||
obj.struct_impl_method(); //~ ERROR no method named `struct_impl_method` found
|
||||
}
|
||||
15
tests/ui/privacy/trait-object-method-error.stderr
Normal file
15
tests/ui/privacy/trait-object-method-error.stderr
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
error[E0599]: no method named `struct_impl_method` found for struct `Box<dyn MyTrait>` in the current scope
|
||||
--> $DIR/trait-object-method-error.rs:19:9
|
||||
|
|
||||
LL | obj.struct_impl_method();
|
||||
| ^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
help: there is a method `trait_method` with a similar name
|
||||
|
|
||||
LL - obj.struct_impl_method();
|
||||
LL + obj.trait_method();
|
||||
|
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0599`.
|
||||
13
tests/ui/traits/trait-impl-missing-method.rs
Normal file
13
tests/ui/traits/trait-impl-missing-method.rs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
//! Trait impls must define all required methods.
|
||||
|
||||
trait MyTrait {
|
||||
fn trait_method(&self);
|
||||
}
|
||||
|
||||
struct ImplType;
|
||||
|
||||
impl MyTrait for ImplType {} //~ ERROR not all trait items implemented, missing: `trait_method`
|
||||
|
||||
fn main() {
|
||||
let _ = ImplType;
|
||||
}
|
||||
12
tests/ui/traits/trait-impl-missing-method.stderr
Normal file
12
tests/ui/traits/trait-impl-missing-method.stderr
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
error[E0046]: not all trait items implemented, missing: `trait_method`
|
||||
--> $DIR/trait-impl-missing-method.rs:9:1
|
||||
|
|
||||
LL | fn trait_method(&self);
|
||||
| ----------------------- `trait_method` from trait
|
||||
...
|
||||
LL | impl MyTrait for ImplType {}
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ missing `trait_method` in implementation
|
||||
|
||||
error: aborting due to 1 previous error
|
||||
|
||||
For more information about this error, try `rustc --explain E0046`.
|
||||
Loading…
Add table
Add a link
Reference in a new issue