Skip to content

resolve: suggest usize for array-length consts - #160155

Closed
AayushMainali-Github wants to merge 1 commit into
rust-lang:mainfrom
AayushMainali-Github:fix/159487-suggest-usize-array-length-const
Closed

resolve: suggest usize for array-length consts#160155
AayushMainali-Github wants to merge 1 commit into
rust-lang:mainfrom
AayushMainali-Github:fix/159487-suggest-usize-array-length-const

Conversation

@AayushMainali-Github

@AayushMainali-Github AayushMainali-Github commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Fixes #159487.

Summary

  • When E0435 suggests turning a let into a const because the binding was used as an array length ([T; n]) or repeat count ([x; n]), suggest usize instead of /* Type */.
  • Other constant contexts keep the /* Type */ placeholder.

Reason for the change

Array lengths are always usize, so the placeholder type in the suggestion was unhelpful for the common case shown in the issue.

Testing performed

  • ./x test tests/ui/consts/suggest-usize-for-array-length.rs --stage 1 — passed (new regression test)
  • ./x test tests/ui/consts/non-const-value-in-const.rs tests/ui/repeat-expr/repeat_count.rs tests/ui/error-codes/E0435.rs tests/ui/parser/recover/array-type-no-semi.rs tests/ui/const-generics/legacy-const-generics-bad.rs --stage 1 --force-rerun — passed
  • rustfmt --edition 2024 --check on changed rustc_resolve sources — clean

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

rustbot commented Jul 29, 2026

Copy link
Copy Markdown
Collaborator

r? @mati865

rustbot has assigned @mati865.
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 74 candidates
  • Random selection from 16 candidates

@apiraino

apiraino commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Hi,

for the last few months we have been receiving an increased amount of LLM generated contributions. We have no way to distinguish your PR from other generated ones, therefore need to put some additional barriers for contributions.

This PR show some LLM usage which under our current policy is not allowed nor it's missing a disclosure about LLM use.

We are a community of contributors, not just a code repository. We focus on contributors who desire to stay around and put in the work to produce high quality contributions or learn to do so. Please also get familiar with our contributions guidelines and contribution standards.

Therefore we are closing this PR. If you're unsure about how to proceed, please feel free to join our Zulip mentoring channel and ask for a mentor to learn how best to use (or not use) LLMs.

-- the Rust mod team

@apiraino apiraino closed this Aug 6, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Aug 6, 2026
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Sep 4, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 4, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 5, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
rust-bors Bot pushed a commit that referenced this pull request Sep 5, 2026
Rollup merge of #160906 - lsunsi:push-ysqvmnlvvzwr, r=davidtwco

Suggest usize instead of placeholder type for array length constants

Fixes #159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from #160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
renovate-bot pushed a commit to renovate-bot/rust-lang-_-compiler-builtins that referenced this pull request Sep 7, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang/rust#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang/rust#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
asukaminato0721 pushed a commit to asukaminato0721/rust-analyzer that referenced this pull request Sep 7, 2026
Suggest usize instead of placeholder type for array length constants

Fixes rust-lang/rust#159487

This PR makes the type suggestion for a anonymous constant used as an array length or repeat expression less generic: usize instead of placeholder type.

I divided the work in several commits so I could track my own progress and test my understanding. I could squash them all into one if needed.

Some ideas were pulled from rust-lang/rust#160155 , which is why the PR might look similar. That said I only used it as reference when I got stuck, because I was prioritizing my own learning instead of just quickly pushing the changes (hence, many commits).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.

Use usize when suggesting creating a const for array lenghts

4 participants