Skip to content

Commit 50f65e8

Browse files
committed
cleaned up some tests
1 parent 9ad98f7 commit 50f65e8

10 files changed

+70
-55
lines changed

tests/ui/closures/closure-no-copy-mut-env.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Check that closures do not implement `Copy` if their environment is not `Copy`.
1+
//! Checks that closures do not implement `Copy` when they capture mutable references.
22
33
fn main() {
44
let mut a = 5;

tests/ui/closures/closure-no-copy-mut-env.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
error[E0382]: use of moved value: `hello`
2-
--> $DIR/not-copy-closure.rs:10:13
2+
--> $DIR/closure-no-copy-mut-env.rs:10:13
33
|
44
LL | let b = hello;
55
| ----- value moved here
66
LL | let c = hello;
77
| ^^^^^ value used here after move
88
|
99
note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `a` out of its environment
10-
--> $DIR/not-copy-closure.rs:6:9
10+
--> $DIR/closure-no-copy-mut-env.rs:6:9
1111
|
1212
LL | a += 1;
1313
| ^

tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1+
//! Checks clean diagnostics for argument count mismatches without unrelated errors.
2+
//!
3+
//! `delegate!` part related: <https://github.com/rust-lang/rust/pull/140591>
4+
15
//@ aux-build: delegate_macro.rs
26
extern crate delegate_macro;
37
use delegate_macro::delegate;
48

5-
// Check that the only error msg we report is the
6-
// mismatch between the # of params, and not other
7-
// unrelated errors.
89
fn foo(a: isize, b: isize, c: isize, d: isize) {
910
panic!();
1011
}
1112

12-
// Check that all arguments are shown in the error message, even if they're across multiple lines.
1313
fn bar(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) {
1414
println!("{}", a);
1515
println!("{}", b);
@@ -37,6 +37,7 @@ struct Bar;
3737

3838
impl Bar {
3939
fn foo(a: u8, b: u8) {}
40+
4041
fn bar() {
4142
delegate_local!(foo);
4243
delegate!(foo);

tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0061]: this function takes 2 arguments but 1 argument was supplied
2-
--> $DIR/not-enough-arguments.rs:24:9
2+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:24:9
33
|
44
LL | <Self>::$method(8)
55
| ^^^^^^^^^^^^^^^--- argument #2 of type `u8` is missing
@@ -8,7 +8,7 @@ LL | delegate_local!(foo);
88
| -------------------- in this macro invocation
99
|
1010
note: associated function defined here
11-
--> $DIR/not-enough-arguments.rs:39:8
11+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:39:8
1212
|
1313
LL | fn foo(a: u8, b: u8) {}
1414
| ^^^ -----
@@ -19,20 +19,20 @@ LL | <Self>::$method(8, /* u8 */)
1919
| ++++++++++
2020

2121
error[E0061]: this function takes 2 arguments but 1 argument was supplied
22-
--> $DIR/not-enough-arguments.rs:42:9
22+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:43:9
2323
|
2424
LL | delegate!(foo);
2525
| ^^^^^^^^^^^^^^ argument #2 of type `u8` is missing
2626
|
2727
note: associated function defined here
28-
--> $DIR/not-enough-arguments.rs:39:8
28+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:39:8
2929
|
3030
LL | fn foo(a: u8, b: u8) {}
3131
| ^^^ -----
3232
= note: this error originates in the macro `delegate` (in Nightly builds, run with -Z macro-backtrace for more info)
3333

3434
error[E0061]: this function takes 2 arguments but 1 argument was supplied
35-
--> $DIR/not-enough-arguments.rs:31:9
35+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:31:9
3636
|
3737
LL | <$from>::$method(8)
3838
| ^^^^^^^^^^^^^^^^--- argument #2 of type `u8` is missing
@@ -41,7 +41,7 @@ LL | delegate_from!(Bar, foo);
4141
| ------------------------ in this macro invocation
4242
|
4343
note: associated function defined here
44-
--> $DIR/not-enough-arguments.rs:39:8
44+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:39:8
4545
|
4646
LL | fn foo(a: u8, b: u8) {}
4747
| ^^^ -----
@@ -52,13 +52,13 @@ LL | <$from>::$method(8, /* u8 */)
5252
| ++++++++++
5353

5454
error[E0061]: this function takes 4 arguments but 3 arguments were supplied
55-
--> $DIR/not-enough-arguments.rs:49:5
55+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:50:5
5656
|
5757
LL | foo(1, 2, 3);
5858
| ^^^--------- argument #4 of type `isize` is missing
5959
|
6060
note: function defined here
61-
--> $DIR/not-enough-arguments.rs:8:4
61+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:9:4
6262
|
6363
LL | fn foo(a: isize, b: isize, c: isize, d: isize) {
6464
| ^^^ --------
@@ -68,13 +68,13 @@ LL | foo(1, 2, 3, /* isize */);
6868
| +++++++++++++
6969

7070
error[E0061]: this function takes 6 arguments but 3 arguments were supplied
71-
--> $DIR/not-enough-arguments.rs:51:5
71+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:52:5
7272
|
7373
LL | bar(1, 2, 3);
7474
| ^^^--------- three arguments of type `i32`, `i32`, and `i32` are missing
7575
|
7676
note: function defined here
77-
--> $DIR/not-enough-arguments.rs:13:4
77+
--> $DIR/fn-arg-count-mismatch-diagnostics.rs:13:4
7878
|
7979
LL | fn bar(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) {
8080
| ^^^ ------ ------ ------
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
1-
//@ run-pass
1+
//! non-null pointer optimization with iota-reduction for enums.
2+
//!
3+
//! Iota-reduction is a rule from the Calculus of (Co-)Inductive Constructions:
4+
//! "a destructor applied to an object built from a constructor behaves as expected".
5+
//! See <https://coq.inria.fr/doc/language/core/conversion.html#iota-reduction>.
6+
//!
7+
//! This test verifies that non-null pointer optimization works correctly for both
8+
//! Option<T> and custom enums, accounting for pointers and regions.
29
3-
// Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions,
4-
// which "says that a destructor applied to an object built from a constructor
5-
// behaves as expected". -- https://coq.inria.fr/doc/language/core/conversion.html#iota-reduction
6-
//
7-
// It's a little more complicated here, because of pointers and regions and
8-
// trying to get assert failure messages that at least identify which case
9-
// failed.
10+
//@ run-pass
1011

1112
#![allow(unpredictable_function_pointer_comparisons)]
1213

13-
enum E<T> { Thing(isize, T), #[allow(dead_code)] Nothing((), ((), ()), [i8; 0]) }
14+
enum E<T> {
15+
Thing(isize, T),
16+
#[allow(dead_code)]
17+
Nothing((), ((), ()), [i8; 0]),
18+
}
19+
1420
impl<T> E<T> {
1521
fn is_none(&self) -> bool {
1622
match *self {
1723
E::Thing(..) => false,
18-
E::Nothing(..) => true
24+
E::Nothing(..) => true,
1925
}
2026
}
27+
2128
fn get_ref(&self) -> (isize, &T) {
2229
match *self {
23-
E::Nothing(..) => panic!("E::get_ref(Nothing::<{}>)", stringify!(T)),
24-
E::Thing(x, ref y) => (x, y)
30+
E::Nothing(..) => panic!("E::get_ref(Nothing::<{}>)", stringify!(T)),
31+
E::Thing(x, ref y) => (x, y),
2532
}
2633
}
2734
}
@@ -36,7 +43,7 @@ macro_rules! check_option {
3643
let s_ = Some::<$T>(e);
3744
let $v = s_.as_ref().unwrap();
3845
$chk
39-
}}
46+
}};
4047
}
4148

4249
macro_rules! check_fancy {
@@ -48,11 +55,10 @@ macro_rules! check_fancy {
4855
let e = $e;
4956
let t_ = E::Thing::<$T>(23, e);
5057
match t_.get_ref() {
51-
(23, $v) => { $chk }
52-
_ => panic!("Thing::<{}>(23, {}).get_ref() != (23, _)",
53-
stringify!($T), stringify!($e))
58+
(23, $v) => $chk,
59+
_ => panic!("Thing::<{}>(23, {}).get_ref() != (23, _)", stringify!($T), stringify!($e)),
5460
}
55-
}}
61+
}};
5662
}
5763

5864
macro_rules! check_type {
@@ -67,7 +73,5 @@ pub fn main() {
6773
check_type!(Box::new(18), Box<isize>);
6874
check_type!("foo".to_string(), String);
6975
check_type!(vec![20, 22], Vec<isize>);
70-
check_type!(main, fn(), |pthing| {
71-
assert_eq!(main as fn(), *pthing as fn())
72-
});
76+
check_type!(main, fn(), |pthing| assert_eq!(main as fn(), *pthing as fn()));
7377
}

tests/ui/layout/null-pointer-size-optimization.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,41 @@
1+
//! non-null pointer optimization preserves type sizes.
2+
//!
3+
//! Verifies that Option<T> has the same size as T for non-null pointer types,
4+
//! and for custom enums that have a niche.
5+
16
//@ run-pass
27

8+
// Needs for Nothing variat in Enum
39
#![allow(dead_code)]
410

511
use std::mem;
612

7-
enum E<T> { Thing(isize, T), Nothing((), ((), ()), [i8; 0]) }
13+
enum E<T> {
14+
Thing(isize, T),
15+
Nothing((), ((), ()), [i8; 0]),
16+
}
17+
818
struct S<T>(isize, T);
919

1020
// These are macros so we get useful assert messages.
1121

1222
macro_rules! check_option {
1323
($T:ty) => {
1424
assert_eq!(mem::size_of::<Option<$T>>(), mem::size_of::<$T>());
15-
}
25+
};
1626
}
1727

1828
macro_rules! check_fancy {
1929
($T:ty) => {
2030
assert_eq!(mem::size_of::<E<$T>>(), mem::size_of::<S<$T>>());
21-
}
31+
};
2232
}
2333

2434
macro_rules! check_type {
2535
($T:ty) => {{
2636
check_option!($T);
2737
check_fancy!($T);
28-
}}
38+
}};
2939
}
3040

3141
pub fn main() {

tests/ui/str/nul-char-equivalence.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
//! Checks that different NUL character representations are equivalent in strings and chars.
2+
13
//@ run-pass
24

3-
pub fn main()
4-
{
5+
pub fn main() {
56
let all_nuls1 = "\0\x00\u{0}\u{0}";
67
let all_nuls2 = "\u{0}\u{0}\x00\0";
78
let all_nuls3 = "\u{0}\u{0}\x00\0";
@@ -17,11 +18,9 @@ pub fn main()
1718
assert_eq!(all_nuls3, all_nuls4);
1819

1920
// all extracted characters in all_nuls are equivalent to each other
20-
for c1 in all_nuls1.chars()
21-
{
22-
for c2 in all_nuls1.chars()
23-
{
24-
assert_eq!(c1,c2);
21+
for c1 in all_nuls1.chars() {
22+
for c2 in all_nuls1.chars() {
23+
assert_eq!(c1, c2);
2524
}
2625
}
2726

tests/ui/traits/trait-object-method-receiver-rules.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
//! Checks that method availability rules for trait objects depend on receiver type.
2+
13
trait Foo {
24
fn borrowed(&self);
35
fn borrowed_mut(&mut self);
4-
56
fn owned(self: Box<Self>);
67
}
78

@@ -20,7 +21,7 @@ fn borrowed_mut_receiver(x: &mut dyn Foo) {
2021
fn owned_receiver(x: Box<dyn Foo>) {
2122
x.borrowed();
2223
x.borrowed_mut(); // See [1]
23-
x.managed(); //~ ERROR no method named `managed` found
24+
x.managed(); //~ ERROR no method named `managed` found
2425
x.owned();
2526
}
2627

tests/ui/traits/trait-object-method-receiver-rules.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0599]: no method named `owned` found for reference `&dyn Foo` in the current scope
2-
--> $DIR/object-pointer-types.rs:11:7
2+
--> $DIR/trait-object-method-receiver-rules.rs:12:7
33
|
44
LL | fn owned(self: Box<Self>);
55
| --------- the method might not be found because of this arbitrary self type
@@ -13,7 +13,7 @@ LL | x.to_owned();
1313
| +++
1414

1515
error[E0599]: no method named `owned` found for mutable reference `&mut dyn Foo` in the current scope
16-
--> $DIR/object-pointer-types.rs:17:7
16+
--> $DIR/trait-object-method-receiver-rules.rs:18:7
1717
|
1818
LL | fn owned(self: Box<Self>);
1919
| --------- the method might not be found because of this arbitrary self type
@@ -22,7 +22,7 @@ LL | x.owned();
2222
| ^^^^^ method not found in `&mut dyn Foo`
2323

2424
error[E0599]: no method named `managed` found for struct `Box<(dyn Foo + 'static)>` in the current scope
25-
--> $DIR/object-pointer-types.rs:23:7
25+
--> $DIR/trait-object-method-receiver-rules.rs:24:7
2626
|
2727
LL | x.managed();
2828
| ^^^^^^^ method not found in `Box<(dyn Foo + 'static)>`

tests/ui/traits/trait-object-mut-to-shared-coercion.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//@ run-pass
2-
// Test that we can coerce an `@Object` to an `&Object`
1+
//! Tests that coercion from `&mut dyn Trait` to `&dyn Trait` works correctly.
32
3+
//@ run-pass
44

55
trait Foo {
66
fn foo(&self) -> usize;

0 commit comments

Comments
 (0)