Skip to content

ast: the id of a ref pattern conflated; has type T in some contexts and &T in others #18207

Closed
@pnkfelix

Description

@pnkfelix

While working on my follow-up to #17439 I rediscovered an old problem in our ast representation:

We usually act like you can unambiguously map a node_id to a single type for that node id. However, if you want to know the type of a pattern like the ref x in:

let t = Some(box 3i);
match t {
  Some(ref x) => ...,
  None => ...,
}

then you have a problem: are you trying to find the type of the thing that is being borrowed by the match (i.e. int in this case)? Or are you trying to find the type of x itself (&int in this case)?

The problem is that there is just one node_id for the entire ref <id> pattern, even though there are two distinct things that you are potentially trying to match.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-lowLow priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions