Skip to content

tests/ui: A New Order [5/N] #141982

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

Merged
merged 1 commit into from
Jun 6, 2025
Merged
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
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
// Test that the borrow checker prevents pointers to temporaries
// with statement lifetimes from escaping.
//! Test that the borrow checker prevents pointers to temporaries
//! with statement lifetimes from escaping.

use std::ops::Drop;

static mut FLAGS: u64 = 0;

struct StackBox<T> { f: T }
struct AddFlags { bits: u64 }
struct StackBox<T> {
f: T,
}
struct AddFlags {
bits: u64,
}

fn AddFlags(bits: u64) -> AddFlags {
AddFlags { bits: bits }
AddFlags { bits }
}

fn arg(x: &AddFlags) -> &AddFlags {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:26:19
--> $DIR/rvalue-borrow-scope-error.rs:30:19
|
LL | let x1 = arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand All @@ -16,7 +16,7 @@ LL ~ let x1 = arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:27:14
--> $DIR/rvalue-borrow-scope-error.rs:31:14
|
LL | let x2 = AddFlags(1).get();
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand All @@ -33,7 +33,7 @@ LL ~ let x2 = binding.get();
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:28:21
--> $DIR/rvalue-borrow-scope-error.rs:32:21
|
LL | let x3 = &*arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand All @@ -50,7 +50,7 @@ LL ~ let x3 = &*arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:29:24
--> $DIR/rvalue-borrow-scope-error.rs:33:24
|
LL | let ref x4 = *arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand All @@ -67,7 +67,7 @@ LL ~ let ref x4 = *arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:30:24
--> $DIR/rvalue-borrow-scope-error.rs:34:24
|
LL | let &ref x5 = arg(&AddFlags(1));
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand All @@ -84,7 +84,7 @@ LL ~ let &ref x5 = arg(&binding);
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:31:14
--> $DIR/rvalue-borrow-scope-error.rs:35:14
|
LL | let x6 = AddFlags(1).get();
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand All @@ -101,7 +101,7 @@ LL ~ let x6 = binding.get();
|

error[E0716]: temporary value dropped while borrowed
--> $DIR/cleanup-rvalue-scopes-cf.rs:32:44
--> $DIR/rvalue-borrow-scope-error.rs:36:44
|
LL | let StackBox { f: x7 } = StackBox { f: AddFlags(1).get() };
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
Expand Down
128 changes: 0 additions & 128 deletions tests/ui/cleanup-rvalue-scopes.rs

This file was deleted.

39 changes: 0 additions & 39 deletions tests/ui/close-over-big-then-small-data.rs

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// This test checks the output format without the intermediate json representation
//! This test checks the output format without the intermediate json representation

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

pub fn main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0384]: cannot assign twice to immutable variable `x`
--> $DIR/command-line-diagnostics.rs:6:5
--> $DIR/command-line-error-format-human.rs:7:5
|
LL | let x = 42;
| - first assignment to `x`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
//@ run-pass
// Test that cleanups for the RHS of shortcircuiting operators work.
//! Test that cleanups for the RHS of shortcircuiting operators work.

//@ run-pass

#![allow(deref_nullptr)]


use std::env;

pub fn main() {
Expand All @@ -18,6 +17,8 @@ pub fn main() {

if args.len() >= 2 && args[1] == "signal" {
// Raise a segfault.
unsafe { *std::ptr::null_mut::<isize>() = 0; }
unsafe {
*std::ptr::null_mut::<isize>() = 0;
}
}
}
104 changes: 104 additions & 0 deletions tests/ui/lifetimes/rvalue-lifetime-drop-timing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
//! Test that destructors for temporaries run either at end of
//! statement or end of block as appropriate.

//@ run-pass

#![feature(box_patterns)]

static mut FLAGS: u64 = 0;

struct Box<T> {
f: T,
}

struct AddFlags {
bits: u64,
}

fn add_flags(bits: u64) -> AddFlags {
AddFlags { bits }
}

fn arg(expected: u64, _x: &AddFlags) {
check_flags(expected);
}

fn pass<T>(v: T) -> T {
v
}

fn check_flags(expected: u64) {
unsafe {
let actual = FLAGS;
FLAGS = 0;
assert_eq!(actual, expected, "flags {}, expected {}", actual, expected);
}
}

impl AddFlags {
fn check_flags(&self, expected: u64) -> &AddFlags {
check_flags(expected);
self
}

fn bits(&self) -> u64 {
self.bits
}
}

impl Drop for AddFlags {
fn drop(&mut self) {
unsafe {
FLAGS += self.bits;
}
}
}

macro_rules! end_of_block {
($pat:pat, $expr:expr) => {{
{
let $pat = $expr;
check_flags(0);
}
check_flags(1);
}};
}

macro_rules! end_of_stmt {
($pat:pat, $expr:expr) => {{
{
let $pat = $expr;
check_flags(1);
}
check_flags(0);
}};
}

fn main() {
end_of_block!(_x, add_flags(1));
end_of_block!(_x, &add_flags(1));
end_of_block!(_x, &&add_flags(1));
end_of_block!(_x, Box { f: add_flags(1) });
end_of_block!(_x, Box { f: &add_flags(1) });
end_of_block!(_x, pass(add_flags(1)));
end_of_block!(ref _x, add_flags(1));
end_of_block!(AddFlags { bits: ref _x }, add_flags(1));
end_of_block!(&AddFlags { bits: _ }, &add_flags(1));
end_of_block!((_, ref _y), (add_flags(1), 22));
end_of_block!(box ref _x, std::boxed::Box::new(add_flags(1)));
end_of_block!(box _x, std::boxed::Box::new(add_flags(1)));
end_of_block!(_, {
{
check_flags(0);
&add_flags(1)
}
});
end_of_block!(_, &((Box { f: add_flags(1) }).f));
end_of_block!(_, &(([add_flags(1)])[0]));

end_of_stmt!(_, add_flags(1));
end_of_stmt!((_, _), (add_flags(1), 22));
end_of_stmt!(ref _x, arg(0, &add_flags(1)));
end_of_stmt!(ref _x, add_flags(1).check_flags(0).bits());
end_of_stmt!(AddFlags { bits: _ }, add_flags(1));
}
Loading
Loading