Skip to content

Fix as str suggestion in subpattern - #164997

Open
yashaggarwal85d wants to merge 2 commits into
rust-lang:mainfrom
yashaggarwal85d:fix-as-str-suggestion-in-subpattern
Open

yashaggarwal85d wants to merge 2 commits into
rust-lang:mainfrom
yashaggarwal85d:fix-as-str-suggestion-in-subpattern

Conversation

@yashaggarwal85d

@yashaggarwal85d yashaggarwal85d commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

The .as_str() help for a string literal pattern against a String was also shown when the literal sits inside a bigger pattern, e.g. matches!(t, Enum::Value("str")), where it suggested t.as_str(). Now it's only suggested when the literal is the whole pattern, so the scrutinee is actually the String.

Added a ui test with the case from the issue plus a nested match and tuple pattern.

Fixes #164973

@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 Oct 26, 2026
@rustbot

rustbot commented Oct 26, 2026

Copy link
Copy Markdown
Collaborator

r? @TaKO8Ki

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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 77 candidates
  • Random selection from 19 candidates

@oli-obk oli-obk closed this Oct 28, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 28, 2026
@oli-obk

oli-obk commented Oct 29, 2026

Copy link
Copy Markdown
Contributor

Reopening after a conversation with the author

@oli-obk oli-obk reopened this Oct 29, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 29, 2026
@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job test-aarch64-gnu-llvm-22-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@yashaggarwal85d

Copy link
Copy Markdown
Contributor Author

Hi @TaKO8Ki, please have a look at the PR, Lemme know if any change is required

@Kivooeo

Kivooeo commented Oct 30, 2026

Copy link
Copy Markdown
Member

Please don’t ping reviewers like this. Many people working on Rust do so in their free time, and their time deserves respect. As rustbot notes, the expected review window is two weeks. If there’s no response after that, feel free to request a reassignment.

@TaKO8Ki TaKO8Ki left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Sorry for the late review. Thank you for the contribution!

View changes since this review

@TaKO8Ki

TaKO8Ki commented Nov 13, 2026

Copy link
Copy Markdown
Member

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit fb20bb7 has been approved by TaKO8Ki

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 Nov 13, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Nov 13, 2026
…ion-in-subpattern, r=TaKO8Ki

Fix as str suggestion in subpattern

The `.as_str()` help for a string literal pattern against a `String` was also shown when the literal sits inside a bigger pattern, e.g. `matches!(t, Enum::Value("str"))`, where it suggested `t.as_str()`. Now it's only suggested when the literal is the whole pattern, so the scrutinee is actually the `String`.

Added a ui test with the case from the issue plus a nested match and tuple pattern.

Fixes rust-lang#164973
rust-bors Bot pushed a commit that referenced this pull request Nov 13, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #160618 (require a consistent codegen backend when -Zllvm-target-feature is present)
 - #164043 (alloc: Unstably add `Vec::repeat` and `Vec::repeat_in`)
 - #164823 (Use `DerefMut` and `IndexMut` before `&raw mut` autoborrow)
 - #165568 (rustdoc: Suggest corrections for reference label typos)
 - #165924 (rustc_codegen_gcc subtree update 2026-11-13)
 - #165927 (Remove `const_struct` from `rustc_codegen_ssa`)
 - #165928 (Replace most uses of `type_array` with `type_byte_array` in `rustc_codegen_llvm`)
 - #164362 (Emit note for `non_exhaustive` within defining crate for `unreachable_patterns`)
 - #164997 (Fix as str suggestion in subpattern)
 - #165868 (Small changes to dyn compatibility)
 - #165879 (Add `#[rustc_test_entrypoint_marker]` back !)
 - #165903 (Fix borrowck ICE when a borrow outlives a local in a const block)
 - #165914 (Use `trim_prefix` in bootstrap)
 - #165919 (tests: accept better behavior on underaligned accesses)
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 13, 2026
…ion-in-subpattern, r=TaKO8Ki

Fix as str suggestion in subpattern

The `.as_str()` help for a string literal pattern against a `String` was also shown when the literal sits inside a bigger pattern, e.g. `matches!(t, Enum::Value("str"))`, where it suggested `t.as_str()`. Now it's only suggested when the literal is the whole pattern, so the scrutinee is actually the `String`.

Added a ui test with the case from the issue plus a nested match and tuple pattern.

Fixes rust-lang#164973
rust-bors Bot pushed a commit that referenced this pull request Nov 13, 2026
Rollup of 17 pull requests

Successful merges:

 - #160618 (require a consistent codegen backend when -Zllvm-target-feature is present)
 - #164043 (alloc: Unstably add `Vec::repeat` and `Vec::repeat_in`)
 - #164808 (asm const ptr: move name generation to asm-specific logic)
 - #164823 (Use `DerefMut` and `IndexMut` before `&raw mut` autoborrow)
 - #165475 (Add a `!type` annotation to a vtable for every supertrait that is a prefix of the vtable)
 - #165568 (rustdoc: Suggest corrections for reference label typos)
 - #165924 (rustc_codegen_gcc subtree update 2026-11-13)
 - #165927 (Remove `const_struct` from `rustc_codegen_ssa`)
 - #164362 (Emit note for `non_exhaustive` within defining crate for `unreachable_patterns`)
 - #164997 (Fix as str suggestion in subpattern)
 - #165825 (make `Complex<x87_f80>` ABI-compatible with C)
 - #165868 (Small changes to dyn compatibility)
 - #165879 (Add `#[rustc_test_entrypoint_marker]` back !)
 - #165903 (Fix borrowck ICE when a borrow outlives a local in a const block)
 - #165914 (Use `trim_prefix` in bootstrap)
 - #165919 (tests: accept better behavior on underaligned accesses)
 - #165936 (Enhance documentation for try_clone File implementation)
Zalathar added a commit to Zalathar/rust that referenced this pull request Nov 14, 2026
…ion-in-subpattern, r=TaKO8Ki

Fix as str suggestion in subpattern

The `.as_str()` help for a string literal pattern against a `String` was also shown when the literal sits inside a bigger pattern, e.g. `matches!(t, Enum::Value("str"))`, where it suggested `t.as_str()`. Now it's only suggested when the literal is the whole pattern, so the scrutinee is actually the `String`.

Added a ui test with the case from the issue plus a nested match and tuple pattern.

Fixes rust-lang#164973
rust-bors Bot pushed a commit that referenced this pull request Nov 14, 2026
Rollup of 16 pull requests

Successful merges:

 - #160618 (require a consistent codegen backend when -Zllvm-target-feature is present)
 - #164043 (alloc: Unstably add `Vec::repeat` and `Vec::repeat_in`)
 - #164823 (Use `DerefMut` and `IndexMut` before `&raw mut` autoborrow)
 - #165475 (Add a `!type` annotation to a vtable for every supertrait that is a prefix of the vtable)
 - #165568 (rustdoc: Suggest corrections for reference label typos)
 - #165924 (rustc_codegen_gcc subtree update 2026-11-13)
 - #165927 (Remove `const_struct` from `rustc_codegen_ssa`)
 - #164362 (Emit note for `non_exhaustive` within defining crate for `unreachable_patterns`)
 - #164997 (Fix as str suggestion in subpattern)
 - #165825 (make `Complex<x87_f80>` ABI-compatible with C)
 - #165868 (Small changes to dyn compatibility)
 - #165879 (Add `#[rustc_test_entrypoint_marker]` back !)
 - #165903 (Fix borrowck ICE when a borrow outlives a local in a const block)
 - #165914 (Use `trim_prefix` in bootstrap)
 - #165919 (tests: accept better behavior on underaligned accesses)
 - #165936 (Enhance documentation for try_clone File implementation)
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 14, 2026
…ion-in-subpattern, r=TaKO8Ki

Fix as str suggestion in subpattern

The `.as_str()` help for a string literal pattern against a `String` was also shown when the literal sits inside a bigger pattern, e.g. `matches!(t, Enum::Value("str"))`, where it suggested `t.as_str()`. Now it's only suggested when the literal is the whole pattern, so the scrutinee is actually the `String`.

Added a ui test with the case from the issue plus a nested match and tuple pattern.

Fixes rust-lang#164973
jhpratt added a commit to jhpratt/rust that referenced this pull request Nov 14, 2026
…ion-in-subpattern, r=TaKO8Ki

Fix as str suggestion in subpattern

The `.as_str()` help for a string literal pattern against a `String` was also shown when the literal sits inside a bigger pattern, e.g. `matches!(t, Enum::Value("str"))`, where it suggested `t.as_str()`. Now it's only suggested when the literal is the whole pattern, so the scrutinee is actually the `String`.

Added a ui test with the case from the issue plus a nested match and tuple pattern.

Fixes rust-lang#164973

This branch has not been deployed

No deployments
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.

Nonsensical "consider converting the String to a &str using .as_str()" suggestion inside matches! macro for E0308

6 participants