Skip to content

Abort after representability errors#153317

Open
nnethercote wants to merge 2 commits intorust-lang:mainfrom
nnethercote:abort-after-infinite-errors
Open

Abort after representability errors#153317
nnethercote wants to merge 2 commits intorust-lang:mainfrom
nnethercote:abort-after-infinite-errors

Conversation

@nnethercote
Copy link
Contributor

Doing so results in better error messages and makes the code a bit simpler. Details in individual commits.

r? @oli-obk

Currently, `Representability::from_cycle_error` prints an "infinite
size" error and then returns `Representability::Infinite`, which lets
analysis continue. This commit changes it so it just aborts after
printing the error. This has two benefits.

First, the error messages are better. The error messages we get after
continuing are mostly bad -- we usually get another cycle error, e.g.
about drop checking or layout, which is not much use to the user, and
then abort after that. The only exception is `issue-105231.rs` where a
"conflicting implementations" error is now omitted, but there are three
other errors before that one so it's no great loss.

Second, it allows some simplifications: see the next commit.
@rustbot rustbot added A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 3, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 3, 2026

oli-obk is not on the review rotation at the moment.
They may take a while to respond.

@nnethercote
Copy link
Contributor Author

This overlaps with #153028 by @Zoxc. (I wrote this independently a few days ago after writing #153169 and then subsequently discovered the overlap.) That PR changes the representability queries and also adds per-query cycle handlers. Those changes are all combined into a single large commit and the review comments have been mixed, so I thought it worth creating this PR for just the representability changes. They improve error messages, make the code simpler, don't get in the way of removing query cycle handling, but also don't commit to removing query cycle handling (which @zetanumbers has concerns about). I have also introduced the use of ensure_ok() and added check_ prefixes to the queries, which I think are good.

@rust-log-analyzer

This comment has been minimized.

This variant was a fallback value used to continue analysis after a
`Representability` error, but it's no longer needed thanks to the
previous commit. This means `Representability` can now be reduced to a
unit type that exists just so `FromCycleError` can exist for the
`representability` query. (There is potential for additional cleanups
here, but those are beyond the scope of this PR.)

This means the `representability`/`representability_adt_ty` queries no
longer have a meaningful return value, i.e. they are check-only queries.
So they now use `ensure_ok()` (which required removing the `anon`
modifier), and have a `check_` prefix added. And the `rtry!` macro is no
longer needed.
@nnethercote nnethercote force-pushed the abort-after-infinite-errors branch from 44bc328 to 8675222 Compare March 3, 2026 01:46
@nnethercote
Copy link
Contributor Author

I have also introduced the use of ensure_ok()

Turns out this doesn't work for the reason because it requires dropping anon from the queries, which caused an incremental test failure. So I have undone that part, and I am just using let _ = tcx.check_representability(...);.

Representable,
Infinite(ErrorGuaranteed),
}
pub struct Representability;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that you haven't got rid of this type, although I would have made it pub struct Representability(()) in order to make its construction a private detail for a query implementation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, but we cannot do that as query implementation is in another crate. I guess I would've done new_unchecked unsafe fn instead then if rustc was my project, but that's kinda a far too theoretical concern for an open project.

@petrochenkov
Copy link
Contributor

I have also introduced the use of ensure_ok()

Turns out this doesn't work for the reason because it requires dropping anon from the queries, which caused an incremental test failure. So I have undone that part, and I am just using let _ = tcx.check_representability(...);.

The second commit message still mentions ensure_ok and anon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-query-system Area: The rustc query system (https://rustc-dev-guide.rust-lang.org/query.html) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants