Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 5e140db

Browse files
Rollup merge of #141982 - Kivooeo:tf5, r=jieyouxu
`tests/ui`: A New Order [5/N] > [!NOTE] > > Intermediate commits are intended to help review, but will be squashed prior to merge. r? ``@jieyouxu``
2 parents c141cbf + 9770f9b commit 5e140db

9 files changed

+135
-188
lines changed

‎tests/ui/cleanup-rvalue-scopes-cf.rs‎ renamed to ‎tests/ui/borrowck/rvalue-borrow-scope-error.rs‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
1-
// Test that the borrow checker prevents pointers to temporaries
2-
// with statement lifetimes from escaping.
1+
//! Test that the borrow checker prevents pointers to temporaries
2+
//! with statement lifetimes from escaping.
33
44
use std::ops::Drop;
55

66
static mut FLAGS: u64 = 0;
77

8-
struct StackBox<T> { f: T }
9-
struct AddFlags { bits: u64 }
8+
struct StackBox<T> {
9+
f: T,
10+
}
11+
struct AddFlags {
12+
bits: u64,
13+
}
1014

1115
fn AddFlags(bits: u64) -> AddFlags {
12-
AddFlags { bits: bits }
16+
AddFlags { bits }
1317
}
1418

1519
fn arg(x: &AddFlags) -> &AddFlags {

‎tests/ui/cleanup-rvalue-scopes-cf.stderr‎ renamed to ‎tests/ui/borrowck/rvalue-borrow-scope-error.stderr‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0716]: temporary value dropped while borrowed
2-
--> $DIR/cleanup-rvalue-scopes-cf.rs:26:19
2+
--> $DIR/rvalue-borrow-scope-error.rs:30:19
33
|
44
LL | let x1 = arg(&AddFlags(1));
55
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement
@@ -16,7 +16,7 @@ LL ~ let x1 = arg(&binding);
1616
|
1717

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

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

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

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

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

103103
error[E0716]: temporary value dropped while borrowed
104-
--> $DIR/cleanup-rvalue-scopes-cf.rs:32:44
104+
--> $DIR/rvalue-borrow-scope-error.rs:36:44
105105
|
106106
LL | let StackBox { f: x7 } = StackBox { f: AddFlags(1).get() };
107107
| ^^^^^^^^^^^ - temporary value is freed at the end of this statement

‎tests/ui/cleanup-rvalue-scopes.rs‎

Lines changed: 0 additions & 128 deletions
This file was deleted.

‎tests/ui/close-over-big-then-small-data.rs‎

Lines changed: 0 additions & 39 deletions
This file was deleted.

‎tests/ui/command-line-diagnostics.rs‎ renamed to ‎tests/ui/diagnostic-width/command-line-error-format-human.rs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
// This test checks the output format without the intermediate json representation
1+
//! This test checks the output format without the intermediate json representation
2+
23
//@ compile-flags: --error-format=human
34

45
pub fn main() {

‎tests/ui/command-line-diagnostics.stderr‎ renamed to ‎tests/ui/diagnostic-width/command-line-error-format-human.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0384]: cannot assign twice to immutable variable `x`
2-
--> $DIR/command-line-diagnostics.rs:6:5
2+
--> $DIR/command-line-error-format-human.rs:7:5
33
|
44
LL | let x = 42;
55
| - first assignment to `x`

‎tests/ui/cleanup-shortcircuit.rs‎ renamed to ‎tests/ui/lifetimes/rvalue-cleanup-shortcircuit.rs‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
1-
//@ run-pass
2-
// Test that cleanups for the RHS of shortcircuiting operators work.
1+
//! Test that cleanups for the RHS of shortcircuiting operators work.
32
3+
//@ run-pass
44

55
#![allow(deref_nullptr)]
66

7-
87
use std::env;
98

109
pub fn main() {
@@ -18,6 +17,8 @@ pub fn main() {
1817

1918
if args.len() >= 2 && args[1] == "signal" {
2019
// Raise a segfault.
21-
unsafe { *std::ptr::null_mut::<isize>() = 0; }
20+
unsafe {
21+
*std::ptr::null_mut::<isize>() = 0;
22+
}
2223
}
2324
}
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
//! Test that destructors for temporaries run either at end of
2+
//! statement or end of block as appropriate.
3+
4+
//@ run-pass
5+
6+
#![feature(box_patterns)]
7+
8+
static mut FLAGS: u64 = 0;
9+
10+
struct Box<T> {
11+
f: T,
12+
}
13+
14+
struct AddFlags {
15+
bits: u64,
16+
}
17+
18+
fn add_flags(bits: u64) -> AddFlags {
19+
AddFlags { bits }
20+
}
21+
22+
fn arg(expected: u64, _x: &AddFlags) {
23+
check_flags(expected);
24+
}
25+
26+
fn pass<T>(v: T) -> T {
27+
v
28+
}
29+
30+
fn check_flags(expected: u64) {
31+
unsafe {
32+
let actual = FLAGS;
33+
FLAGS = 0;
34+
assert_eq!(actual, expected, "flags {}, expected {}", actual, expected);
35+
}
36+
}
37+
38+
impl AddFlags {
39+
fn check_flags(&self, expected: u64) -> &AddFlags {
40+
check_flags(expected);
41+
self
42+
}
43+
44+
fn bits(&self) -> u64 {
45+
self.bits
46+
}
47+
}
48+
49+
impl Drop for AddFlags {
50+
fn drop(&mut self) {
51+
unsafe {
52+
FLAGS += self.bits;
53+
}
54+
}
55+
}
56+
57+
macro_rules! end_of_block {
58+
($pat:pat, $expr:expr) => {{
59+
{
60+
let $pat = $expr;
61+
check_flags(0);
62+
}
63+
check_flags(1);
64+
}};
65+
}
66+
67+
macro_rules! end_of_stmt {
68+
($pat:pat, $expr:expr) => {{
69+
{
70+
let $pat = $expr;
71+
check_flags(1);
72+
}
73+
check_flags(0);
74+
}};
75+
}
76+
77+
fn main() {
78+
end_of_block!(_x, add_flags(1));
79+
end_of_block!(_x, &add_flags(1));
80+
end_of_block!(_x, &&add_flags(1));
81+
end_of_block!(_x, Box { f: add_flags(1) });
82+
end_of_block!(_x, Box { f: &add_flags(1) });
83+
end_of_block!(_x, pass(add_flags(1)));
84+
end_of_block!(ref _x, add_flags(1));
85+
end_of_block!(AddFlags { bits: ref _x }, add_flags(1));
86+
end_of_block!(&AddFlags { bits: _ }, &add_flags(1));
87+
end_of_block!((_, ref _y), (add_flags(1), 22));
88+
end_of_block!(box ref _x, std::boxed::Box::new(add_flags(1)));
89+
end_of_block!(box _x, std::boxed::Box::new(add_flags(1)));
90+
end_of_block!(_, {
91+
{
92+
check_flags(0);
93+
&add_flags(1)
94+
}
95+
});
96+
end_of_block!(_, &((Box { f: add_flags(1) }).f));
97+
end_of_block!(_, &(([add_flags(1)])[0]));
98+
99+
end_of_stmt!(_, add_flags(1));
100+
end_of_stmt!((_, _), (add_flags(1), 22));
101+
end_of_stmt!(ref _x, arg(0, &add_flags(1)));
102+
end_of_stmt!(ref _x, add_flags(1).check_flags(0).bits());
103+
end_of_stmt!(AddFlags { bits: _ }, add_flags(1));
104+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /