Skip to content

tests/ui: A New Order [21/N] #143296

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
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
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;
| ^
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
//! Checks clean diagnostics for argument count mismatches without unrelated errors.
//!
//! `delegate!` part related: <https://github.com/rust-lang/rust/pull/140591>

//@ 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);
Expand Down Expand Up @@ -37,6 +37,7 @@ struct Bar;

impl Bar {
fn foo(a: u8, b: u8) {}

fn bar() {
delegate_local!(foo);
delegate!(foo);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 | <Self>::$method(8)
| ^^^^^^^^^^^^^^^--- argument #2 of type `u8` is missing
Expand All @@ -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) {}
| ^^^ -----
Expand All @@ -19,20 +19,20 @@ LL | <Self>::$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
Expand All @@ -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) {}
| ^^^ -----
Expand All @@ -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) {
| ^^^ --------
Expand All @@ -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) {
| ^^^ ------ ------ ------
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
//@ run-pass
//! Nullable pointer optimization with iota-reduction for enums.
//!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The term should be "null pointer optimization", not "nullable"; because types like &T and Box<T> are not nullable.

Also for the file name

//! 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 <https://coq.inria.fr/doc/language/core/conversion.html#iota-reduction>.
//!
//! This test verifies that nullable pointer optimization works correctly for both
//! Option<T> 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<T> { Thing(isize, T), #[allow(dead_code)] Nothing((), ((), ()), [i8; 0]) }
enum E<T> {
Thing(isize, T),
#[allow(dead_code)]
Nothing((), ((), ()), [i8; 0]),
}

impl<T> E<T> {
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),
}
}
}
Expand All @@ -36,7 +43,7 @@ macro_rules! check_option {
let s_ = Some::<$T>(e);
let $v = s_.as_ref().unwrap();
$chk
}}
}};
}

macro_rules! check_fancy {
Expand All @@ -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 {
Expand All @@ -67,7 +73,5 @@ pub fn main() {
check_type!(Box::new(18), Box<isize>);
check_type!("foo".to_string(), String);
check_type!(vec![20, 22], Vec<isize>);
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()));
}
Original file line number Diff line number Diff line change
@@ -1,31 +1,41 @@
//! Nullable pointer optimization preserves type sizes.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nullable -> Null (also the file name)

//!
//! Verifies that Option<T> has the same size as T for nullable pointer types,
//! and that custom enums get the same optimization.
Comment on lines +3 to +4
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Slight correction

Suggested change
//! Verifies that Option<T> has the same size as T for nullable pointer types,
//! and that custom enums get the same optimization.
//! Verifies that Option<T> has the same size as T for non-nullable 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<T> { Thing(isize, T), Nothing((), ((), ()), [i8; 0]) }
enum E<T> {
Thing(isize, T),
Nothing((), ((), ()), [i8; 0]),
}

struct S<T>(isize, T);

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

macro_rules! check_option {
($T:ty) => {
assert_eq!(mem::size_of::<Option<$T>>(), mem::size_of::<$T>());
}
};
}

macro_rules! check_fancy {
($T:ty) => {
assert_eq!(mem::size_of::<E<$T>>(), mem::size_of::<S<$T>>());
}
};
}

macro_rules! check_type {
($T:ty) => {{
check_option!($T);
check_fancy!($T);
}}
}};
}

pub fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -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";
Expand All @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Self>);
}

Expand All @@ -20,7 +21,7 @@ fn borrowed_mut_receiver(x: &mut dyn Foo) {
fn owned_receiver(x: Box<dyn Foo>) {
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();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Self>);
| --------- the method might not be found because of this arbitrary self type
Expand All @@ -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<Self>);
| --------- the method might not be found because of this arbitrary self type
Expand All @@ -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)>`
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Loading