-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
[WIP] implement explicit deref patterns through k#deref
#119467
Conversation
(rustbot has picked a reviewer for you, use r? to override) |
k#deref
k#deref
The job Click to see the possible cause of the failure (guessed by this bot)
|
r? compiler |
Also, |
re For point number 6, Nadrieril suggested that we do the |
@petrochenkov I don't think I agree. I think it should be totally fine as a placeholder here and can't really see any issues... |
☔ The latest upstream changes (presumably #119578) made this pull request unmergeable. Please resolve the merge conflicts. |
closing in favor of #122222. |
…r=compiler-errors deref patterns: bare-bones feature gate and typechecking I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team [experimental feature](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md) process, with [`@cramertj` as lang-team liaison](rust-lang/lang-team#88) (it's been a while though, you still ok with this `@cramertj?).` Tracking issue: rust-lang#87121. This is the barest-bones implementation I could think of: - explicit syntax, reusing `box <pat>` because that saves me a ton of work; - use `Deref` as a marker trait (instead of a yet-to-design `DerefPure`); - no support for mutable patterns with `DerefMut` for now; - MIR lowering will come in the next PR. It's the trickiest part. My goal is to let us figure out the MIR lowering part, which might take some work. And hopefully get something working for std types soon. This is in large part salvaged from `@fee1-dead's` rust-lang#119467. r? `@compiler-errors`
…r=compiler-errors deref patterns: bare-bones feature gate and typechecking I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team [experimental feature](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md) process, with [``@cramertj`` as lang-team liaison](rust-lang/lang-team#88) (it's been a while though, you still ok with this ``@cramertj?).`` Tracking issue: rust-lang#87121. This is the barest-bones implementation I could think of: - explicit syntax, reusing `box <pat>` because that saves me a ton of work; - use `Deref` as a marker trait (instead of a yet-to-design `DerefPure`); - no support for mutable patterns with `DerefMut` for now; - MIR lowering will come in the next PR. It's the trickiest part. My goal is to let us figure out the MIR lowering part, which might take some work. And hopefully get something working for std types soon. This is in large part salvaged from ``@fee1-dead's`` rust-lang#119467. r? ``@compiler-errors``
…r=compiler-errors deref patterns: bare-bones feature gate and typechecking I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team [experimental feature](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md) process, with [```@cramertj``` as lang-team liaison](rust-lang/lang-team#88) (it's been a while though, you still ok with this ```@cramertj?).``` Tracking issue: rust-lang#87121. This is the barest-bones implementation I could think of: - explicit syntax, reusing `box <pat>` because that saves me a ton of work; - use `Deref` as a marker trait (instead of a yet-to-design `DerefPure`); - no support for mutable patterns with `DerefMut` for now; - MIR lowering will come in the next PR. It's the trickiest part. My goal is to let us figure out the MIR lowering part, which might take some work. And hopefully get something working for std types soon. This is in large part salvaged from ```@fee1-dead's``` rust-lang#119467. r? ```@compiler-errors```
…r=compiler-errors deref patterns: bare-bones feature gate and typechecking I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team [experimental feature](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md) process, with [````@cramertj```` as lang-team liaison](rust-lang/lang-team#88) (it's been a while though, you still ok with this ````@cramertj?).```` Tracking issue: rust-lang#87121. This is the barest-bones implementation I could think of: - explicit syntax, reusing `box <pat>` because that saves me a ton of work; - use `Deref` as a marker trait (instead of a yet-to-design `DerefPure`); - no support for mutable patterns with `DerefMut` for now; - MIR lowering will come in the next PR. It's the trickiest part. My goal is to let us figure out the MIR lowering part, which might take some work. And hopefully get something working for std types soon. This is in large part salvaged from ````@fee1-dead's```` rust-lang#119467. r? ````@compiler-errors````
Rollup merge of rust-lang#122222 - Nadrieril:deref-pat-feature-gate, r=compiler-errors deref patterns: bare-bones feature gate and typechecking I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team [experimental feature](https://github.com/rust-lang/lang-team/blob/master/src/how_to/experiment.md) process, with [````@cramertj```` as lang-team liaison](rust-lang/lang-team#88) (it's been a while though, you still ok with this ````@cramertj?).```` Tracking issue: rust-lang#87121. This is the barest-bones implementation I could think of: - explicit syntax, reusing `box <pat>` because that saves me a ton of work; - use `Deref` as a marker trait (instead of a yet-to-design `DerefPure`); - no support for mutable patterns with `DerefMut` for now; - MIR lowering will come in the next PR. It's the trickiest part. My goal is to let us figure out the MIR lowering part, which might take some work. And hopefully get something working for std types soon. This is in large part salvaged from ````@fee1-dead's```` rust-lang#119467. r? ````@compiler-errors````
Some technical considerations: (feel free to add to the list)
k#ident
keywords as valid tokens #119351, adding support for thek#ident
syntax.ast::PatKind::Deref
,hir::PatKind::Deref
,thir::PatKind::DerefPattern
,mir::TestKind::Deref
.Deref
for now, but we might want a different trait (DerefPure
) later.expected
(input type of the expression) type exactly once for simplicity, and then type check the inner pattern with<expected as Deref>::Target
. Doing multiple derefs with a singlek#deref
isn't supported for now, and we might want to explore how to do implicit/multiple derefs later.place
), creates a temporary references&place
, then callsderef
. (place2 = Deref::deref(&place)
). The inner patterns then use(*place2)
for continued matching. This means: (TODO: add test for types that cannot be moved out)vec-2.rs
test for this) Clarification: skipping false edges are done because deref patterns generate temporaries that are used to create bindings. When false edges are generated for deref patterns the temporaries don't get assigned to since they are assigned to during the tests and not before an arm block starts, which lead to borrowck errors.sort_candidate
, where we replace the original match pair ofPatKind::DerefPattern
with the inner pattern on the new temporary created by the deref. Note that sincesort_candidate
can be called on multiple candidates after a test is performed, we need to ensure that the peeling of deref pattern on a match pair only happens once (throughis_first
), so that the subsequent match arms all do their derefs individually and get tested individually.Deref
as being deliberately minimal. We would want to figure out the binding mode and try doing the appropriate deref in the future.is_first
is opposed to this idea. We'd probably want to explore whetheris_first
is really necessary with more testing.cc @compiler-errors @BoxyUwU @Nadrieril @matthewjasper @tgross35 @CAD97 (would like to hear from you about the implementation)