-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cycle error through variance computation when using -> _
.
#72730
Comments
#72707 had to do this to because I couldn't get the default impl to work with |
@matthewjasper Can you split that part out and PM me on Discord/Zulip when you do? |
I think one of the things we could also do to improve this kind of query cycle error is to replace:
with
That's because we know why we queried So we can just change this line (i.e. by adding rust/src/librustc_typeck/collect.rs Line 1474 in 4b1f86a
let fn_sig = tcx.at(ty.span).typeck_tables_of(def_id).liberated_fn_sigs()[hir_id]; |
Since I'm looking through typeck, thought I'd take a look at the underlying cause: rust/src/librustc_typeck/variance/constraints.rs Lines 160 to 162 in 4b1f86a
I thought that was unused/vestigial, but it does seem to be used when relating "function item" types ( rust/src/librustc_middle/ty/relate.rs Lines 471 to 476 in 4b1f86a
So if That entire behavior seems vestigial, I wonder what we can do backwards-compatibly. The easiest thing to do would be to make it invariant. It might even work out. Nominating for discussion (on the topic of variance of "function item" types). |
…ddyb Add descriptions for all queries This also removes the default description for queries with DefId keys and makes the macro validate that a description is provided. cc rust-lang#72730 r? @eddyb
I sort of remember that you added in the variance to enable backwards compatibility of I'm not sure what you mean by the "most compatible thing would be bivariant", in part because "bivariant" is perhaps not that well-defined. I think we want to maintain the invariant (no pun intended) that if you have a given fn-def type |
Unnominating this as it was already discussed in our last |
Reduced example (playground):
You can see right away that it's hard to figure out what "processing" means and we should probably start a cleanup effort to add proper descriptions to queries (or at least name the query in the default message, even if it might not look pretty at all). cc @rust-lang/compiler
Using
-Ztreat-err-as-bug
+RUST_BACKTRACE=1
I can turn the error into an ICE and get this:So variance computation uses
fn_sig
(not sure why it would need to), which is normally harmless, as function signatures are fully explicit.But we nowadays "allow"
_
in the signature, guaranteeing an error still, while showing the user the inferred type (this should be useful during prototyping but I keep forgetting it exists).As a result of that, instead of
typeck_tables_of
depending onfn_sig
,fn_sig
depends ontypeck_tables_of
(since it needs the results of type inference from thefn
body), so an otherwise harmlessfn_sig
turns into a cycle as soon as type-checking needs any variances.The text was updated successfully, but these errors were encountered: