Skip to content

tests/ui: A New Order [28/N] FINAL PART #143303

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 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions tests/ui/allocator/weak-uninhabited-type.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Checks that `Weak` pointers can be created with an empty enum type parameter.
//! And generic `Weak` handles zero-variant enums without error.
//!
//! Regression test for <https://github.com/rust-lang/rust/issues/48493>

//@ run-pass

enum Void {}

fn main() {
let _ = std::rc::Weak::<Void>::new();
let _ = std::sync::Weak::<Void>::new();
}
15 changes: 15 additions & 0 deletions tests/ui/binding/underscore-prefixed-function-argument.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//! Test that functions with unnamed arguments are correct handled by compiler

//@ run-pass

fn good(_a: &isize) {}

fn called<F>(_f: F)
where
F: FnOnce(&isize),
{
}

pub fn main() {
called(good);
}
19 changes: 19 additions & 0 deletions tests/ui/borrowck/ownership-struct-update-moved-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//! Checks borrow after move error when using `self` consuming method with struct update syntax.

struct Mine {
test: String,
other_val: isize,
}

impl Mine {
fn make_string_bar(mut self) -> Mine {
self.test = "Bar".to_string();
self
}
}

fn main() {
let start = Mine { test: "Foo".to_string(), other_val: 0 };
let end = Mine { other_val: 1, ..start.make_string_bar() };
println!("{}", start.test); //~ ERROR borrow of moved value: `start`
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error[E0382]: borrow of moved value: `start`
--> $DIR/walk-struct-literal-with.rs:16:20
--> $DIR/ownership-struct-update-moved-error.rs:18:20
|
LL | let start = Mine{test:"Foo".to_string(), other_val:0};
LL | let start = Mine { test: "Foo".to_string(), other_val: 0 };
| ----- move occurs because `start` has type `Mine`, which does not implement the `Copy` trait
LL | let end = Mine{other_val:1, ..start.make_string_bar()};
| ----------------- `start` moved due to this method call
LL | let end = Mine { other_val: 1, ..start.make_string_bar() };
| ----------------- `start` moved due to this method call
LL | println!("{}", start.test);
| ^^^^^^^^^^ value borrowed here after move
|
note: `Mine::make_string_bar` takes ownership of the receiver `self`, which moves `start`
--> $DIR/walk-struct-literal-with.rs:7:28
--> $DIR/ownership-struct-update-moved-error.rs:9:28
|
LL | fn make_string_bar(mut self) -> Mine{
LL | fn make_string_bar(mut self) -> Mine {
| ^^^^
= note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Sanity check for no capture closures

//@ run-pass

pub fn main() {
Expand Down
12 changes: 12 additions & 0 deletions tests/ui/drop/box-drop-unused-value-statement-regression.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Regression test for a crash caused by an "unsused move"
//! (specifically, a variable bound to a `Box` used as a statement)
//! leading to incorrect memory zero-filling after drop.
//!
//! Regression test for <https://github.com/rust-lang/rust/issues/3878>.

//@ run-pass

pub fn main() {
let y: Box<_> = Box::new(1);
drop(y);
}
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,26 +1,28 @@
//! Checks that `HashSet` initialization with enum variants correctly includes only
//! specified variants, preventing platform-specific bugs
//! where all enum variants were mistakenly included
//!
//! Regression test for <https://github.com/rust-lang/rust/issues/42918>

//@ run-pass
//
#![allow(dead_code)]
//@ compile-flags: -O

#![allow(dead_code)]

use std::collections::HashSet;

#[derive(PartialEq, Debug, Hash, Eq, Clone, PartialOrd, Ord)]
enum MyEnum {
E0,

E1,

E2,
E3,
E4,

E5,
E6,
E7,
}


fn main() {
use MyEnum::*;
let s: HashSet<_> = [E4, E1].iter().cloned().collect();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
//! Tests that errors from both the writer (`Write::write`) and formatter (`Display::fmt`)
//! are correctly propagated: writer errors return `Err`, formatter errors cause panics.

//@ run-pass
//@ needs-unwind

Expand All @@ -24,7 +27,9 @@ impl Write for ErrorWriter {
Err(Error::new(WRITER_ERROR, "not connected"))
}

fn flush(&mut self) -> io::Result<()> { Ok(()) }
fn flush(&mut self) -> io::Result<()> {
Ok(())
}
}

fn main() {
Expand All @@ -37,7 +42,8 @@ fn main() {
let err = res.expect_err("formatter error did not lead to panic").downcast::<&str>().unwrap();
assert!(
err.contains("formatting trait implementation returned an error"),
"unexpected panic: {}", err
"unexpected panic: {}",
err
);

// Writer error when there's some string before the first `{}`
Expand All @@ -50,6 +56,7 @@ fn main() {
let err = res.expect_err("formatter error did not lead to panic").downcast::<&str>().unwrap();
assert!(
err.contains("formatting trait implementation returned an error"),
"unexpected panic: {}", err
"unexpected panic: {}",
err
);
}
12 changes: 12 additions & 0 deletions tests/ui/lang-items/lang-item-unknown-definition-error.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
//! Checks that compiler prevernt attempting to define an unrecognized or unknown lang item

#![allow(unused)]
#![feature(lang_items)]

#[lang = "foo"]
fn bar() -> ! {
//~^^ ERROR definition of an unknown lang item: `foo`
loop {}
}

fn main() {}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0522]: definition of an unknown lang item: `foo`
--> $DIR/unknown-language-item.rs:4:1
--> $DIR/lang-item-unknown-definition-error.rs:6:1
|
LL | #[lang = "foo"]
| ^^^^^^^^^^^^^^^ definition of unknown lang item `foo`
Expand Down
20 changes: 20 additions & 0 deletions tests/ui/modules/module-qualified-paths-basic.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//! Checks that functions from different modules are accessible via their fully-qualified paths.

//@ run-pass

mod foo {
pub fn x() -> isize {
return 1;
}
}

mod bar {
pub fn y() -> isize {
return 1;
}
}

pub fn main() {
foo::x();
bar::y();
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! Checks complex `use` syntax and availability of types across nested modules.

//@ run-pass

mod a {
Expand All @@ -15,10 +17,13 @@ mod a {
}

// Test every possible part of the syntax
use a::{B, d::{self, *, g::H}};

// Test a more common use case
use std::sync::{Arc, atomic::{AtomicBool, Ordering}};
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};

use a::B;
use a::d::g::H;
use a::d::{self, *};

fn main() {
let _: B;
Expand Down
13 changes: 13 additions & 0 deletions tests/ui/modules/primitive-type-module-deprecated-paths.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Make sure the module level constants are still there and accessible even after
//! the corresponding associated constants have been added, and later stabilized.

//@ run-pass

#![allow(deprecated, deprecated_in_future)]
use std::{f32, u16};

fn main() {
let _ = u16::MAX;
let _ = f32::EPSILON;
let _ = std::f64::MANTISSA_DIGITS;
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
//! Checks module re-exports, aliasing with `pub use`,
//! and calling private methods via `Self` in an impl block.

//@ run-pass

#![allow(unused_variables)]
pub struct A;

mod test {
pub use super :: A;

pub use self :: A as B;
pub use self::A as B;
pub use super::A;
}

impl A {
fn f() {}
fn g() {
Self :: f()
Self::f()
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//! This test ensures that the unary negation operator (`-`) cannot be applied to unsigned ints

fn main() {
let x = -1 as usize; //~ ERROR: cannot apply unary operator `-`
let x = (-1) as usize; //~ ERROR: cannot apply unary operator `-`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0600]: cannot apply unary operator `-` to type `usize`
--> $DIR/unsigned-literal-negation.rs:2:13
--> $DIR/unary-negation-unsigned-integer-error.rs:4:13
|
LL | let x = -1 as usize;
| ^^ cannot apply unary operator `-`
Expand All @@ -12,7 +12,7 @@ LL + let x = usize::MAX;
|

error[E0600]: cannot apply unary operator `-` to type `usize`
--> $DIR/unsigned-literal-negation.rs:3:13
--> $DIR/unary-negation-unsigned-integer-error.rs:5:13
|
LL | let x = (-1) as usize;
| ^^^^ cannot apply unary operator `-`
Expand All @@ -25,7 +25,7 @@ LL + let x = usize::MAX;
|

error[E0600]: cannot apply unary operator `-` to type `u32`
--> $DIR/unsigned-literal-negation.rs:4:18
--> $DIR/unary-negation-unsigned-integer-error.rs:6:18
|
LL | let x: u32 = -1;
| ^^ cannot apply unary operator `-`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
//! This test checks that Rust's unwinding mechanism correctly executes `Drop`
//! implementations during stack unwinding, even when unwind tables (`uwtable`)
//! are explicitly disabled via `-C force-unwind-tables=n`.

//@ run-pass
//@ needs-unwind
//@ ignore-windows target requires uwtable
Expand Down Expand Up @@ -26,9 +30,12 @@ fn increase(count: &mut u8) {

fn main() {
let mut count = 0;
assert!(panic::catch_unwind(AssertUnwindSafe(
#[inline(never)]
|| increase(&mut count)
)).is_err());
assert!(
panic::catch_unwind(AssertUnwindSafe(
#[inline(never)]
|| increase(&mut count)
))
.is_err()
);
assert_eq!(count, 1);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
//! Tests that repeatedly spawning a failing command does not create zombie processes.
//! Spawns a deliberately invalid command multiple times, verifies each spawn fails,
//! then uses `ps` (on Unix) to detect any leftover zombie (defunct) child processes.
//! Checks Rust's process spawning cleans up resources properly.
//! Skipped on platforms without `ps` utility.

//@ run-pass
//@ needs-subprocess
//@ ignore-vxworks no 'ps'
Expand Down Expand Up @@ -36,35 +42,42 @@ fn find_zombies() {
// the PPID column contains a "-" for the respective process.
// Filter out any lines that have a "-" as the PPID as the PPID is
// expected to be an integer.
let filtered_ps: Vec<_> = ps_output
.lines()
.filter(|line| line.split_whitespace().nth(1) != Some("-"))
.collect();
let filtered_ps: Vec<_> =
ps_output.lines().filter(|line| line.split_whitespace().nth(1) != Some("-")).collect();

for (line_no, line) in filtered_ps.into_iter().enumerate() {
if 0 < line_no && 0 < line.len() &&
my_pid == line.split(' ').filter(|w| 0 < w.len()).nth(1)
.expect("1st column should be PPID")
.parse().ok()
.expect("PPID string into integer") &&
line.contains("defunct") {
if 0 < line_no
&& 0 < line.len()
&& my_pid
== line
.split(' ')
.filter(|w| 0 < w.len())
.nth(1)
.expect("1st column should be PPID")
.parse()
.ok()
.expect("PPID string into integer")
&& line.contains("defunct")
{
panic!("Zombie child {}", line);
}
}
}

#[cfg(windows)]
fn find_zombies() { }
fn find_zombies() {}

fn main() {
let too_long = format!("/NoSuchCommand{:0300}", 0u8);

let _failures = (0..100).map(|_| {
let mut cmd = Command::new(&too_long);
let failed = cmd.spawn();
assert!(failed.is_err(), "Make sure the command fails to spawn(): {:?}", cmd);
failed
}).collect::<Vec<_>>();
let _failures = (0..100)
.map(|_| {
let mut cmd = Command::new(&too_long);
let failed = cmd.spawn();
assert!(failed.is_err(), "Make sure the command fails to spawn(): {:?}", cmd);
failed
})
.collect::<Vec<_>>();

find_zombies();
// then _failures goes out of scope
Expand Down
Loading
Loading