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

Fix an invalid error for a suggestion to add a slice in pattern-matching #96122

Conversation

TaKO8Ki
Copy link
Member

@TaKO8Ki TaKO8Ki commented Apr 16, 2022

closes #96103

@rust-highfive
Copy link
Collaborator

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Apr 16, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 16, 2022
compiler/rustc_typeck/src/check/pat.rs Show resolved Hide resolved
Comment on lines 2086 to 2092
if any_target_ty {
err.span_suggestion(
span,
"consider slicing here",
format!("{snippet}[..]"),
Applicability::MachineApplicable,
);
Copy link
Member

Choose a reason for hiding this comment

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

Won't this suggestion still be wrong for some custom defined type that has Deref<Target=[*]> but not Index<RangeFull, Output=[*]>?

Maybe we should be suggesting borrowing here instead of slicing?

Copy link
Member Author

Choose a reason for hiding this comment

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

I fixed this problem.

compiler/rustc_typeck/src/check/pat.rs Outdated Show resolved Hide resolved
@TaKO8Ki TaKO8Ki requested a review from nagisa April 18, 2022 03:57
@nagisa
Copy link
Member

nagisa commented Apr 19, 2022

Thanks, this looks like a definite improvement!

@bors r+

@bors
Copy link
Contributor

bors commented Apr 19, 2022

📌 Commit efe438b has been approved by nagisa

@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 Apr 19, 2022
bors added a commit to rust-lang-ci/rust that referenced this pull request Apr 19, 2022
Rollup of 6 pull requests

Successful merges:

 - rust-lang#94493 (Improved diagnostic on failure to meet send bound on future in a foreign crate)
 - rust-lang#95809 (Fix typo in bootstrap.py)
 - rust-lang#96086 (Remove `--extern-location` and all associated code)
 - rust-lang#96089 (`alloc`: make `vec!` unavailable under `no_global_oom_handling`)
 - rust-lang#96122 (Fix an invalid error for a suggestion to add a slice in pattern-matching)
 - rust-lang#96142 (Stop using CRATE_DEF_INDEX outside of metadata encoding.)

Failed merges:

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 036d200 into rust-lang:master Apr 19, 2022
@rustbot rustbot added this to the 1.62.0 milestone Apr 19, 2022
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.

Erroneous suggestion to add a slice in pattern-matching
5 participants