Description
Hello. I was looking into a UI test failure with the aarch64-unknown-nto-qnx710
target. (but this is not a QNX specific issue as noted below)
The test is question is /tests/ui/structs-enums/enum-rec/issue-17431-6.rs
. The contents of the file have been copied below for your convenience.
//@ ignore-apple: cycle error does not appear on apple
use std::sync::Mutex;
enum Foo { X(Mutex<Option<Foo>>) }
//~^ ERROR recursive type `Foo` has infinite size
//~| ERROR cycle detected
impl Foo { fn bar(self) {} }
fn main() {}
The UI test expects the compiler to produce TWO error messages (see ERROR
comments in the code) but the compiler only produces ONE when the compilation target is aarch64-unknown-nto-qnx710
.
NOTE The issue can also be reproduced without a QNX toolchain on a Linux host using the aarch64-apple-darwin
target.
I have narrowed down the issue to compiletest
's internal use of the --emit metadata
flag. In other words, rustc --emit metadata --target aarch64-apple-darwin issue-17431-6.rs
produces ONE error; whereas rustc --target aarch64-apple-darwin issue-17431-6.rs
(no --emit
flag) produces the TWO error messages that the UI test expects.
I'm not sure why --emit metadata
triggers the issue but I suspect that Mutex
having OS / platform specific implementations (i.e. cfg
-style conditional compilation is involved) is part of the problem. After all, the error that's not reported is about a cycle being found when computing the layout of Foo
; the error includes note
s that list all the types beneath Foo
: that is Mutex
, UnsafeCell
, etc.
A workaround that fixes the UI test (when target = QNX) is to replace the Mutex
type with UnsafeCell
, that is
use std::cell::UnsafeCell;
enum Foo { X(UnsafeCell<Option<Foo>>) }
This change may let you drop the ignore-apple
compiletest attribute from the test but I haven't tested this change with an apple target.
Again, I suspect that this modified version does not run into the problem because UnsafeCell
does NOT have a target specific implementation / layout.
Meta
rustc --version --verbose
:
rustc 1.82.0-nightly (636d7ff91 2024-08-19)
binary: rustc
commit-hash: 636d7ff91b9847d6d43c7bbe023568828f6e3246
commit-date: 2024-08-19
host: x86_64-unknown-linux-gnu
release: 1.82.0-nightly
LLVM version: 19.1.0