Skip to content

tests/ui: A New Order [25/N] #143300

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 17 commits into
base: master
Choose a base branch
from
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Check that `#[reexport_test_harness_main]` correctly reexports the test harness entry point
//! and allows it to be called from within the code.

//@ run-pass
//@ compile-flags:--test

Expand Down
11 changes: 11 additions & 0 deletions tests/ui/const-ptr/pointer-address-stability.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//! Check that taking the address of a stack variable with `&`
//! yields a stable and comparable pointer.
//!
//! Regression test for <https://github.com/rust-lang/rust/issues/2040>.

//@ run-pass

pub fn main() {
let foo: isize = 1;
assert_eq!(&foo as *const isize, &foo as *const isize);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Check that compile errors are formatted in the "short" style
//! when `--error-format=short` is used.

//@ compile-flags: --error-format=short

fn foo(_: u32) {}
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/diagnostic-flags/error-format-short.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$DIR/error-format-short.rs:9:9: error[E0308]: mismatched types: expected `u32`, found `String`
$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`
error: aborting due to 2 previous errors
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! Check that types not implementing `Copy` are moved, not copied, during assignment
//! operations, and their `Drop` implementation is called exactly once when the
//! value goes out of scope.

//@ run-pass

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

fn r(i: &Cell<isize>) -> r<'_> {
r {
i: i
}
r { i }
}

pub fn main() {
Expand Down
20 changes: 13 additions & 7 deletions tests/ui/resource-destruct.rs → tests/ui/drop/drop-scope-exit.rs
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
//! Check that the `Drop` implementation is called when a value goes out of scope.

//@ run-pass

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

struct shrinky_pointer<'a> {
i: &'a Cell<isize>,
i: &'a Cell<isize>,
}

impl<'a> Drop for shrinky_pointer<'a> {
fn drop(&mut self) {
println!("Hello!"); self.i.set(self.i.get() - 1);
println!("Hello!");
self.i.set(self.i.get() - 1);
}
}

impl<'a> shrinky_pointer<'a> {
pub fn look_at(&self) -> isize { return self.i.get(); }
pub fn look_at(&self) -> isize {
return self.i.get();
}
}

fn shrinky_pointer(i: &Cell<isize>) -> shrinky_pointer<'_> {
shrinky_pointer {
i: i
}
shrinky_pointer { i }
}

pub fn main() {
let my_total = &Cell::new(10);
{ let pt = shrinky_pointer(my_total); assert_eq!(pt.look_at(), 10); }
{
let pt = shrinky_pointer(my_total);
assert_eq!(pt.look_at(), 10);
}
println!("my_total = {}", my_total.get());
assert_eq!(my_total.get(), 9);
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
//! Check for compilation errors when a trait is used with an incorrect number of generic arguments.

fn main() {
trait Seq { }
trait Seq {}

impl<T> Seq<T> for Vec<T> {
//~^ ERROR trait takes 0 generic arguments but 1 generic argument
Expand Down
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/seq-args.rs:4:13
--> $DIR/trait-incorrect-generic-args.rs:6:13
|
LL | impl<T> Seq<T> for Vec<T> {
| ^^^--- help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
note: trait defined here, with 0 generic parameters
--> $DIR/seq-args.rs:2:11
--> $DIR/trait-incorrect-generic-args.rs:4:11
|
LL | trait Seq { }
LL | trait Seq {}
| ^^^

error[E0107]: trait takes 0 generic arguments but 1 generic argument was supplied
--> $DIR/seq-args.rs:9:10
--> $DIR/trait-incorrect-generic-args.rs:11:10
|
LL | impl Seq<bool> for u32 {
| ^^^------ help: remove the unnecessary generics
| |
| expected 0 generic arguments
|
note: trait defined here, with 0 generic parameters
--> $DIR/seq-args.rs:2:11
--> $DIR/trait-incorrect-generic-args.rs:4:11
|
LL | trait Seq { }
LL | trait Seq {}
| ^^^

error: aborting due to 2 previous errors
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//! Check that writes to standard output are blocking, ensuring data
//! integrity even with concurrent writes from multiple threads.

//@ run-pass
//@ needs-subprocess

use std::env;
use std::io::prelude::*;
use std::process::Command;
use std::thread;
use std::{env, thread};

const THREADS: usize = 20;
const WRITES: usize = 100;
Expand Down Expand Up @@ -33,14 +35,16 @@ fn parent() {
}

fn child() {
let threads = (0..THREADS).map(|_| {
thread::spawn(|| {
let buf = [b'a'; WRITE_SIZE];
for _ in 0..WRITES {
write_all(&buf);
}
let threads = (0..THREADS)
.map(|_| {
thread::spawn(|| {
let buf = [b'a'; WRITE_SIZE];
for _ in 0..WRITES {
write_all(&buf);
}
})
})
}).collect::<Vec<_>>();
.collect::<Vec<_>>();

for thread in threads {
thread.join().unwrap();
Expand All @@ -63,8 +67,8 @@ fn write_all(buf: &[u8]) {
fn write_all(buf: &[u8]) {
use std::fs::File;
use std::mem;
use std::os::windows::raw::*;
use std::os::windows::prelude::*;
use std::os::windows::raw::*;

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

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Check that a primitive type can be shadowed by a user-defined type, and the primitive type
//! can still be referenced using its fully qualified path (e.g., `core::primitive::bool`).

//@ check-pass

mod bar {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Check that a local `use` declaration can shadow a re-exported item within the same module.

//@ run-pass

#![allow(unused_imports)]
Expand Down
3 changes: 0 additions & 3 deletions tests/ui/short-error-format.stderr

This file was deleted.

9 changes: 0 additions & 9 deletions tests/ui/sized-borrowed-pointer.rs

This file was deleted.

7 changes: 0 additions & 7 deletions tests/ui/sized-cycle-note.rs

This file was deleted.

19 changes: 0 additions & 19 deletions tests/ui/sized-cycle-note.stderr

This file was deleted.

10 changes: 0 additions & 10 deletions tests/ui/sized-owned-pointer.rs

This file was deleted.

16 changes: 16 additions & 0 deletions tests/ui/sized/recursive-type-infinite-size.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//! Check for compilation errors when recursive types are defined in a way
//! that leads to an infinite size.

struct Baz {
//~^ ERROR recursive types `Baz` and `Foo` have infinite size
q: Option<Foo>,
}
struct Foo {
q: Option<Baz>,
}

impl Foo {
fn bar(&self) {}
}

fn main() {}
25 changes: 25 additions & 0 deletions tests/ui/sized/recursive-type-infinite-size.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0072]: recursive types `Baz` and `Foo` have infinite size
--> $DIR/recursive-type-infinite-size.rs:4:1
|
LL | struct Baz {
| ^^^^^^^^^^
LL |
LL | q: Option<Foo>,
| --- recursive without indirection
LL | }
LL | struct Foo {
| ^^^^^^^^^^
LL | q: Option<Baz>,
| --- recursive without indirection
|
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
|
LL ~ q: Option<Box<Foo>>,
LL | }
LL | struct Foo {
LL ~ q: Option<Box<Baz>>,
|

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0072`.
12 changes: 12 additions & 0 deletions tests/ui/sized/sized-box-unsized-content.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Check that `Box<T>` is `Sized`, even when `T` is a dynamically sized type.
//! This allows `Box<T>` to be used in contexts requiring `Sized` types.

//@ run-pass

#![allow(dead_code)]

fn bar<T: Sized>() {}
fn foo<T>() {
bar::<Box<T>>()
}
pub fn main() {}
12 changes: 12 additions & 0 deletions tests/ui/sized/sized-reference-to-unsized.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Check that a reference to a potentially unsized type (`&T`) is itself considered `Sized`.
//! This allows functions requiring `Sized` types to accept references to dynamically sized types.

//@ run-pass

#![allow(dead_code)]

fn bar<T: Sized>() {}
fn foo<T>() {
bar::<&T>()
}
pub fn main() {}
8 changes: 0 additions & 8 deletions tests/ui/stable-addr-of.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// Issue #8380
//! Check that atomic types from `std::sync::atomic` are not `Copy`
//! and cannot be moved out of a shared reference.
//!
//! Regression test for <https://github.com/rust-lang/rust/issues/8380>.


use std::sync::atomic::*;
use std::ptr;
use std::sync::atomic::*;

fn main() {
let x = AtomicBool::new(false);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0507]: cannot move out of a shared reference
--> $DIR/std-uncopyable-atomics.rs:9:13
--> $DIR/atomic-types-not-copyable.rs:11:13
|
LL | let x = *&x;
| ^^^ move occurs because value has type `std::sync::atomic::AtomicBool`, which does not implement the `Copy` trait
Expand All @@ -11,7 +11,7 @@ LL + let x = &x;
|

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

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

error[E0507]: cannot move out of a shared reference
--> $DIR/std-uncopyable-atomics.rs:15:13
--> $DIR/atomic-types-not-copyable.rs:17:13
|
LL | let x = *&x;
| ^^^ move occurs because value has type `std::sync::atomic::AtomicPtr<usize>`, which does not implement the `Copy` trait
Expand Down
Loading
Loading