Skip to content

Raw Pointers are Constant PatKinds too #144573

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

Merged
merged 1 commit into from
Jul 29, 2025

Conversation

BoxyUwU
Copy link
Member

@BoxyUwU BoxyUwU commented Jul 28, 2025

raw pointers can be matched on with a const pattern:

const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}

as far as I can tell this is represented with a PatKind::Constant: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337

@rustbot
Copy link
Collaborator

rustbot commented Jul 28, 2025

r? @lcnr

rustbot has assigned @lcnr.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@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 Jul 28, 2025
@rust-log-analyzer

This comment has been minimized.

@BoxyUwU BoxyUwU force-pushed the patkind_constant_ptr_docs branch from 64fc4f6 to 2b11851 Compare July 28, 2025 09:13
@BoxyUwU
Copy link
Member Author

BoxyUwU commented Jul 28, 2025

@bors r=lcnr rollup

@bors
Copy link
Collaborator

bors commented Jul 28, 2025

📌 Commit 2b11851 has been approved by lcnr

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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 28, 2025
@@ -838,6 +838,8 @@ pub enum PatKind<'tcx> {
/// * integer, bool, char or float (represented as a valtree), which will be handled by
/// exhaustiveness to cover exactly its own value, similar to `&str`, but these values are
/// much simpler.
/// * raw pointers derived from integers, other raw pointers will have already resulted in an
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will also be a valtree then.

Hm, that makes me wonder whether we shouldn't change the type here from mir::Const to something that enforces val-tree-ness... that was part of the goal of the big const pattern changes we did last year.

I don't know how the String case is represented though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't know about the String case :3 mir::Const does seem a bit funny to me too

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See follow-up at #144591.

samueltardieu added a commit to samueltardieu/rust that referenced this pull request Jul 28, 2025
… r=lcnr

Raw Pointers are Constant PatKinds too

raw pointers can be matched on with a const pattern:
```rust
const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}
```
as far as I can tell this is represented with a `PatKind::Constant`: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337
bors added a commit that referenced this pull request Jul 29, 2025
Rollup of 11 pull requests

Successful merges:

 - #143289 (Remove `[T]::array_chunks(_mut)`)
 - #143883 (Add `--link-targets-dir` argument to linkchecker)
 - #144034 (tests: Test line number in debuginfo for diverging function calls)
 - #144236 (Add `core::mem::DropGuard`)
 - #144268 (Add method `find_ancestor_not_from_macro` and `find_ancestor_not_from_extern_macro` to supersede `find_oldest_ancestor_in_same_ctxt`)
 - #144303 (Consolidate staging for `rustc_private` tools)
 - #144539 (constify with_exposed_provenance)
 - #144569 (rustc-dev-guide subtree update)
 - #144573 (Raw Pointers are Constant PatKinds too)
 - #144578 (Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.)
 - #144582 (fix `Atomic*::as_ptr` wording)

r? `@ghost`
`@rustbot` modify labels: rollup
Zalathar added a commit to Zalathar/rust that referenced this pull request Jul 29, 2025
… r=lcnr

Raw Pointers are Constant PatKinds too

raw pointers can be matched on with a const pattern:
```rust
const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}
```
as far as I can tell this is represented with a `PatKind::Constant`: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337
Zalathar added a commit to Zalathar/rust that referenced this pull request Jul 29, 2025
… r=lcnr

Raw Pointers are Constant PatKinds too

raw pointers can be matched on with a const pattern:
```rust
const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}
```
as far as I can tell this is represented with a `PatKind::Constant`: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337
Zalathar added a commit to Zalathar/rust that referenced this pull request Jul 29, 2025
… r=lcnr

Raw Pointers are Constant PatKinds too

raw pointers can be matched on with a const pattern:
```rust
const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}
```
as far as I can tell this is represented with a `PatKind::Constant`: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337
bors added a commit that referenced this pull request Jul 29, 2025
Rollup of 11 pull requests

Successful merges:

 - #143883 (Add `--link-targets-dir` argument to linkchecker)
 - #144236 (Add `core::mem::DropGuard`)
 - #144303 (Consolidate staging for `rustc_private` tools)
 - #144367 (Move dist-apple-various from x86_64 to aarch64)
 - #144539 (constify with_exposed_provenance)
 - #144569 (rustc-dev-guide subtree update)
 - #144573 (Raw Pointers are Constant PatKinds too)
 - #144575 (fixed typo chunks->as_chunks)
 - #144578 (Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.)
 - #144582 (fix `Atomic*::as_ptr` wording)
 - #144616 (coverage: Regression test for "function name is empty" bug)

r? `@ghost`
`@rustbot` modify labels: rollup
bors added a commit that referenced this pull request Jul 29, 2025
Rollup of 10 pull requests

Successful merges:

 - #143883 (Add `--link-targets-dir` argument to linkchecker)
 - #144236 (Add `core::mem::DropGuard`)
 - #144367 (Move dist-apple-various from x86_64 to aarch64)
 - #144539 (constify with_exposed_provenance)
 - #144569 (rustc-dev-guide subtree update)
 - #144573 (Raw Pointers are Constant PatKinds too)
 - #144575 (fixed typo chunks->as_chunks)
 - #144578 (Ensure correct aligement of rustc_hir::Lifetime on platforms with lower default alignments.)
 - #144582 (fix `Atomic*::as_ptr` wording)
 - #144616 (coverage: Regression test for "function name is empty" bug)

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit fce74ba into rust-lang:master Jul 29, 2025
10 checks passed
@rustbot rustbot added this to the 1.90.0 milestone Jul 29, 2025
rust-timer added a commit that referenced this pull request Jul 29, 2025
Rollup merge of #144573 - BoxyUwU:patkind_constant_ptr_docs, r=lcnr

Raw Pointers are Constant PatKinds too

raw pointers can be matched on with a const pattern:
```rust
const FOO: *const u8 = core::ptr::null();

fn foo(a: *const u8) {
  match a {
    FOO => (),
    _ => todo!(),
  }
}
```
as far as I can tell this is represented with a `PatKind::Constant`: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_build/src/thir/pattern/const_to_pat.rs#L333-L337
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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