Skip to content

Commit c3a632c

Browse files
Rollup merge of rust-lang#133074 - ferrocene:ja-make-ui-test-os-agnostic, r=Noratrieb
make UI test OS-agnostic the internal representation of `std::sync::Mutex` depends on the compilation target. due to this, the compiler produces different number of errors for UI test `issue-17431-6.rs` depending on the compilation target. for example, when compiling the UI test to an `*-apple-*` or `*-qnx7*` target, the "cycle detected" error is not reported ``` console $ cat src/lib.rs use std::sync::Mutex; enum Foo { X(Mutex<Option<Foo>>), } impl Foo { fn bar(self) {} } fn main() {} $ cargo check --target x86_64-apple-ios 2>&1 | rg '^error\[' error[E0072]: recursive type `Foo` has infinite size ``` whereas rustc produces two errors for other OSes, like Linux, which is what the UI test expects ``` console $ cargo check --target x86_64-unknown-linux-gnu 2>&1 | rg '^error\[' error[E0072]: recursive type `Foo` has infinite size error[E0391]: cycle detected when computing when `Foo` needs drop ``` this commit replaces the problematic `Mutex` with `UnsafeCell`, which has the same internal representation regardless of the compilation target. with that change, rustc reports two errors for all compilation targets. ``` console $ cat src/lib.rs use std::cell::UnsafeCell; enum Foo { X(UnsafeCell<Option<Foo>>), } impl Foo { fn bar(self) {} } fn main() {} $ cargo check --target x86_64-apple-ios 2>&1 | rg '^error\[' error[E0072]: recursive type `Foo` has infinite size error[E0391]: cycle detected when computing when `Foo` needs drop ``` with this change, we can remove the `ignore-apple` directive as the UI test now also passes on apple targets.
2 parents b3e2981 + 7f02756 commit c3a632c

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Diff for: tests/ui/structs-enums/enum-rec/issue-17431-6.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
1-
//@ ignore-apple: cycle error does not appear on apple
1+
use std::cell::UnsafeCell;
22

3-
use std::sync::Mutex;
4-
5-
enum Foo { X(Mutex<Option<Foo>>) }
3+
enum Foo { X(UnsafeCell<Option<Foo>>) }
64
//~^ ERROR recursive type `Foo` has infinite size
75
//~| ERROR cycle detected
86

Diff for: tests/ui/structs-enums/enum-rec/issue-17431-6.stderr

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
error[E0072]: recursive type `Foo` has infinite size
2-
--> $DIR/issue-17431-6.rs:5:1
2+
--> $DIR/issue-17431-6.rs:3:1
33
|
4-
LL | enum Foo { X(Mutex<Option<Foo>>) }
5-
| ^^^^^^^^ --- recursive without indirection
4+
LL | enum Foo { X(UnsafeCell<Option<Foo>>) }
5+
| ^^^^^^^^ --- recursive without indirection
66
|
77
help: insert some indirection (e.g., a `Box`, `Rc`, or `&`) to break the cycle
88
|
9-
LL | enum Foo { X(Mutex<Option<Box<Foo>>>) }
10-
| ++++ +
9+
LL | enum Foo { X(UnsafeCell<Option<Box<Foo>>>) }
10+
| ++++ +
1111

1212
error[E0391]: cycle detected when computing when `Foo` needs drop
13-
--> $DIR/issue-17431-6.rs:5:1
13+
--> $DIR/issue-17431-6.rs:3:1
1414
|
15-
LL | enum Foo { X(Mutex<Option<Foo>>) }
15+
LL | enum Foo { X(UnsafeCell<Option<Foo>>) }
1616
| ^^^^^^^^
1717
|
1818
= note: ...which immediately requires computing when `Foo` needs drop again

0 commit comments

Comments
 (0)