diff --git a/tests/ui/not-copy-closure.rs b/tests/ui/closures/closure-no-copy-mut-env.rs similarity index 65% rename from tests/ui/not-copy-closure.rs rename to tests/ui/closures/closure-no-copy-mut-env.rs index f6530f9a410aa..890e99c1ac79c 100644 --- a/tests/ui/not-copy-closure.rs +++ b/tests/ui/closures/closure-no-copy-mut-env.rs @@ -1,4 +1,4 @@ -// Check that closures do not implement `Copy` if their environment is not `Copy`. +//! Checks that closures do not implement `Copy` when they capture mutable references. fn main() { let mut a = 5; diff --git a/tests/ui/not-copy-closure.stderr b/tests/ui/closures/closure-no-copy-mut-env.stderr similarity index 84% rename from tests/ui/not-copy-closure.stderr rename to tests/ui/closures/closure-no-copy-mut-env.stderr index 60cb135231306..1443366a47700 100644 --- a/tests/ui/not-copy-closure.stderr +++ b/tests/ui/closures/closure-no-copy-mut-env.stderr @@ -1,5 +1,5 @@ error[E0382]: use of moved value: `hello` - --> $DIR/not-copy-closure.rs:10:13 + --> $DIR/closure-no-copy-mut-env.rs:10:13 | LL | let b = hello; | ----- value moved here @@ -7,7 +7,7 @@ LL | let c = hello; | ^^^^^ value used here after move | note: closure cannot be moved more than once as it is not `Copy` due to moving the variable `a` out of its environment - --> $DIR/not-copy-closure.rs:6:9 + --> $DIR/closure-no-copy-mut-env.rs:6:9 | LL | a += 1; | ^ diff --git a/tests/ui/auxiliary/delegate_macro.rs b/tests/ui/fn/auxiliary/delegate_macro.rs similarity index 100% rename from tests/ui/auxiliary/delegate_macro.rs rename to tests/ui/fn/auxiliary/delegate_macro.rs diff --git a/tests/ui/not-enough-arguments.rs b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs similarity index 82% rename from tests/ui/not-enough-arguments.rs rename to tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs index ec660a1de81be..b2f80ba1bf62f 100644 --- a/tests/ui/not-enough-arguments.rs +++ b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.rs @@ -1,15 +1,15 @@ +//! Checks clean diagnostics for argument count mismatches without unrelated errors. +//! +//! `delegate!` part related: + //@ aux-build: delegate_macro.rs extern crate delegate_macro; use delegate_macro::delegate; -// Check that the only error msg we report is the -// mismatch between the # of params, and not other -// unrelated errors. fn foo(a: isize, b: isize, c: isize, d: isize) { panic!(); } -// Check that all arguments are shown in the error message, even if they're across multiple lines. fn bar(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) { println!("{}", a); println!("{}", b); @@ -37,6 +37,7 @@ struct Bar; impl Bar { fn foo(a: u8, b: u8) {} + fn bar() { delegate_local!(foo); delegate!(foo); diff --git a/tests/ui/not-enough-arguments.stderr b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr similarity index 83% rename from tests/ui/not-enough-arguments.stderr rename to tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr index 908d0273bbecd..6af7671af03bf 100644 --- a/tests/ui/not-enough-arguments.stderr +++ b/tests/ui/fn/fn-arg-count-mismatch-diagnostics.stderr @@ -1,5 +1,5 @@ error[E0061]: this function takes 2 arguments but 1 argument was supplied - --> $DIR/not-enough-arguments.rs:24:9 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:24:9 | LL | ::$method(8) | ^^^^^^^^^^^^^^^--- argument #2 of type `u8` is missing @@ -8,7 +8,7 @@ LL | delegate_local!(foo); | -------------------- in this macro invocation | note: associated function defined here - --> $DIR/not-enough-arguments.rs:39:8 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:39:8 | LL | fn foo(a: u8, b: u8) {} | ^^^ ----- @@ -19,20 +19,20 @@ LL | ::$method(8, /* u8 */) | ++++++++++ error[E0061]: this function takes 2 arguments but 1 argument was supplied - --> $DIR/not-enough-arguments.rs:42:9 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:43:9 | LL | delegate!(foo); | ^^^^^^^^^^^^^^ argument #2 of type `u8` is missing | note: associated function defined here - --> $DIR/not-enough-arguments.rs:39:8 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:39:8 | LL | fn foo(a: u8, b: u8) {} | ^^^ ----- = note: this error originates in the macro `delegate` (in Nightly builds, run with -Z macro-backtrace for more info) error[E0061]: this function takes 2 arguments but 1 argument was supplied - --> $DIR/not-enough-arguments.rs:31:9 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:31:9 | LL | <$from>::$method(8) | ^^^^^^^^^^^^^^^^--- argument #2 of type `u8` is missing @@ -41,7 +41,7 @@ LL | delegate_from!(Bar, foo); | ------------------------ in this macro invocation | note: associated function defined here - --> $DIR/not-enough-arguments.rs:39:8 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:39:8 | LL | fn foo(a: u8, b: u8) {} | ^^^ ----- @@ -52,13 +52,13 @@ LL | <$from>::$method(8, /* u8 */) | ++++++++++ error[E0061]: this function takes 4 arguments but 3 arguments were supplied - --> $DIR/not-enough-arguments.rs:49:5 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:50:5 | LL | foo(1, 2, 3); | ^^^--------- argument #4 of type `isize` is missing | note: function defined here - --> $DIR/not-enough-arguments.rs:8:4 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:9:4 | LL | fn foo(a: isize, b: isize, c: isize, d: isize) { | ^^^ -------- @@ -68,13 +68,13 @@ LL | foo(1, 2, 3, /* isize */); | +++++++++++++ error[E0061]: this function takes 6 arguments but 3 arguments were supplied - --> $DIR/not-enough-arguments.rs:51:5 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:52:5 | LL | bar(1, 2, 3); | ^^^--------- three arguments of type `i32`, `i32`, and `i32` are missing | note: function defined here - --> $DIR/not-enough-arguments.rs:13:4 + --> $DIR/fn-arg-count-mismatch-diagnostics.rs:13:4 | LL | fn bar(a: i32, b: i32, c: i32, d: i32, e: i32, f: i32) { | ^^^ ------ ------ ------ diff --git a/tests/ui/nullable-pointer-size.rs b/tests/ui/layout/null-pointer-optimization-sizes.rs similarity index 65% rename from tests/ui/nullable-pointer-size.rs rename to tests/ui/layout/null-pointer-optimization-sizes.rs index aabdfa140dff6..95310b32e25f3 100644 --- a/tests/ui/nullable-pointer-size.rs +++ b/tests/ui/layout/null-pointer-optimization-sizes.rs @@ -1,10 +1,20 @@ +//! null pointer optimization preserves type sizes. +//! +//! Verifies that Option has the same size as T for non-null pointer types, +//! and for custom enums that have a niche. + //@ run-pass +// Needs for Nothing variat in Enum #![allow(dead_code)] use std::mem; -enum E { Thing(isize, T), Nothing((), ((), ()), [i8; 0]) } +enum E { + Thing(isize, T), + Nothing((), ((), ()), [i8; 0]), +} + struct S(isize, T); // These are macros so we get useful assert messages. @@ -12,20 +22,20 @@ struct S(isize, T); macro_rules! check_option { ($T:ty) => { assert_eq!(mem::size_of::>(), mem::size_of::<$T>()); - } + }; } macro_rules! check_fancy { ($T:ty) => { assert_eq!(mem::size_of::>(), mem::size_of::>()); - } + }; } macro_rules! check_type { ($T:ty) => {{ check_option!($T); check_fancy!($T); - }} + }}; } pub fn main() { diff --git a/tests/ui/nullable-pointer-iotareduction.rs b/tests/ui/layout/null-pointer-optimization.rs similarity index 62% rename from tests/ui/nullable-pointer-iotareduction.rs rename to tests/ui/layout/null-pointer-optimization.rs index 1b73164c9fc74..5e77c8d22ab22 100644 --- a/tests/ui/nullable-pointer-iotareduction.rs +++ b/tests/ui/layout/null-pointer-optimization.rs @@ -1,27 +1,34 @@ -//@ run-pass +//! null pointer optimization with iota-reduction for enums. +//! +//! Iota-reduction is a rule from the Calculus of (Co-)Inductive Constructions: +//! "a destructor applied to an object built from a constructor behaves as expected". +//! See . +//! +//! This test verifies that null pointer optimization works correctly for both +//! Option and custom enums, accounting for pointers and regions. -// Iota-reduction is a rule in the Calculus of (Co-)Inductive Constructions, -// which "says that a destructor applied to an object built from a constructor -// behaves as expected". -- https://coq.inria.fr/doc/language/core/conversion.html#iota-reduction -// -// It's a little more complicated here, because of pointers and regions and -// trying to get assert failure messages that at least identify which case -// failed. +//@ run-pass #![allow(unpredictable_function_pointer_comparisons)] -enum E { Thing(isize, T), #[allow(dead_code)] Nothing((), ((), ()), [i8; 0]) } +enum E { + Thing(isize, T), + #[allow(dead_code)] + Nothing((), ((), ()), [i8; 0]), +} + impl E { fn is_none(&self) -> bool { match *self { E::Thing(..) => false, - E::Nothing(..) => true + E::Nothing(..) => true, } } + fn get_ref(&self) -> (isize, &T) { match *self { - E::Nothing(..) => panic!("E::get_ref(Nothing::<{}>)", stringify!(T)), - E::Thing(x, ref y) => (x, y) + E::Nothing(..) => panic!("E::get_ref(Nothing::<{}>)", stringify!(T)), + E::Thing(x, ref y) => (x, y), } } } @@ -36,7 +43,7 @@ macro_rules! check_option { let s_ = Some::<$T>(e); let $v = s_.as_ref().unwrap(); $chk - }} + }}; } macro_rules! check_fancy { @@ -48,11 +55,10 @@ macro_rules! check_fancy { let e = $e; let t_ = E::Thing::<$T>(23, e); match t_.get_ref() { - (23, $v) => { $chk } - _ => panic!("Thing::<{}>(23, {}).get_ref() != (23, _)", - stringify!($T), stringify!($e)) + (23, $v) => $chk, + _ => panic!("Thing::<{}>(23, {}).get_ref() != (23, _)", stringify!($T), stringify!($e)), } - }} + }}; } macro_rules! check_type { @@ -67,7 +73,5 @@ pub fn main() { check_type!(Box::new(18), Box); check_type!("foo".to_string(), String); check_type!(vec![20, 22], Vec); - check_type!(main, fn(), |pthing| { - assert_eq!(main as fn(), *pthing as fn()) - }); + check_type!(main, fn(), |pthing| assert_eq!(main as fn(), *pthing as fn())); } diff --git a/tests/ui/nul-characters.rs b/tests/ui/str/nul-char-equivalence.rs similarity index 79% rename from tests/ui/nul-characters.rs rename to tests/ui/str/nul-char-equivalence.rs index eb83f440d3e03..2d4110de6812b 100644 --- a/tests/ui/nul-characters.rs +++ b/tests/ui/str/nul-char-equivalence.rs @@ -1,7 +1,8 @@ +//! Checks that different NUL character representations are equivalent in strings and chars. + //@ run-pass -pub fn main() -{ +pub fn main() { let all_nuls1 = "\0\x00\u{0}\u{0}"; let all_nuls2 = "\u{0}\u{0}\x00\0"; let all_nuls3 = "\u{0}\u{0}\x00\0"; @@ -17,11 +18,9 @@ pub fn main() assert_eq!(all_nuls3, all_nuls4); // all extracted characters in all_nuls are equivalent to each other - for c1 in all_nuls1.chars() - { - for c2 in all_nuls1.chars() - { - assert_eq!(c1,c2); + for c1 in all_nuls1.chars() { + for c2 in all_nuls1.chars() { + assert_eq!(c1, c2); } } diff --git a/tests/ui/object-pointer-types.rs b/tests/ui/traits/trait-object-method-receiver-rules.rs similarity index 81% rename from tests/ui/object-pointer-types.rs rename to tests/ui/traits/trait-object-method-receiver-rules.rs index 760a50e5b7972..383e59c131a14 100644 --- a/tests/ui/object-pointer-types.rs +++ b/tests/ui/traits/trait-object-method-receiver-rules.rs @@ -1,7 +1,8 @@ +//! Checks that method availability rules for trait objects depend on receiver type. + trait Foo { fn borrowed(&self); fn borrowed_mut(&mut self); - fn owned(self: Box); } @@ -20,7 +21,7 @@ fn borrowed_mut_receiver(x: &mut dyn Foo) { fn owned_receiver(x: Box) { x.borrowed(); x.borrowed_mut(); // See [1] - x.managed(); //~ ERROR no method named `managed` found + x.managed(); //~ ERROR no method named `managed` found x.owned(); } diff --git a/tests/ui/object-pointer-types.stderr b/tests/ui/traits/trait-object-method-receiver-rules.stderr similarity index 86% rename from tests/ui/object-pointer-types.stderr rename to tests/ui/traits/trait-object-method-receiver-rules.stderr index 72b290f2ad9f8..83b61a2e6b52e 100644 --- a/tests/ui/object-pointer-types.stderr +++ b/tests/ui/traits/trait-object-method-receiver-rules.stderr @@ -1,5 +1,5 @@ error[E0599]: no method named `owned` found for reference `&dyn Foo` in the current scope - --> $DIR/object-pointer-types.rs:11:7 + --> $DIR/trait-object-method-receiver-rules.rs:12:7 | LL | fn owned(self: Box); | --------- the method might not be found because of this arbitrary self type @@ -13,7 +13,7 @@ LL | x.to_owned(); | +++ error[E0599]: no method named `owned` found for mutable reference `&mut dyn Foo` in the current scope - --> $DIR/object-pointer-types.rs:17:7 + --> $DIR/trait-object-method-receiver-rules.rs:18:7 | LL | fn owned(self: Box); | --------- the method might not be found because of this arbitrary self type @@ -22,7 +22,7 @@ LL | x.owned(); | ^^^^^ method not found in `&mut dyn Foo` error[E0599]: no method named `managed` found for struct `Box<(dyn Foo + 'static)>` in the current scope - --> $DIR/object-pointer-types.rs:23:7 + --> $DIR/trait-object-method-receiver-rules.rs:24:7 | LL | x.managed(); | ^^^^^^^ method not found in `Box<(dyn Foo + 'static)>` diff --git a/tests/ui/objects-coerce-freeze-borrored.rs b/tests/ui/traits/trait-object-mut-to-shared-coercion.rs similarity index 88% rename from tests/ui/objects-coerce-freeze-borrored.rs rename to tests/ui/traits/trait-object-mut-to-shared-coercion.rs index e122bb9938061..26b5cc6d2dfcb 100644 --- a/tests/ui/objects-coerce-freeze-borrored.rs +++ b/tests/ui/traits/trait-object-mut-to-shared-coercion.rs @@ -1,6 +1,6 @@ -//@ run-pass -// Test that we can coerce an `@Object` to an `&Object` +//! Tests that coercion from `&mut dyn Trait` to `&dyn Trait` works correctly. +//@ run-pass trait Foo { fn foo(&self) -> usize;