Skip to content

fix: Look for enum variants and trait assoc functions when looking for lang items #9808

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

Merged
merged 1 commit into from
Aug 8, 2021

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Aug 7, 2021

Examples for lang enum variants are the Option variants.
Assoc trait functions aren't being seen since they aren't declared in the direct module scope.

@matklad
Copy link
Member

matklad commented Aug 8, 2021

bors r+

I wonder why Option needs to be a lang item though?

@bors
Copy link
Contributor

bors bot commented Aug 8, 2021

@bors bors bot merged commit 546d718 into rust-lang:master Aug 8, 2021
@Veykril Veykril deleted the lang-items branch August 8, 2021 10:49
@Veykril
Copy link
Member Author

Veykril commented Aug 8, 2021

Good question, Result's variants are also lang items so imagine it might be due to ? being more special cased back then? at least from what I remember it had a very specific desugaring, might be wrong.

@Veykril
Copy link
Member Author

Veykril commented Aug 8, 2021

Interesting, they were added for AST lowering purposes rust-lang/rust#75145

@matklad
Copy link
Member

matklad commented Aug 8, 2021

Interesting! So that means that we might want to change hir_def::Expr::Path to point either to an unresolved path, or to a resolved def.

I don't think we do a lot of desugaring today, we have an explicit Expr::For, Expr::Try etc. Instead, all those are handled explicitly in the type inference, and that's where we need to get "known" items.

I think that's the right pattern -- AST-based desugaring is a nice thing in theory, but, in practice, it doesn't save that much effort. And the lowering shape in rustc, which has this awkward effect of needing both unresolved and resolved paths in the same data type, feels like an evidence for awkwardness of lowering.

At this point, it seems that it's better to carry the surface syntax as is through the type-inference, and then, in a single step, resolve all names and simplify things to some core language.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants