Rollup merge of #140029 - reddevilmidzy:move-test, r=jieyouxu

Relocate tests in `tests/ui`

Part of #133895

Moved tests from a top-level directory into a more appropriate subdirectory.
If there is anything else that could be improved, please let me know!

r? jieyouxu
This commit is contained in:
Chris Denton 2025-04-21 15:55:58 +00:00 committed by GitHub
commit f8c67c6d15
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 56 additions and 25 deletions

View file

@ -1,12 +0,0 @@
//@ run-pass
fn incr(x: &mut isize) -> bool { *x += 1; assert!((false)); return false; }
pub fn main() {
let x = 1 == 2 || 3 == 3;
assert!((x));
let mut y: isize = 10;
println!("{}", x || incr(&mut y));
assert_eq!(y, 10);
if true && x { assert!((true)); } else { assert!((false)); }
}

View file

@ -1,9 +0,0 @@
//@ run-pass
#![allow(non_camel_case_types)]
enum list { #[allow(dead_code)] cons(isize, Box<list>), nil, }
pub fn main() {
list::cons(10, Box::new(list::cons(11, Box::new(list::cons(12, Box::new(list::nil))))));
}

View file

@ -1 +0,0 @@
fn main() { -"foo".to_string(); } //~ ERROR cannot apply unary operator `-` to type `String`

View file

@ -0,0 +1,25 @@
//@ run-pass
// This test verifies the short-circuiting behavior of logical operators `||` and `&&`.
// It ensures that the right-hand expression is not evaluated when the left-hand
// expression is sufficient to determine the result.
fn would_panic_if_called(x: &mut isize) -> bool {
*x += 1;
assert!(false, "This function should never be called due to short-circuiting");
false
}
fn main() {
let x = 1 == 2 || 3 == 3;
assert!(x);
let mut y: isize = 10;
println!("Result of short-circuit: {}", x || would_panic_if_called(&mut y));
assert_eq!(y, 10, "y should remain 10 if short-circuiting works correctly");
if true && x {
assert!(true);
} else {
assert!(false, "This branch should not be reached");
}
}

View file

@ -0,0 +1,21 @@
//@ run-pass
// A smoke test for recursive enum structures using Box<T>.
// This test constructs a linked list-like structure to exercise memory allocation and ownership.
// Originally introduced in 2010, this is one of Rusts earliest test cases.
#![allow(dead_code)]
enum List {
Cons(isize, Box<List>),
Nil,
}
fn main() {
List::Cons(
10,
Box::new(List::Cons(
11,
Box::new(List::Cons(12, Box::new(List::Nil))),
)),
);
}

View file

@ -0,0 +1,7 @@
// Regression test for issue #813.
// This ensures that the unary negation operator `-` cannot be applied to an owned `String`.
// Previously, due to a type-checking bug, this was mistakenly accepted by the compiler.
fn main() {
-"foo".to_string(); //~ ERROR cannot apply unary operator `-` to type `String`
}

View file

@ -1,8 +1,8 @@
error[E0600]: cannot apply unary operator `-` to type `String`
--> $DIR/minus-string.rs:1:13
--> $DIR/minus-string.rs:6:5
|
LL | fn main() { -"foo".to_string(); }
| ^^^^^^^^^^^^^^^^^^ cannot apply unary operator `-`
LL | -"foo".to_string();
| ^^^^^^^^^^^^^^^^^^ cannot apply unary operator `-`
|
note: the foreign item type `String` doesn't implement `Neg`
--> $SRC_DIR/alloc/src/string.rs:LL:COL