Fix where-bound suggestion with legacy const generics#158981
Fix where-bound suggestion with legacy const generics#158981IsaiahCoroama wants to merge 5 commits into
Conversation
|
Thanks for the pull request, and welcome! The Rust Project is excited to review your changes, and you should hear from @khyperia (or someone else) some time within the next two weeks. Please see the contribution instructions for more information. Namely, in order to ensure the minimum review times lag, PR authors and assigned reviewers should ensure that the review label (
Why was this reviewer chosen?The reviewer was selected based on:
|
|
thanks for looking into this! as noted by @asquared31415 in the issue, generic_const_exprs is on its way out, to be replaced by generic_const_args (min_generic_const_args to start with). It would be nice if we could get a repro with min_generic_const_args instead if at all possible, but it's fine to keep this testing generic_const_exprs as well I suppose. Some feedback:
@rustbot author |
|
Reminder, once the PR becomes ready for a review, use |
During lowering of legacy const generic arguments, it pointed to the function's span instead of the const argument's span, which led to the diagnostics suggesting bounding the function's name instead of the const argument itself.
…gestions Checks that the `unconstrained generic constant` suggestion points to the correct const argument instead of the function name. Ran across all basic integer types with the help of an auxiliary crate.
Requested by `khyperia`, removing these doesn't affect the test case.
Appending ` as usize` directly to the const snippet produced `[(); N + 1 as usize]:`, which fails to compile (as pointed out by `khyperia`). Instead, wrap each non-atomic expression in parentheses on the anon const's body with the help of `rustc_hir::expr_needs_parens` so the suggestion is `[(); (N + 1) as usize]:` instead.
Removing this doesn't break the test in any way, and having it doesn't make sense for a private test. More of a nitpick than a necessity.
|
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. |
This comment has been minimized.
This comment has been minimized.
dd697af to
9ea03db
Compare
Summary
During lowering of legacy const generics in
lower_legacy_const_generics, the function's span was passed when creating the associatedLocalDefIdinstead of the const argument span. This later caused diagnostics to pull the function's name instead of the const argument for suggestions when emitting anunconstrained generic constanterror.Also adds regression tests for all basic integer types. The full set isn't redundant: non-
usizetypes exercise theas usizecast in the suggestion, whileusizeexercises the no-cast path. The tests use a cross-crate aux crate rather than a target-specific intrinsic (the rewrite only fires cross-crate), so they run on all platforms.Sample
Previous Output
Current Output
AI Assistance Disclosure
This is my first time contributing to the compiler, and I used Claude Opus 4.8 to assist with finding the root cause and implementing the fix, and to navigate the contributing docs, build system, and debugging tooling. The regression tests were designed and written entirely by me. I used Grok to proofread the written materials (commit bodies and this PR) for spelling and grammar. I reviewed and verified all changes myself.
Related Issues
Closes #108382