-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
feat: dedup "the size for values ... cannot be known" error #108733
Conversation
r? @cjgillot (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not checking whether the type is sized when we do require it is not a solution to extra diagnostics. I'd rather have a solution based on tweaking the diagnostic output, not a change to the type-checking logic.
I realize now that my impl is not going to work. Some advice on what can be done would be nice. Although I don't think that diagnostic de-duplication will work, it'd still require changes to typechecking. What would probably be best is if we kept the local variable error and attached a note saying that the bound value is unsized. EDIT: how can I check if an expression is bound to a local variable? |
Would wrapping the sized check in: let parent = tcx.hir().parent_id(expr.hir_id);
let parent = tcx.hir().get_parent(parent);
if !matches!(parent, hir::Node::Local(..)) {
// ...
} work? All local variables are still guaranteed to be sized. Is there some way to downgrade this error with |
This comment has been minimized.
This comment has been minimized.
7e2a36f
to
4904ae9
Compare
@cjgillot @compiler-errors I've implemented what I said above. |
I'm still pretty uncomfortable with this approach, and still think @cjgillot's initial comment is valid. I still think this needs to be focused on diagnostic deduplication via post-processing, rather than relaxing where a type is required to be |
@compiler-errors Do you have any advice on where to start with that? I'm not entirely sure what you mean by "diagnostics deduplication" (I associate that with |
Sorry, not sure if I can give much advice. By diagnostics deduplication, I mean the general approach to maintaining additional state that can be used to soundly defuse reporting errors for We do that in various other ways in other places in the compiler (unfortunately, in pretty ad-hoc ways as well, though, so not sure if you can adopt any machinery to help you with this). Fixing this probably requires some novel brainstorming, and it's not something I've given much though towards, since these redundant errors issues are typically P-low and haven't really caught my interest recently. At the end of the day, registering fewer |
I note that emphasis, in this case it is definitely a redundant error which is completely unnecessary and confusing.
Sorry for the excess clarification but this can be done with Also (and I know my current approach isn't ideal) could you point to a concrete example where this code causes unsoundness or ICEs? |
Maybe a better approach is to determine whether def-site (i.e. defining a function) errors imply ref-site (i.e. referencing a function) errors. To be more specific, in the original issue (#105753), the first error ( After checking the code, it seems that currently we do have similar logic in order to remove fulfillment errors that are implied by others. rust/compiler/rustc_trait_selection/src/traits/error_reporting/mod.rs Lines 429 to 458 in 8a7ca93
However, its current capability is limited by removing duplicate errors at only the same span. It should be reasonable as it is not easy to determine whether errors are really duplicate if they happen at different places. But back in this issue, we know that def-site unsized errors and ref-site unsized errors are actually related, so we should be confident at removing the ref-site errors (once ref-site errors are indeed implied by call-site errors?). In fact, it also seems that we do not have enough information (in the rust/compiler/rustc_middle/src/traits/mod.rs Lines 304 to 305 in 553ecbe
(Just a few of my own thoughts. I'm not very familiar with related code so things could be wrong.. cc @compiler-errors as he have contributed much in the related files.) |
@lrh2000 I think that you're right, I'll probably try to implement this. The only thing might be around how this interacts with |
4904ae9
to
9673115
Compare
See https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler/topic/dedup.20sized.20errors.20PR/near/350151854 for rationale behind latest attempt. |
This comment has been minimized.
This comment has been minimized.
9673115
to
aaf68c8
Compare
Fixes #105753
Two points on the UI updates:- most are de-duplicating trait errors (which I assume come frominstantiate_binder_with_fresh_vars
), this is invisible to the user regardless.-tests/ui/unsized-locals/unsized-exprs.rs
: seems to make sense withinunsized_fn_params
.out of date