Dealing with type/const ambiguities #480
Labels
major-change
A proposal to make a major change to rustc
T-compiler
Add this label so rfcbot knows to poll the compiler team
Proposal
It is not always possible to check whether a given generic argument should be a type or a const until typeck. While this is mostly fine, this most makes it difficult to represent ambiguous paths and
_
in thehir
.Examples
This is the behavior on stable:
As we want to be able to resolve that ambiguity and get the above example to compile, we need a way to represent ambiguous generic arguments in the
hir
(and to a lesser degree in theast
). This representation should ideally avoid multiple equivalent representation and minimize the risk of misuse.This MCP only cares about the
hir
for now as we don't really use theast
for anything which cares about types or constants.Suggested solution
Modify the
hir
AST to the followingWith this setup, every type and constant can only be represented one way.
How
hir::intravisit::Visitor
should now be implemented to avoid bugs while still being fairly usable.While we need to add comments to
visit_ty
on how to deal with_
and paths, you can't really misuse that as these variants just don't exist.Another issue is what happens if we want to get a
ty::Ty
for somehir::Ty
. Afaict the only hir visitor which does that isHirWfCheck
which I intend to manually update to also considerSharedTyConst
. I am not sure if there's a good way to prevent us from forgetting this in the general case.Sidenote: Paths and nameres
Not yet sure how to best deal with the ambiguity for paths during nameres, maybe by adding a variant
Res::ForGenericArg(Box<[Res; 2]>)
or something? 🤷Mentors or Reviewers
If you have a reviewer or mentor in mind for this work, mention then
here. You can put your own name here if you are planning to mentor the
work.
Process
The main points of the Major Change Process are as follows:
@rustbot second
.-C flag
, then full team check-off is required.@rfcbot fcp merge
on either the MCP or the PR.You can read more about Major Change Proposals on forge.
Comments
This issue is not meant to be used for technical discussion. There is a Zulip stream for that. Use this issue to leave procedural comments, such as volunteering to review, indicating that you second the proposal (or third, etc), or raising a concern that you would like to be addressed.
The text was updated successfully, but these errors were encountered: