-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Relocate tests in tests/ui
#140029
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Relocate tests in tests/ui
#140029
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Discussion: so this one is also introduced in the 2010 populate tree commit, and it kinda has been preserved all these years modulo some language changes. I believe this is some kind of "positive" smoke test of a tree of owned memory...? Originally (like back in Rust 0.8), this was tag list {
cons(int,@list);
nil;
}
fn main() {
cons(10, @cons(11, @cons(12, @nil)));
} This is also one of the OG rust syntax examples at https://brson.github.io/archaea/list.html. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 Rust’s 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))), | ||
)), | ||
); | ||
} |
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Remark: yeah, this test is because unary negation on an owned string didn't use to properly typeck, back in de4b383. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discussion: I honestly have no idea what this test is actually trying to exercise. This goes all the way back to 2010 d6b7c96.
I assume this is trying to exercise some short-circuiting behavior of
||
and&&
but the test itself makes it hard to tell.EDIT: the OG version of this Rust was
so yeah, I believe this is indeed a
||
and&&
short-circuiting test. It has a no-arg closure, presumably because back then there must've been a case where the parser confused||
and the no-arg closure form|| EXPR
or sth.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's amusing is that this is one of the listings of the archive of OG rust syntax listed at https://brson.github.io/archaea/lazy-and-or.html/.
EDIT: I realized you can actually see the dynamic evolution of this test on that listing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the analysis and sharing that interesting link! Now I understand that this test verifies short-circuiting behavior of logical operators.
I'll update the test with clearer naming and comments to better express its purpose while preserving the original functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And thanks for the historical context! That's super helpful 😁