Skip to content

rustc_resolve: improve const generic errors#152913

Open
Unique-Usman wants to merge 1 commit intorust-lang:mainfrom
Unique-Usman:ua/constnottype
Open

rustc_resolve: improve const generic errors#152913
Unique-Usman wants to merge 1 commit intorust-lang:mainfrom
Unique-Usman:ua/constnottype

Conversation

@Unique-Usman
Copy link
Contributor

No description provided.

@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 Feb 20, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 20, 2026

r? @JonathanBrouwer

rustbot has assigned @JonathanBrouwer.
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 68 candidates
  • Random selection from 14 candidates

@Unique-Usman
Copy link
Contributor Author

r? @estebank

@rustbot rustbot assigned estebank and unassigned JonathanBrouwer Feb 20, 2026
@Unique-Usman Unique-Usman marked this pull request as draft February 20, 2026 14:49
@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Feb 20, 2026
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Feb 28, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-bors

This comment has been minimized.

Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com>
LL + impl X<X> {}
|
help: you might be missing a type parameter
help: you might have meant to write a const parameter here
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
help: you might have meant to write a const parameter here
help: you might have meant to introduce a const parameter on the `impl`

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the const parameter can be in other place apart from impl, I think we should leave it as here instead of the impl or we can just make it varies based on where it appears.

--> $DIR/missing-type-parameter2.rs:5:28
|
LL | struct X<const N: u8>();
| ----------- const parameter `N` is defined here
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| ----------- const parameter `N` is defined here
| ----------- const parameter `N` is defined on the type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense.

|
LL | struct X<const N: u8>();
| ------------------------ similarly named struct `X` defined here
| ----------- const parameter `N` is defined here
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
| ----------- const parameter `N` is defined here
| ----------- const parameter `N` is defined on the type

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Make sense

.struct_constructors
.insert(local_def_id, (ctor_res, ctor_vis.to_def_id(), ret_fields));
}
self.r.struct_generics.insert(local_def_id, generics.clone());
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's see if we can struct_generics store references. That should keep mem usage to a minimum.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Noted.

Comment on lines +4472 to +4475
if let Some(const_err) = const_err {
err.cancel();
err = const_err;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This is currently inactive, right? const_err isn't None anywhere right now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

const_err is actually always None except in the case of where we add the error we just introduce see it here -> https://github.com/rust-lang/rust/pull/152913/changes#diff-2c81e6d8048a31a3ce43f30181aaa037e0ad0076e7aee67792ca993f28c75ac3R3440-R3441

Copy link
Contributor Author

Choose a reason for hiding this comment

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

it is to prevent the type error from showing up.

Comment on lines 31 to 32
LL - impl<const N: u8> Foo for C<N, T> {}
LL + impl<const N: u8> Foo for C<N, A> {}
|
help: you might be missing a type parameter
LL + impl<const T: u8> Foo for C<N, T> {}
|
LL | impl<const N: u8, T> Foo for C<N, T> {}
| +++

error[E0747]: unresolved item provided when a constant was expected
--> $DIR/invalid-const-arguments.rs:5:16
|
LL | impl Foo for A<N> {}
| ^
|
help: if this generic argument was intended as a const parameter, surround it with braces
|
LL | impl Foo for A<{ N }> {}
| + +

error[E0747]: type provided when a constant was expected
--> $DIR/invalid-const-arguments.rs:10:19
--> $DIR/invalid-const-arguments.rs:9:19
|
LL | impl<N> Foo for B<N> {}
Copy link
Contributor

Choose a reason for hiding this comment

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

We're going to have to account for "there's already an impl generics list" to suggest adding, instead of replacing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, noted. make sense.

@Unique-Usman Unique-Usman requested a review from estebank March 6, 2026 17:35
@Unique-Usman Unique-Usman marked this pull request as ready for review March 6, 2026 17:35
@rustbot
Copy link
Collaborator

rustbot commented Mar 6, 2026

HIR ty lowering was modified

cc @fmease

@rust-log-analyzer
Copy link
Collaborator

The job pr-check-2 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
/dev/sda15      105M  6.2M   99M   6% /boot/efi
tmpfs           1.6G   12K  1.6G   1% /run/user/1001
================================================================================

Sufficient disk space available (94885672KB >= 52428800KB). Skipping cleanup.
##[group]Run echo "[CI_PR_NUMBER=$num]"
echo "[CI_PR_NUMBER=$num]"
shell: /usr/bin/bash --noprofile --norc -e -o pipefail {0}

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.

5 participants