Skip to content

Commit 48528d8

Browse files
committed
Cleaned up 5 tests in tests/ui
1 parent f433fa4 commit 48528d8

11 files changed

+47
-25
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: tests/ui/lazy-and-or.rs

-12
This file was deleted.

Diff for: tests/ui/list.rs

-9
This file was deleted.

Diff for: tests/ui/minus-string.rs

-1
This file was deleted.

Diff for: tests/ui/or-patterns/lazy-and-or.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
//@ run-pass
2+
// This test verifies the short-circuiting behavior of logical operators `||` and `&&`.
3+
// It ensures that the right-hand expression is not evaluated when the left-hand
4+
// expression is sufficient to determine the result.
5+
6+
fn would_panic_if_called(x: &mut isize) -> bool {
7+
*x += 1;
8+
assert!(false, "This function should never be called due to short-circuiting");
9+
false
10+
}
11+
12+
fn main() {
13+
let x = 1 == 2 || 3 == 3;
14+
assert!(x);
15+
16+
let mut y: isize = 10;
17+
println!("Result of short-circuit: {}", x || would_panic_if_called(&mut y));
18+
assert_eq!(y, 10, "y should remain 10 if short-circuiting works correctly");
19+
20+
if true && x {
21+
assert!(true, "Short-circuit evaluation wored correctly");
22+
} else {
23+
assert!(false, "This branch should not be reached");
24+
}
25+
}

Diff for: tests/ui/recursion/recursive-enum-box.rs

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ run-pass
2+
// A smoke test for recursive enum structures using Box<T>.
3+
// This test constructs a linked list-like structure to verify memory allocation and ownership.
4+
// Originally introduced in 2010, this is one of Rust’s earliest test cases.
5+
6+
#![allow(non_camel_case_types)]
7+
8+
enum list { #[allow(dead_code)] cons(isize, Box<list>), nil, }
9+
10+
pub fn main() {
11+
list::cons(10, Box::new(list::cons(11, Box::new(list::cons(12, Box::new(list::nil))))));
12+
}

Diff for: tests/ui/typeck/minus-string.rs

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

Diff for: tests/ui/minus-string.stderr renamed to tests/ui/typeck/minus-string.stderr

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

0 commit comments

Comments
 (0)