Skip to content

Conversation

@Zalathar
Copy link
Member

Historically, constants and literals of type &str have been represented in THIR patterns as PatKind::Const nodes with type &str.

That's fine for stable Rust, but feature(deref_patterns) also created a need to have string literal patterns of type str in some cases, which resulted in a number of additional special cases and inconsistencies in typechecking and in HIR-to-THIR-to-MIR lowering of patterns.

We can avoid several of those special cases by having THIR treat string-constant-values as fundamentally being of type str, and then using PatKind::Deref to represent the additional & layer in the common case where it is needed. This allows bare str patterns to require very little special treatment.

Existing tests should already do a good job of demonstrating that this implementation change does not affect the stable language.

@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2026

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred in match lowering

cc @Nadrieril

Some changes occurred in exhaustiveness checking

cc @Nadrieril

@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 Jan 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Jan 15, 2026

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
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

@Zalathar
Copy link
Member Author

This does result in a few more deref-ref round trips in built MIR, so let's see if that has measurable perf consequences:

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 15, 2026
rust-bors bot pushed a commit that referenced this pull request Jan 15, 2026
THIR patterns: Always use type `str` for string-constant-value nodes
@Zalathar
Copy link
Member Author

@bors try cancel

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 15, 2026

Try build cancelled. Cancelled workflows:

@Zalathar
Copy link
Member Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rust-bors

This comment has been minimized.

rust-bors bot pushed a commit that referenced this pull request Jan 15, 2026
THIR patterns: Always use type `str` for string-constant-value nodes
@Nadrieril
Copy link
Member

Oh, very nice! Loving your small improvements :)

r? me

r=me if perf is good

@rustbot rustbot assigned Nadrieril and unassigned BoxyUwU Jan 15, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 15, 2026

☀️ Try build successful (CI)
Build commit: f0bde62 (f0bde62e299ad76dbe6d39e2eb7aee596ab11ec8, parent: a6acf0f07f0ed1c12e26dc0db3b9bf1d0504a0bb)

@rust-timer

This comment has been minimized.

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (f0bde62): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request means it may be perf-sensitive – we'll automatically label it not fit for rolling up. You can override this, but we strongly advise not to, due to possible changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary -2.9%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-2.9% [-2.9%, -2.9%] 1
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) -2.9% [-2.9%, -2.9%] 1

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

Results (primary -0.1%, secondary -0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.2% [0.2%, 0.2%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.1% [-0.2%, -0.0%] 42
Improvements ✅
(secondary)
-0.1% [-0.1%, -0.0%] 23
All ❌✅ (primary) -0.1% [-0.2%, 0.2%] 43

Bootstrap: 473.873s -> 472.953s (-0.19%)
Artifact size: 383.59 MiB -> 383.51 MiB (-0.02%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jan 15, 2026
@Zalathar
Copy link
Member Author

@bors r=Nadrieril rollup=maybe

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 15, 2026

📌 Commit 0777344 has been approved by Nadrieril

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Jan 15, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 15, 2026
THIR patterns: Always use type `str` for string-constant-value nodes

Historically, constants and literals of type `&str` have been represented in THIR patterns as `PatKind::Const` nodes with type `&str`.

That's fine for stable Rust, but `feature(deref_patterns)` also created a need to have string literal patterns of type `str` in some cases, which resulted in a number of additional special cases and inconsistencies in typechecking and in HIR-to-THIR-to-MIR lowering of patterns.

We can avoid several of those special cases by having THIR treat string-constant-values as fundamentally being of type `str`, and then using `PatKind::Deref` to represent the additional `&` layer in the common case where it is needed. This allows bare `str` patterns to require very little special treatment.

Existing tests should already do a good job of demonstrating that this implementation change does not affect the stable language.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jan 15, 2026
THIR patterns: Always use type `str` for string-constant-value nodes

Historically, constants and literals of type `&str` have been represented in THIR patterns as `PatKind::Const` nodes with type `&str`.

That's fine for stable Rust, but `feature(deref_patterns)` also created a need to have string literal patterns of type `str` in some cases, which resulted in a number of additional special cases and inconsistencies in typechecking and in HIR-to-THIR-to-MIR lowering of patterns.

We can avoid several of those special cases by having THIR treat string-constant-values as fundamentally being of type `str`, and then using `PatKind::Deref` to represent the additional `&` layer in the common case where it is needed. This allows bare `str` patterns to require very little special treatment.

Existing tests should already do a good job of demonstrating that this implementation change does not affect the stable language.
rust-bors bot pushed a commit that referenced this pull request Jan 15, 2026
…uwer

Rollup of 3 pull requests

Successful merges:

 - #150607 (Add amdgpu_dispatch_ptr intrinsic)
 - #150611 (Unify and deduplicate From<T> float tests)
 - #151155 (THIR patterns: Always use type `str` for string-constant-value nodes)

r? @ghost
@Zalathar
Copy link
Member Author

Needs a rebase/bless due to #150846.

@bors r-

@rust-bors rust-bors bot 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 Jan 16, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 16, 2026

Commit 0777344 has been unapproved.

@rustbot
Copy link
Collaborator

rustbot commented Jan 16, 2026

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

@Zalathar
Copy link
Member Author

@bors r=Nadrieril

@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 16, 2026

📌 Commit e673bf5 has been approved by Nadrieril

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Jan 16, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 16, 2026
THIR patterns: Always use type `str` for string-constant-value nodes

Historically, constants and literals of type `&str` have been represented in THIR patterns as `PatKind::Const` nodes with type `&str`.

That's fine for stable Rust, but `feature(deref_patterns)` also created a need to have string literal patterns of type `str` in some cases, which resulted in a number of additional special cases and inconsistencies in typechecking and in HIR-to-THIR-to-MIR lowering of patterns.

We can avoid several of those special cases by having THIR treat string-constant-values as fundamentally being of type `str`, and then using `PatKind::Deref` to represent the additional `&` layer in the common case where it is needed. This allows bare `str` patterns to require very little special treatment.

Existing tests should already do a good job of demonstrating that this implementation change does not affect the stable language.
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 16, 2026
THIR patterns: Always use type `str` for string-constant-value nodes

Historically, constants and literals of type `&str` have been represented in THIR patterns as `PatKind::Const` nodes with type `&str`.

That's fine for stable Rust, but `feature(deref_patterns)` also created a need to have string literal patterns of type `str` in some cases, which resulted in a number of additional special cases and inconsistencies in typechecking and in HIR-to-THIR-to-MIR lowering of patterns.

We can avoid several of those special cases by having THIR treat string-constant-values as fundamentally being of type `str`, and then using `PatKind::Deref` to represent the additional `&` layer in the common case where it is needed. This allows bare `str` patterns to require very little special treatment.

Existing tests should already do a good job of demonstrating that this implementation change does not affect the stable language.
rust-bors bot pushed a commit that referenced this pull request Jan 16, 2026
Rollup of 4 pull requests

Successful merges:

 - #151155 (THIR patterns: Always use type `str` for string-constant-value nodes)
 - #151166 (fix: Do not delay E0107 when there exists an assoc ty with the same name)
 - #151172 (Use default field values in a few more cases)
 - #151185 (Disable `dump-ice-to-disk` on `i686-pc-windows-msvc`)

r? @ghost
@rust-bors

This comment has been minimized.

@rust-bors rust-bors bot added merged-by-bors This PR was explicitly merged by bors. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jan 16, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 16, 2026

☀️ Test successful - CI
Approved by: Nadrieril
Pushing d2015e2 to main...

@rust-bors rust-bors bot merged commit d2015e2 into rust-lang:main Jan 16, 2026
12 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 16, 2026
@github-actions
Copy link
Contributor

What is this? This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.

Comparing bcf787a (parent) -> d2015e2 (this PR)

Test differences

Show 58 test diffs

Stage 1

  • [ui] tests/ui/thir-print/str-patterns.rs: [missing] -> pass (J0)

Stage 2

  • [ui] tests/ui/thir-print/str-patterns.rs: [missing] -> pass (J1)

Additionally, 56 doctest diffs were found. These are ignored, as they are noisy.

Job group index

Test dashboard

Run

cargo run --manifest-path src/ci/citool/Cargo.toml -- \
    test-dashboard d2015e2359d5d0b154c2b192d4039f9b5711fcdc --output-dir test-dashboard

And then open test-dashboard/index.html in your browser to see an overview of all executed tests.

Job duration changes

  1. dist-x86_64-apple: 10404.9s -> 8246.4s (-20.7%)
  2. aarch64-apple: 9322.7s -> 11105.6s (+19.1%)
  3. dist-aarch64-apple: 7650.6s -> 8776.2s (+14.7%)
  4. armhf-gnu: 5464.8s -> 4694.5s (-14.1%)
  5. i686-gnu-nopt-1: 8124.9s -> 7054.7s (-13.2%)
  6. x86_64-gnu-llvm-21-1: 4505.0s -> 3914.2s (-13.1%)
  7. x86_64-gnu-gcc: 3538.9s -> 3082.2s (-12.9%)
  8. x86_64-gnu-llvm-20-1: 4338.7s -> 3780.8s (-12.9%)
  9. x86_64-rust-for-linux: 3085.0s -> 2689.3s (-12.8%)
  10. dist-ohos-armv7: 4003.5s -> 4496.7s (+12.3%)
How to interpret the job duration changes?

Job durations can vary a lot, based on the actual runner instance
that executed the job, system noise, invalidated caches, etc. The table above is provided
mostly for t-infra members, for simpler debugging of potential CI slow-downs.

@Zalathar Zalathar deleted the str branch January 16, 2026 10:23
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (d2015e2): comparison URL.

Overall result: no relevant changes - no action needed

@rustbot label: -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

Results (primary 3.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
3.0% [3.0%, 3.0%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 3.0% [3.0%, 3.0%] 1

Cycles

Results (primary 2.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
2.1% [2.1%, 2.1%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 2.1% [2.1%, 2.1%] 1

Binary size

Results (primary 0.0%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
0.3% [0.3%, 0.3%] 1
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
-0.0% [-0.1%, -0.0%] 4
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 0.0% [-0.1%, 0.3%] 5

Bootstrap: 473.462s -> 471.749s (-0.36%)
Artifact size: 383.62 MiB -> 383.62 MiB (0.00%)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merged-by-bors This PR was explicitly merged by bors. 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.

5 participants