Skip to content
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

deref patterns: bare-bones feature gate and typechecking #122222

Merged
merged 1 commit into from
Mar 21, 2024

Conversation

Nadrieril
Copy link
Member

I am restarting the deref patterns experimentation. This introduces a feature gate under the lang-team experimental feature process, with @cramertj as lang-team liaison (it's been a while though, you still ok with this @cramertj?). Tracking issue: #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 #119467.

r? @compiler-errors

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Mar 9, 2024
@Nadrieril Nadrieril added the F-deref_patterns `#![feature(deref_patterns)]` label Mar 9, 2024
@Nadrieril Nadrieril mentioned this pull request Mar 9, 2024
6 tasks
@rust-log-analyzer

This comment has been minimized.

@Nadrieril Nadrieril force-pushed the deref-pat-feature-gate branch 2 times, most recently from 8242838 to 2e1f7ab Compare March 9, 2024 04:32
compiler/rustc_hir_typeck/src/pat.rs Outdated Show resolved Hide resolved
compiler/rustc_middle/src/thir.rs Outdated Show resolved Hide resolved
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 9, 2024
@compiler-errors
Copy link
Member

pls squash as well, ty

regarding the lang team experiment, it may need a new liaison since @cramertj is no longer on T-lang

@Nadrieril
Copy link
Member Author

Ok, I've asked around for a new lang-team liaison

@safinaskar
Copy link
Contributor

Please, add more tests. I want to see how this is supposed to work. In particular I'd like to see this code in tests:

let a = Rc::new(vec![0]);
let x = match a {
  box x => x,
}
let a = Rc::new(vec![0]);
let x: &Vec<i32> = match &a {
  box x => x,
}

As well as I understand the first example should not compile (because you cannot move out of Rc), but the second - should

@Nadrieril
Copy link
Member Author

Nadrieril commented Mar 9, 2024

These test are not yet possible, because patterns are not lowered correctly to MIR. This is the very first beginnings of implementing the feature, more tests will come in later PRs. (I've just added your examples to my next PR, thank you for them. You are correct about how they should work).

@Nadrieril
Copy link
Member Author

We have a liaison!

@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 20, 2024

📌 Commit bf7951d has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 20, 2024
@compiler-errors
Copy link
Member

Actually

@bors r-

this needs rebasing

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Mar 20, 2024
Co-authored-by: Deadbeef <ent3rm4n@gmail.com>
@compiler-errors
Copy link
Member

@bors r+

@bors
Copy link
Contributor

bors commented Mar 20, 2024

📌 Commit 120d357 has been approved by compiler-errors

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Mar 20, 2024
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 21, 2024
…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`
workingjubilee added a commit to workingjubilee/rustc that referenced this pull request Mar 21, 2024
…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``
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 21, 2024
…kingjubilee

Rollup of 9 pull requests

Successful merges:

 - rust-lang#122222 (deref patterns: bare-bones feature gate and typechecking)
 - rust-lang#122456 (CFI: Skip non-passed arguments)
 - rust-lang#122696 (Add bare metal riscv32 target.)
 - rust-lang#122771 (add some comments to hir::ModuleItems)
 - rust-lang#122773 (make "expected paren or brace" error translatable)
 - rust-lang#122795 (Inherit `RUSTC_BOOTSTRAP` when testing wasm)
 - rust-lang#122799 (Replace closures with `_` when suggesting fully qualified path for method call)
 - rust-lang#122801 (Fix misc printing issues in emit=stable_mir)
 - rust-lang#122806 (Make `type_ascribe!` not a built-in)

r? `@ghost`
`@rustbot` modify labels: rollup
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 21, 2024
…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```
bors added a commit to rust-lang-ci/rust that referenced this pull request Mar 21, 2024
…iaskrgr

Rollup of 8 pull requests

Successful merges:

 - rust-lang#122222 (deref patterns: bare-bones feature gate and typechecking)
 - rust-lang#122358 (Don't ICE when encountering bound regions in generator interior type)
 - rust-lang#122696 (Add bare metal riscv32 target.)
 - rust-lang#122773 (make "expected paren or brace" error translatable)
 - rust-lang#122795 (Inherit `RUSTC_BOOTSTRAP` when testing wasm)
 - rust-lang#122799 (Replace closures with `_` when suggesting fully qualified path for method call)
 - rust-lang#122801 (Fix misc printing issues in emit=stable_mir)
 - rust-lang#122806 (Make `type_ascribe!` not a built-in)

Failed merges:

 - rust-lang#122771 (add some comments to hir::ModuleItems)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 0867025 into rust-lang:master Mar 21, 2024
11 checks passed
@rustbot rustbot added this to the 1.79.0 milestone Mar 21, 2024
@bors
Copy link
Contributor

bors commented Mar 21, 2024

⌛ Testing commit 120d357 with merge 2627e9f...

rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 21, 2024
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````
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Mar 21, 2024
…r=Nadrieril

Implement macro-based deref!() syntax for deref patterns

Stop using `box PAT` syntax for deref patterns, and instead use a perma-unstable macro.

Blocked on rust-lang#122222

r? `@Nadrieril`
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Mar 21, 2024
Rollup merge of rust-lang#122793 - compiler-errors:deref-pat-syntax, r=Nadrieril

Implement macro-based deref!() syntax for deref patterns

Stop using `box PAT` syntax for deref patterns, and instead use a perma-unstable macro.

Blocked on rust-lang#122222

r? `@Nadrieril`
@Nadrieril Nadrieril deleted the deref-pat-feature-gate branch March 21, 2024 20:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F-deref_patterns `#![feature(deref_patterns)]` S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants