Skip to content

Point at array length instead of whole array type - #165516

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
estebank:point-at-arr-len
Nov 9, 2026
Merged

rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
estebank:point-at-arr-len

Conversation

@estebank

@estebank estebank commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor
error: the constant `N` is not of type `usize`
  --> $DIR/bad-subst-const-kind.rs:8:31
   |
LL | impl<const N: u64> Q for [u8; N] {
   |                               ^ array length expected `usize`, found `u64`
   |
   = note: the length of array `[u8; N]` must be type `usize`

When evaluating an array type's length we don't have accurate spans for that hir node, because evaluation happens on types. Keep the Span for the whole array type that we can use later to try and find the hir node and extract the right span to use in the diagnostic.

@rustbot

rustbot commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

changes to the core type system

cc @lcnr

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

rustbot commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

r? @nnethercote

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

@estebank

estebank commented Nov 5, 2026

Copy link
Copy Markdown
Contributor Author

Will have merge conflicts with #164775.

@rust-bors

This comment has been minimized.

@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

@rustbot

rustbot commented Nov 8, 2026

Copy link
Copy Markdown
Collaborator

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.

@rust-log-analyzer

This comment has been minimized.

```
error: the constant `N` is not of type `usize`
  --> $DIR/bad-subst-const-kind.rs:8:31
   |
LL | impl<const N: u64> Q for [u8; N] {
   |      ------------             ^ array length expected `usize`, found `u64`
   |      |
   |      `N` defined here
   |
   = note: the length of array `[u8; N]` must be type `usize`
```

When evaluating an array type's length we don't have accurate spans for that hir node, because evaluation happens on types. Keep the Span for the whole array type that we can use later to try and find the hir node and extract the right span to use in the diagnostic.
@nnethercote

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 93e596a has been approved by nnethercote

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 9, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 9, 2026
…uwer

Rollup of 9 pull requests

Successful merges:

 - #165161 (`rustc_builtin_macros` cleanup, part 9)
 - #165663 (Avoid repeated gated spans snapshots during macro matching)
 - #165637 (library: std: process: Make Command::status platform specific)
 - #163571 ([rustdoc] Render `Deref` methods on aliased items)
 - #164712 (Reject unexpanded attributes in attributes)
 - #165516 (Point at array length instead of whole array type)
 - #165674 (Add regression test for issue 118449)
 - #165676 (Make `Proxy` weak reference as it seems that it is not dropped at all)
 - #165695 (Add regression test for unsafe diagnostic attributes)
@rust-bors
rust-bors Bot merged commit 972028e into rust-lang:main Nov 9, 2026
14 checks passed
@rustbot rustbot added this to the 1.102.0 milestone Nov 9, 2026
rust-bors Bot pushed a commit that referenced this pull request Nov 9, 2026
Rollup merge of #165516 - estebank:point-at-arr-len, r=nnethercote

Point at array length instead of whole array type

```
error: the constant `N` is not of type `usize`
  --> $DIR/bad-subst-const-kind.rs:8:31
   |
LL | impl<const N: u64> Q for [u8; N] {
   |                               ^ array length expected `usize`, found `u64`
   |
   = note: the length of array `[u8; N]` must be type `usize`
```

When evaluating an array type's length we don't have accurate spans for that hir node, because evaluation happens on types. Keep the Span for the whole array type that we can use later to try and find the hir node and extract the right span to use in the diagnostic.
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.

4 participants