`--emit metadata` produces less error messages with some targets
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
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 notes 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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with tests/ui/structs-enums/enum-rec/issue-17431-6.rs and reproduce the target-specific behavior using the two rustc commands shown for aarch64-apple-darwin. Compare diagnostics with and without --emit metadata, including the Mutex and UnsafeCell variants. Done means the UI test consistently receives both expected errors for affected targets.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers, testing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100