Skip to content

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

Merged
merged 1 commit into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 0 additions & 12 deletions tests/ui/lazy-and-or.rs

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/list.rs

This file was deleted.

1 change: 0 additions & 1 deletion tests/ui/minus-string.rs

This file was deleted.

25 changes: 25 additions & 0 deletions tests/ui/or-patterns/lazy-and-or.rs
Copy link
Member

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

fn incr(mutable &int x) -> bool {
  x += 1;
  check (false);
  ret false;
}

fn main() {

  auto x = (1 == 2) || (3 == 3);
  check (x);

  let int y = 10;
  log x || incr(y);
  check (y == 10);

  if (true && x) {
    check (true);
  } else {
    check (false);
  }

}

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.

Copy link
Member

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!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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 😁

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");
}
}
21 changes: 21 additions & 0 deletions tests/ui/recursion/recursive-enum-box.rs
Copy link
Member

Choose a reason for hiding this comment

The 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))),
)),
);
}
7 changes: 7 additions & 0 deletions tests/ui/typeck/minus-string.rs
Copy link
Member

Choose a reason for hiding this comment

The 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`
}
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Loading