Skip to content

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

Open
estebank wants to merge 1 commit into
rust-lang:mainfrom
estebank:point-at-arr-len
Open

estebank wants to merge 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.

```
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.
@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

rust-bors Bot commented Nov 7, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #165579) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants