Skip to content

Commit 066a281

Browse files
committed
cleaned up some tests
1 parent 1549585 commit 066a281

19 files changed

+126
-68
lines changed

tests/ui/attributes/reexport-test-harness-entry-point.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Check that `#[reexport_test_harness_main]` correctly reexports the test harness entry point
2+
//! and allows it to be called from within the code.
3+
14
//@ run-pass
25
//@ compile-flags:--test
36

tests/ui/const-ptr/pointer-address-stability.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1-
//@ run-pass
2-
// Issue #2040
1+
//! Check that taking the address of a stack variable with `&`
2+
//! yields a stable and comparable pointer.
3+
//!
4+
//! Regression test for <https://github.com/rust-lang/rust/issues/2040>.
35
6+
//@ run-pass
47

58
pub fn main() {
69
let foo: isize = 1;

tests/ui/diagnostic-flags/error-format-short.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Check that compile errors are formatted in the "short" style
2+
//! when `--error-format=short` is used.
3+
14
//@ compile-flags: --error-format=short
25

36
fn foo(_: u32) {}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
$DIR/short-error-format.rs:6:9: error[E0308]: mismatched types: expected `u32`, found `String`
2-
$DIR/short-error-format.rs:8:7: error[E0599]: no method named `salut` found for type `u32` in the current scope: method not found in `u32`
1+
$DIR/error-format-short.rs:9:9: error[E0308]: mismatched types: expected `u32`, found `String`
2+
$DIR/error-format-short.rs:11:7: error[E0599]: no method named `salut` found for type `u32` in the current scope: method not found in `u32`
33
error: aborting due to 2 previous errors

tests/ui/drop/drop-once-on-move.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//! Check that types not implementing `Copy` are moved, not copied, during assignment
2+
//! operations, and their `Drop` implementation is called exactly once when the
3+
//! value goes out of scope.
4+
15
//@ run-pass
26

37
#![allow(non_camel_case_types)]
@@ -15,9 +19,7 @@ impl<'a> Drop for r<'a> {
1519
}
1620

1721
fn r(i: &Cell<isize>) -> r<'_> {
18-
r {
19-
i: i
20-
}
22+
r { i }
2123
}
2224

2325
pub fn main() {

tests/ui/drop/drop-scope-exit.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,37 @@
1+
//! Check that the `Drop` implementation is called when a value goes out of scope.
2+
13
//@ run-pass
24

35
#![allow(non_camel_case_types)]
46
use std::cell::Cell;
57

68
struct shrinky_pointer<'a> {
7-
i: &'a Cell<isize>,
9+
i: &'a Cell<isize>,
810
}
911

1012
impl<'a> Drop for shrinky_pointer<'a> {
1113
fn drop(&mut self) {
12-
println!("Hello!"); self.i.set(self.i.get() - 1);
14+
println!("Hello!");
15+
self.i.set(self.i.get() - 1);
1316
}
1417
}
1518

1619
impl<'a> shrinky_pointer<'a> {
17-
pub fn look_at(&self) -> isize { return self.i.get(); }
20+
pub fn look_at(&self) -> isize {
21+
return self.i.get();
22+
}
1823
}
1924

2025
fn shrinky_pointer(i: &Cell<isize>) -> shrinky_pointer<'_> {
21-
shrinky_pointer {
22-
i: i
23-
}
26+
shrinky_pointer { i }
2427
}
2528

2629
pub fn main() {
2730
let my_total = &Cell::new(10);
28-
{ let pt = shrinky_pointer(my_total); assert_eq!(pt.look_at(), 10); }
31+
{
32+
let pt = shrinky_pointer(my_total);
33+
assert_eq!(pt.look_at(), 10);
34+
}
2935
println!("my_total = {}", my_total.get());
3036
assert_eq!(my_total.get(), 9);
3137
}

tests/ui/generics/trait-incorrect-generic-args.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
//! Check for compilation errors when a trait is used with an incorrect number of generic arguments.
2+
13
fn main() {
2-
trait Seq { }
4+
trait Seq {}
35

46
impl<T> Seq<T> for Vec<T> {
57
//~^ ERROR trait takes 0 generic arguments but 1 generic argument

tests/ui/generics/trait-incorrect-generic-args.stderr

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
2-
--> $DIR/seq-args.rs:4:13
2+
--> $DIR/trait-incorrect-generic-args.rs:6:13
33
|
44
LL | impl<T> Seq<T> for Vec<T> {
55
| ^^^--- help: remove the unnecessary generics
66
| |
77
| expected 0 generic arguments
88
|
99
note: trait defined here, with 0 generic parameters
10-
--> $DIR/seq-args.rs:2:11
10+
--> $DIR/trait-incorrect-generic-args.rs:4:11
1111
|
12-
LL | trait Seq { }
12+
LL | trait Seq {}
1313
| ^^^
1414

1515
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
16-
--> $DIR/seq-args.rs:9:10
16+
--> $DIR/trait-incorrect-generic-args.rs:11:10
1717
|
1818
LL | impl Seq<bool> for u32 {
1919
| ^^^------ help: remove the unnecessary generics
2020
| |
2121
| expected 0 generic arguments
2222
|
2323
note: trait defined here, with 0 generic parameters
24-
--> $DIR/seq-args.rs:2:11
24+
--> $DIR/trait-incorrect-generic-args.rs:4:11
2525
|
26-
LL | trait Seq { }
26+
LL | trait Seq {}
2727
| ^^^
2828

2929
error: aborting due to 2 previous errors

tests/ui/io-checks/io-stdout-blocking-writes.rs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
//! Check that writes to standard output are blocking, avoiding interleaving
2+
//! even with concurrent writes from multiple threads.
3+
14
//@ run-pass
25
//@ needs-subprocess
36

4-
use std::env;
57
use std::io::prelude::*;
68
use std::process::Command;
7-
use std::thread;
9+
use std::{env, thread};
810

911
const THREADS: usize = 20;
1012
const WRITES: usize = 100;
@@ -33,14 +35,16 @@ fn parent() {
3335
}
3436

3537
fn child() {
36-
let threads = (0..THREADS).map(|_| {
37-
thread::spawn(|| {
38-
let buf = [b'a'; WRITE_SIZE];
39-
for _ in 0..WRITES {
40-
write_all(&buf);
41-
}
38+
let threads = (0..THREADS)
39+
.map(|_| {
40+
thread::spawn(|| {
41+
let buf = [b'a'; WRITE_SIZE];
42+
for _ in 0..WRITES {
43+
write_all(&buf);
44+
}
45+
})
4246
})
43-
}).collect::<Vec<_>>();
47+
.collect::<Vec<_>>();
4448

4549
for thread in threads {
4650
thread.join().unwrap();
@@ -63,8 +67,8 @@ fn write_all(buf: &[u8]) {
6367
fn write_all(buf: &[u8]) {
6468
use std::fs::File;
6569
use std::mem;
66-
use std::os::windows::raw::*;
6770
use std::os::windows::prelude::*;
71+
use std::os::windows::raw::*;
6872

6973
const STD_OUTPUT_HANDLE: u32 = (-11i32) as u32;
7074

tests/ui/shadowed/primitive-type-shadowing.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Check that a primitive type can be shadowed by a user-defined type, and the primitive type
2+
//! can still be referenced using its fully qualified path (e.g., `core::primitive::bool`).
3+
14
//@ check-pass
25

36
mod bar {

tests/ui/shadowed/use-shadows-reexport.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! Check that a local `use` declaration can shadow a re-exported item within the same module.
2+
13
//@ run-pass
24

35
#![allow(unused_imports)]
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
1-
struct Baz { q: Option<Foo> }
2-
//~^ ERROR recursive types `Baz` and `Foo` have infinite size
3-
struct Foo { q: Option<Baz> }
1+
//! Check for compilation errors when recursive types are defined in a way
2+
//! that leads to an infinite size.
43
5-
impl Foo { fn bar(&self) {} }
4+
struct Baz {
5+
//~^ ERROR recursive types `Baz` and `Foo` have infinite size
6+
q: Option<Foo>,
7+
}
8+
struct Foo {
9+
q: Option<Baz>,
10+
}
11+
12+
impl Foo {
13+
fn bar(&self) {}
14+
}
615

716
fn main() {}

tests/ui/sized/recursive-type-infinite-size.stderr

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,23 @@
11
error[E0072]: recursive types `Baz` and `Foo` have infinite size
2-
--> $DIR/sized-cycle-note.rs:1:1
2+
--> $DIR/recursive-type-infinite-size.rs:4:1
33
|
4-
LL | struct Baz { q: Option<Foo> }
5-
| ^^^^^^^^^^ --- recursive without indirection
4+
LL | struct Baz {
5+
| ^^^^^^^^^^
66
LL |
7-
LL | struct Foo { q: Option<Baz> }
8-
| ^^^^^^^^^^ --- recursive without indirection
7+
LL | q: Option<Foo>,
8+
| --- recursive without indirection
9+
LL | }
10+
LL | struct Foo {
11+
| ^^^^^^^^^^
12+
LL | q: Option<Baz>,
13+
| --- recursive without indirection
914
|
1015
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
1116
|
12-
LL ~ struct Baz { q: Option<Box<Foo>> }
13-
LL |
14-
LL ~ struct Foo { q: Option<Box<Baz>> }
17+
LL ~ q: Option<Box<Foo>>,
18+
LL | }
19+
LL | struct Foo {
20+
LL ~ q: Option<Box<Baz>>,
1521
|
1622

1723
error: aborting due to 1 previous error
Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1+
//! Check that `Box<T>` is `Sized`, even when `T` is a dynamically sized type.
2+
13
//@ run-pass
24

35
#![allow(dead_code)]
4-
// Possibly-dynamic size of typaram should be cleared at pointer boundary.
5-
6-
76

8-
fn bar<T: Sized>() { }
9-
fn foo<T>() { bar::<Box<T>>() }
10-
pub fn main() { }
7+
fn bar<T: Sized>() {}
8+
fn foo<T>() {
9+
bar::<Box<T>>()
10+
}
11+
pub fn main() {}
Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
//! Check that a reference to a potentially unsized type (`&T`) is itself considered `Sized`.
2+
13
//@ run-pass
24

35
#![allow(dead_code)]
4-
// Possibly-dynamic size of typaram should be cleared at pointer boundary.
5-
66

7-
fn bar<T: Sized>() { }
8-
fn foo<T>() { bar::<&T>() }
9-
pub fn main() { }
7+
fn bar<T: Sized>() {}
8+
fn foo<T>() {
9+
bar::<&T>()
10+
}
11+
pub fn main() {}

tests/ui/sync/atomic-types-not-copyable.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
1-
// Issue #8380
1+
//! Check that atomic types from `std::sync::atomic` are not `Copy`
2+
//! and cannot be moved out of a shared reference.
3+
//!
4+
//! Regression test for <https://github.com/rust-lang/rust/issues/8380>.
25
3-
4-
use std::sync::atomic::*;
56
use std::ptr;
7+
use std::sync::atomic::*;
68

79
fn main() {
810
let x = AtomicBool::new(false);

tests/ui/sync/atomic-types-not-copyable.stderr

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0507]: cannot move out of a shared reference
2-
--> $DIR/std-uncopyable-atomics.rs:9:13
2+
--> $DIR/atomic-types-not-copyable.rs:11:13
33
|
44
LL | let x = *&x;
55
| ^^^ move occurs because value has type `std::sync::atomic::AtomicBool`, which does not implement the `Copy` trait
@@ -11,7 +11,7 @@ LL + let x = &x;
1111
|
1212

1313
error[E0507]: cannot move out of a shared reference
14-
--> $DIR/std-uncopyable-atomics.rs:11:13
14+
--> $DIR/atomic-types-not-copyable.rs:13:13
1515
|
1616
LL | let x = *&x;
1717
| ^^^ move occurs because value has type `std::sync::atomic::AtomicIsize`, which does not implement the `Copy` trait
@@ -23,7 +23,7 @@ LL + let x = &x;
2323
|
2424

2525
error[E0507]: cannot move out of a shared reference
26-
--> $DIR/std-uncopyable-atomics.rs:13:13
26+
--> $DIR/atomic-types-not-copyable.rs:15:13
2727
|
2828
LL | let x = *&x;
2929
| ^^^ move occurs because value has type `std::sync::atomic::AtomicUsize`, which does not implement the `Copy` trait
@@ -35,7 +35,7 @@ LL + let x = &x;
3535
|
3636

3737
error[E0507]: cannot move out of a shared reference
38-
--> $DIR/std-uncopyable-atomics.rs:15:13
38+
--> $DIR/atomic-types-not-copyable.rs:17:13
3939
|
4040
LL | let x = *&x;
4141
| ^^^ move occurs because value has type `std::sync::atomic::AtomicPtr<usize>`, which does not implement the `Copy` trait
Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
//! Check that `cfg!(target_feature = "...")` correctly detects available CPU features,
2+
//! specifically `sse2` on x86/x86_64 platforms, and correctly reports absent features.
3+
14
//@ run-pass
25

36
#![allow(stable_features)]
@@ -10,17 +13,23 @@ fn main() {
1013
Ok(s) => {
1114
// Skip this tests on i586-unknown-linux-gnu where sse2 is disabled
1215
if s.contains("i586") {
13-
return
16+
return;
1417
}
1518
}
1619
Err(_) => return,
1720
}
1821
if cfg!(any(target_arch = "x86", target_arch = "x86_64")) {
19-
assert!(cfg!(target_feature = "sse2"),
20-
"SSE2 was not detected as available on an x86 platform");
22+
assert!(
23+
cfg!(target_feature = "sse2"),
24+
"SSE2 was not detected as available on an x86 platform"
25+
);
2126
}
2227
// check a negative case too -- certainly not enabled by default
2328
#[expect(unexpected_cfgs)]
24-
{ assert!(cfg!(not(target_feature = "ferris_wheel")),
25-
"🎡 shouldn't be detected as available by default on any platform") };
29+
{
30+
assert!(
31+
cfg!(not(target_feature = "ferris_wheel")),
32+
"🎡 shouldn't be detected as available by default on any platform"
33+
)
34+
};
2635
}

tests/ui/traits/error-trait-object-from-string.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
//! Check that `String` and `&str` can be converted into `Box<dyn Error>` and
2+
//! `Box<dyn Error + Send + Sync>` trait objects
3+
14
//@ run-pass
2-
// Ensure that both `Box<dyn Error + Send + Sync>` and `Box<dyn Error>` can be
3-
// obtained from `String`.
45

56
use std::error::Error;
67

0 commit comments

Comments
 (0)