Skip to content

Exhaustiveness #3

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

Open
nrc opened this issue Jul 14, 2021 · 0 comments
Open

Exhaustiveness #3

nrc opened this issue Jul 14, 2021 · 0 comments

Comments

@nrc
Copy link
Member

nrc commented Jul 14, 2021

Exhaustiveness checking could be incorrect in the presence of an incorrectly implemented deref function. This could lead to UB. Some possible solutions:

  • The compiler adds an implicit _ => unreachable!(), match arm for all sub-patterns which use deref. The match arm would not be generated if the user supplied one. The actual pattern would have _ as a sub-pattern, as required. E.g., when matching a scrutinee with type Option<Rc<bool>>, the generated arm would be equivalent to Some(_) => unreachable!(). Obviously the generated arm should not trigger any unreachable code lints. This is my personally preferred option.
  • We require the user to have an explicit _ match arm. This is boilerplatey.
  • Only allow deref in patterns for trusted types, e.g., a subset of std types.
  • Add a DerefPure trait or similar attribute to indicate to the compiler that a smart pointer is safe to be used with deref patterns. This option would require a lot of work to design, implement, and stabilise such a trait.
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

No branches or pull requests

1 participant