about summary refs log tree commit diff
diff options
context:
space:
mode:
authorKivooeo <Kivooeo123@gmail.com>2025-06-30 00:05:58 +0500
committerKivooeo <Kivooeo123@gmail.com>2025-07-01 15:16:56 +0500
commitda5c6395dad7c5be33f842c3660ae2f6af287f3a (patch)
treeecdab72d5ce57382b83a6abcce3e2a693ba5a192
parent4feb5de34c1e41da0c10e149e243a25a6eafcd17 (diff)
downloadrust-da5c6395dad7c5be33f842c3660ae2f6af287f3a.tar.gz
rust-da5c6395dad7c5be33f842c3660ae2f6af287f3a.zip
cleaned up some tests
-rw-r--r--tests/ui/cast/non-primitive-cast-suggestion.fixed11
-rw-r--r--tests/ui/cast/non-primitive-cast-suggestion.rs11
-rw-r--r--tests/ui/cast/non-primitive-cast-suggestion.stderr10
-rw-r--r--tests/ui/closures/closure-clone-requires-captured-clone.rs20
-rw-r--r--tests/ui/closures/closure-clone-requires-captured-clone.stderr22
-rw-r--r--tests/ui/consts/array-repeat-expr-not-const.rs6
-rw-r--r--tests/ui/consts/array-repeat-expr-not-const.stderr6
-rw-r--r--tests/ui/cross-crate/auxiliary/unexported-type-error-message.rs (renamed from tests/ui/cross-crate/auxiliary/noexporttypelib.rs)0
-rw-r--r--tests/ui/cross-crate/unexported-type-error-message.rs6
-rw-r--r--tests/ui/cross-crate/unexported-type-error-message.stderr14
-rw-r--r--tests/ui/drop/field-replace-in-struct-with-drop.rs48
-rw-r--r--tests/ui/no_std/no-core-edition2018-syntax.rs18
-rw-r--r--tests/ui/no_std/no-core-with-explicit-std-core.rs8
-rw-r--r--tests/ui/threads-sendsync/rc-is-not-send.rs30
-rw-r--r--tests/ui/threads-sendsync/rc-is-not-send.stderr24
15 files changed, 132 insertions, 102 deletions
diff --git a/tests/ui/cast/non-primitive-cast-suggestion.fixed b/tests/ui/cast/non-primitive-cast-suggestion.fixed
index cb5591dbb9d..9a1a3c022c7 100644
--- a/tests/ui/cast/non-primitive-cast-suggestion.fixed
+++ b/tests/ui/cast/non-primitive-cast-suggestion.fixed
@@ -1,8 +1,14 @@
+//! Test that casting non-primitive types with `as` is rejected with a helpful suggestion.
+//!
+//! You can't use `as` to cast between non-primitive types, even if they have
+//! `From`/`Into` implementations. The compiler should suggest using `From::from()`
+//! or `.into()` instead, and rustfix should be able to apply the suggestion.
+
 //@ run-rustfix
 
 #[derive(Debug)]
 struct Foo {
-    x: isize
+    x: isize,
 }
 
 impl From<Foo> for isize {
@@ -12,5 +18,6 @@ impl From<Foo> for isize {
 }
 
 fn main() {
-    println!("{}", isize::from(Foo { x: 1 })); //~ ERROR non-primitive cast: `Foo` as `isize` [E0605]
+    let _ = isize::from(Foo { x: 1 });
+    //~^ ERROR non-primitive cast: `Foo` as `isize` [E0605]
 }
diff --git a/tests/ui/cast/non-primitive-cast-suggestion.rs b/tests/ui/cast/non-primitive-cast-suggestion.rs
index 27429b44cd0..79006f4ba26 100644
--- a/tests/ui/cast/non-primitive-cast-suggestion.rs
+++ b/tests/ui/cast/non-primitive-cast-suggestion.rs
@@ -1,8 +1,14 @@
+//! Test that casting non-primitive types with `as` is rejected with a helpful suggestion.
+//!
+//! You can't use `as` to cast between non-primitive types, even if they have
+//! `From`/`Into` implementations. The compiler should suggest using `From::from()`
+//! or `.into()` instead, and rustfix should be able to apply the suggestion.
+
 //@ run-rustfix
 
 #[derive(Debug)]
 struct Foo {
-    x: isize
+    x: isize,
 }
 
 impl From<Foo> for isize {
@@ -12,5 +18,6 @@ impl From<Foo> for isize {
 }
 
 fn main() {
-    println!("{}", Foo { x: 1 } as isize); //~ ERROR non-primitive cast: `Foo` as `isize` [E0605]
+    let _ = Foo { x: 1 } as isize;
+    //~^ ERROR non-primitive cast: `Foo` as `isize` [E0605]
 }
diff --git a/tests/ui/cast/non-primitive-cast-suggestion.stderr b/tests/ui/cast/non-primitive-cast-suggestion.stderr
index 834d4ea241c..bd35ded15a4 100644
--- a/tests/ui/cast/non-primitive-cast-suggestion.stderr
+++ b/tests/ui/cast/non-primitive-cast-suggestion.stderr
@@ -1,13 +1,13 @@
 error[E0605]: non-primitive cast: `Foo` as `isize`
-  --> $DIR/nonscalar-cast.rs:15:20
+  --> $DIR/non-primitive-cast-suggestion.rs:21:13
    |
-LL |     println!("{}", Foo { x: 1 } as isize);
-   |                    ^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
+LL |     let _ = Foo { x: 1 } as isize;
+   |             ^^^^^^^^^^^^^^^^^^^^^ an `as` expression can only be used to convert between primitive types or to coerce to a specific trait object
    |
 help: consider using the `From` trait instead
    |
-LL -     println!("{}", Foo { x: 1 } as isize);
-LL +     println!("{}", isize::from(Foo { x: 1 }));
+LL -     let _ = Foo { x: 1 } as isize;
+LL +     let _ = isize::from(Foo { x: 1 });
    |
 
 error: aborting due to 1 previous error
diff --git a/tests/ui/closures/closure-clone-requires-captured-clone.rs b/tests/ui/closures/closure-clone-requires-captured-clone.rs
index 976e3b9e81c..80938e50b67 100644
--- a/tests/ui/closures/closure-clone-requires-captured-clone.rs
+++ b/tests/ui/closures/closure-clone-requires-captured-clone.rs
@@ -1,13 +1,19 @@
-//@compile-flags: --diagnostic-width=300
-// Check that closures do not implement `Clone` if their environment is not `Clone`.
+//! Test that closures only implement `Clone` if all captured values implement `Clone`.
+//!
+//! When a closure captures variables from its environment, it can only be cloned
+//! if all those captured variables are cloneable. This test makes sure the compiler
+//! properly rejects attempts to clone closures that capture non-Clone types.
 
-struct S(i32);
+//@ compile-flags: --diagnostic-width=300
+
+struct NonClone(i32);
 
 fn main() {
-    let a = S(5);
-    let hello = move || {
-        println!("Hello {}", a.0);
+    let captured_value = NonClone(5);
+    let closure = move || {
+        let _ = captured_value.0;
     };
 
-    let hello = hello.clone(); //~ ERROR the trait bound `S: Clone` is not satisfied
+    closure.clone();
+    //~^ ERROR the trait bound `NonClone: Clone` is not satisfied
 }
diff --git a/tests/ui/closures/closure-clone-requires-captured-clone.stderr b/tests/ui/closures/closure-clone-requires-captured-clone.stderr
index 0c95a99d0c0..785cc8a3032 100644
--- a/tests/ui/closures/closure-clone-requires-captured-clone.stderr
+++ b/tests/ui/closures/closure-clone-requires-captured-clone.stderr
@@ -1,21 +1,21 @@
-error[E0277]: the trait bound `S: Clone` is not satisfied in `{closure@$DIR/not-clone-closure.rs:8:17: 8:24}`
-  --> $DIR/not-clone-closure.rs:12:23
+error[E0277]: the trait bound `NonClone: Clone` is not satisfied in `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`
+  --> $DIR/closure-clone-requires-captured-clone.rs:17:13
    |
-LL |     let hello = move || {
-   |                 ------- within this `{closure@$DIR/not-clone-closure.rs:8:17: 8:24}`
+LL |     let closure = move || {
+   |                   ------- within this `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`
 ...
-LL |     let hello = hello.clone();
-   |                       ^^^^^ within `{closure@$DIR/not-clone-closure.rs:8:17: 8:24}`, the trait `Clone` is not implemented for `S`
+LL |     closure.clone();
+   |             ^^^^^ within `{closure@$DIR/closure-clone-requires-captured-clone.rs:13:19: 13:26}`, the trait `Clone` is not implemented for `NonClone`
    |
 note: required because it's used within this closure
-  --> $DIR/not-clone-closure.rs:8:17
+  --> $DIR/closure-clone-requires-captured-clone.rs:13:19
    |
-LL |     let hello = move || {
-   |                 ^^^^^^^
-help: consider annotating `S` with `#[derive(Clone)]`
+LL |     let closure = move || {
+   |                   ^^^^^^^
+help: consider annotating `NonClone` with `#[derive(Clone)]`
    |
 LL + #[derive(Clone)]
-LL | struct S(i32);
+LL | struct NonClone(i32);
    |
 
 error: aborting due to 1 previous error
diff --git a/tests/ui/consts/array-repeat-expr-not-const.rs b/tests/ui/consts/array-repeat-expr-not-const.rs
index 1b101d3233f..55aee7336da 100644
--- a/tests/ui/consts/array-repeat-expr-not-const.rs
+++ b/tests/ui/consts/array-repeat-expr-not-const.rs
@@ -1,7 +1,9 @@
-// Check that non constant exprs fail for array repeat syntax
+//! Arrays created with `[value; length]` syntax need the length to be known at
+//! compile time. This test makes sure the compiler rejects runtime values like
+//! function parameters in the length position.
 
 fn main() {
-    fn bar(n: usize) {
+    fn create_array(n: usize) {
         let _x = [0; n];
         //~^ ERROR attempt to use a non-constant value in a constant [E0435]
     }
diff --git a/tests/ui/consts/array-repeat-expr-not-const.stderr b/tests/ui/consts/array-repeat-expr-not-const.stderr
index c9f977fbaa4..f5761545259 100644
--- a/tests/ui/consts/array-repeat-expr-not-const.stderr
+++ b/tests/ui/consts/array-repeat-expr-not-const.stderr
@@ -1,8 +1,8 @@
 error[E0435]: attempt to use a non-constant value in a constant
-  --> $DIR/non-constant-expr-for-arr-len.rs:5:22
+  --> $DIR/array-repeat-expr-not-const.rs:7:22
    |
-LL |     fn bar(n: usize) {
-   |            - this would need to be a `const`
+LL |     fn create_array(n: usize) {
+   |                     - this would need to be a `const`
 LL |         let _x = [0; n];
    |                      ^
 
diff --git a/tests/ui/cross-crate/auxiliary/noexporttypelib.rs b/tests/ui/cross-crate/auxiliary/unexported-type-error-message.rs
index 67889cc5f65..67889cc5f65 100644
--- a/tests/ui/cross-crate/auxiliary/noexporttypelib.rs
+++ b/tests/ui/cross-crate/auxiliary/unexported-type-error-message.rs
diff --git a/tests/ui/cross-crate/unexported-type-error-message.rs b/tests/ui/cross-crate/unexported-type-error-message.rs
index 35257b20ccd..5998f0dc6e2 100644
--- a/tests/ui/cross-crate/unexported-type-error-message.rs
+++ b/tests/ui/cross-crate/unexported-type-error-message.rs
@@ -1,13 +1,13 @@
-//@ aux-build:noexporttypelib.rs
+//@ aux-build:unexported-type-error-message.rs
 
-extern crate noexporttypelib;
+extern crate unexported_type_error_message;
 
 fn main() {
     // Here, the type returned by foo() is not exported.
     // This used to cause internal errors when serializing
     // because the def_id associated with the type was
     // not convertible to a path.
-  let x: isize = noexporttypelib::foo();
+    let x: isize = unexported_type_error_message::foo();
     //~^ ERROR mismatched types
     //~| NOTE expected type `isize`
     //~| NOTE found enum `Option<isize>`
diff --git a/tests/ui/cross-crate/unexported-type-error-message.stderr b/tests/ui/cross-crate/unexported-type-error-message.stderr
index 59759b696c7..b468d9839e1 100644
--- a/tests/ui/cross-crate/unexported-type-error-message.stderr
+++ b/tests/ui/cross-crate/unexported-type-error-message.stderr
@@ -1,17 +1,17 @@
 error[E0308]: mismatched types
-  --> $DIR/noexporttypeexe.rs:10:18
+  --> $DIR/unexported-type-error-message.rs:10:20
    |
-LL |   let x: isize = noexporttypelib::foo();
-   |          -----   ^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `Option<isize>`
-   |          |
-   |          expected due to this
+LL |     let x: isize = unexported_type_error_message::foo();
+   |            -----   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `isize`, found `Option<isize>`
+   |            |
+   |            expected due to this
    |
    = note: expected type `isize`
               found enum `Option<isize>`
 help: consider using `Option::expect` to unwrap the `Option<isize>` value, panicking if the value is an `Option::None`
    |
-LL |   let x: isize = noexporttypelib::foo().expect("REASON");
-   |                                        +++++++++++++++++
+LL |     let x: isize = unexported_type_error_message::foo().expect("REASON");
+   |                                                        +++++++++++++++++
 
 error: aborting due to 1 previous error
 
diff --git a/tests/ui/drop/field-replace-in-struct-with-drop.rs b/tests/ui/drop/field-replace-in-struct-with-drop.rs
index e1d5e9c5268..8c65a4b3ad1 100644
--- a/tests/ui/drop/field-replace-in-struct-with-drop.rs
+++ b/tests/ui/drop/field-replace-in-struct-with-drop.rs
@@ -1,22 +1,17 @@
-// Issue 34101: Circa 2016-06-05, `fn inline` below issued an
-// erroneous warning from the elaborate_drops pass about moving out of
-// a field in `Foo`, which has a destructor (and thus cannot have
-// content moved out of it). The reason that the warning is erroneous
-// in this case is that we are doing a *replace*, not a move, of the
-// content in question, and it is okay to replace fields within `Foo`.
-//
-// Another more subtle problem was that the elaborate_drops was
-// creating a separate drop flag for that internally replaced content,
-// even though the compiler should enforce an invariant that any drop
-// flag for such subcontent of `Foo` will always have the same value
-// as the drop flag for `Foo` itself.
-
-
-
-
-
-
-
+//! Circa 2016-06-05, `fn inline` below issued an
+//! erroneous warning from the elaborate_drops pass about moving out of
+//! a field in `Foo`, which has a destructor (and thus cannot have
+//! content moved out of it). The reason that the warning is erroneous
+//! in this case is that we are doing a *replace*, not a move, of the
+//! content in question, and it is okay to replace fields within `Foo`.
+//!
+//! Another more subtle problem was that the elaborate_drops was
+//! creating a separate drop flag for that internally replaced content,
+//! even though the compiler should enforce an invariant that any drop
+//! flag for such subcontent of `Foo` will always have the same value
+//! as the drop flag for `Foo` itself.
+//!
+//! Regression test for <https://github.com/rust-lang/rust/issues/34101>.
 
 //@ check-pass
 
@@ -26,21 +21,20 @@ impl Drop for Foo {
     fn drop(&mut self) {}
 }
 
-fn inline() {
-    // (dummy variable so `f` gets assigned `var1` in MIR for both fn's)
+fn test_inline_replacement() {
+    // dummy variable so `f` gets assigned `var1` in MIR for both functions
     let _s = ();
     let mut f = Foo(String::from("foo"));
-    f.0 = String::from("bar");
+    f.0 = String::from("bar"); // This should not warn
 }
 
-fn outline() {
+fn test_outline_replacement() {
     let _s = String::from("foo");
     let mut f = Foo(_s);
-    f.0 = String::from("bar");
+    f.0 = String::from("bar"); // This should not warn either
 }
 
-
 fn main() {
-    inline();
-    outline();
+    test_inline_replacement();
+    test_outline_replacement();
 }
diff --git a/tests/ui/no_std/no-core-edition2018-syntax.rs b/tests/ui/no_std/no-core-edition2018-syntax.rs
index 2f55365bdd0..9a327e4c8e3 100644
--- a/tests/ui/no_std/no-core-edition2018-syntax.rs
+++ b/tests/ui/no_std/no-core-edition2018-syntax.rs
@@ -1,19 +1,27 @@
+//! Test that `#![no_core]` doesn't break modern Rust syntax in edition 2018.
+//!
+//! When you use `#![no_core]`, you lose the automatic prelude, but you can still
+//! get everything back by manually importing `use core::{prelude::v1::*, *}`.
+//! This test makes sure that after doing that, things like `for` loops and the
+//! `?` operator still work as expected.
+
 //@ run-pass
+//@ edition:2018
 
 #![allow(dead_code, unused_imports)]
 #![feature(no_core)]
 #![no_core]
-//@ edition:2018
 
-extern crate std;
 extern crate core;
-use core::{prelude::v1::*, *};
+extern crate std;
+use core::prelude::v1::*;
+use core::*;
 
-fn foo() {
+fn test_for_loop() {
     for _ in &[()] {}
 }
 
-fn bar() -> Option<()> {
+fn test_question_mark_operator() -> Option<()> {
     None?
 }
 
diff --git a/tests/ui/no_std/no-core-with-explicit-std-core.rs b/tests/ui/no_std/no-core-with-explicit-std-core.rs
index d6d2ba60445..3940bcb3aa4 100644
--- a/tests/ui/no_std/no-core-with-explicit-std-core.rs
+++ b/tests/ui/no_std/no-core-with-explicit-std-core.rs
@@ -1,11 +1,17 @@
+//! Test that you can use `#![no_core]` and still import std and core manually.
+//!
+//! The `#![no_core]` attribute disables the automatic core prelude, but you should
+//! still be able to explicitly import both `std` and `core` crates and use types
+//! like `Option` normally.
+
 //@ run-pass
 
 #![allow(stable_features)]
 #![feature(no_core, core)]
 #![no_core]
 
-extern crate std;
 extern crate core;
+extern crate std;
 
 use std::option::Option::Some;
 
diff --git a/tests/ui/threads-sendsync/rc-is-not-send.rs b/tests/ui/threads-sendsync/rc-is-not-send.rs
index 1bac5868e73..dd562e9e8f3 100644
--- a/tests/ui/threads-sendsync/rc-is-not-send.rs
+++ b/tests/ui/threads-sendsync/rc-is-not-send.rs
@@ -1,28 +1,28 @@
-use std::thread;
+//! Test that `Rc<T>` cannot be sent between threads.
+
 use std::rc::Rc;
+use std::thread;
 
 #[derive(Debug)]
 struct Port<T>(Rc<T>);
 
-fn main() {
-    #[derive(Debug)]
-    struct Foo {
-      _x: Port<()>,
-    }
+#[derive(Debug)]
+struct Foo {
+    _x: Port<()>,
+}
 
-    impl Drop for Foo {
-        fn drop(&mut self) {}
-    }
+impl Drop for Foo {
+    fn drop(&mut self) {}
+}
 
-    fn foo(x: Port<()>) -> Foo {
-        Foo {
-            _x: x
-        }
-    }
+fn foo(x: Port<()>) -> Foo {
+    Foo { _x: x }
+}
 
+fn main() {
     let x = foo(Port(Rc::new(())));
 
-    thread::spawn(move|| {
+    thread::spawn(move || {
         //~^ ERROR `Rc<()>` cannot be sent between threads safely
         let y = x;
         println!("{:?}", y);
diff --git a/tests/ui/threads-sendsync/rc-is-not-send.stderr b/tests/ui/threads-sendsync/rc-is-not-send.stderr
index 9c30261e5cb..a06b683f729 100644
--- a/tests/ui/threads-sendsync/rc-is-not-send.stderr
+++ b/tests/ui/threads-sendsync/rc-is-not-send.stderr
@@ -1,10 +1,10 @@
 error[E0277]: `Rc<()>` cannot be sent between threads safely
-  --> $DIR/no-send-res-ports.rs:25:19
+  --> $DIR/rc-is-not-send.rs:25:19
    |
-LL |       thread::spawn(move|| {
-   |       ------------- ^-----
+LL |       thread::spawn(move || {
+   |       ------------- ^------
    |       |             |
-   |  _____|_____________within this `{closure@$DIR/no-send-res-ports.rs:25:19: 25:25}`
+   |  _____|_____________within this `{closure@$DIR/rc-is-not-send.rs:25:19: 25:26}`
    | |     |
    | |     required by a bound introduced by this call
 LL | |
@@ -13,22 +13,22 @@ LL | |         println!("{:?}", y);
 LL | |     });
    | |_____^ `Rc<()>` cannot be sent between threads safely
    |
-   = help: within `{closure@$DIR/no-send-res-ports.rs:25:19: 25:25}`, the trait `Send` is not implemented for `Rc<()>`
+   = help: within `{closure@$DIR/rc-is-not-send.rs:25:19: 25:26}`, the trait `Send` is not implemented for `Rc<()>`
 note: required because it appears within the type `Port<()>`
-  --> $DIR/no-send-res-ports.rs:5:8
+  --> $DIR/rc-is-not-send.rs:7:8
    |
 LL | struct Port<T>(Rc<T>);
    |        ^^^^
 note: required because it appears within the type `Foo`
-  --> $DIR/no-send-res-ports.rs:9:12
+  --> $DIR/rc-is-not-send.rs:10:8
    |
-LL |     struct Foo {
-   |            ^^^
+LL | struct Foo {
+   |        ^^^
 note: required because it's used within this closure
-  --> $DIR/no-send-res-ports.rs:25:19
+  --> $DIR/rc-is-not-send.rs:25:19
    |
-LL |     thread::spawn(move|| {
-   |                   ^^^^^^
+LL |     thread::spawn(move || {
+   |                   ^^^^^^^
 note: required by a bound in `spawn`
   --> $SRC_DIR/std/src/thread/mod.rs:LL:COL