Skip to content

reintroduce check RibKind::ConstParamTy did in direct consts - #162842

Open
khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:ConstParamTy-check
Open

khyperia wants to merge 1 commit into
rust-lang:mainfrom
khyperia:ConstParamTy-check

Conversation

@khyperia

Copy link
Copy Markdown
Member

The ConstParamTy nameres rib checks were never implemented for gca!-rhs direct consts. So, when type const got removed in #162517 and we now only have gca!-rhs direct consts, the lack of checks became very apparent
This PR adds the check again for gca!-rhs direct consts.

When implementing this and updating tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs, I ran into #160553 which caused a glaringly obvious issue - the following succeeds compilation:

#![feature(min_generic_const_args, generic_const_items, generic_const_parameter_types)]
const BAR<const N: usize>: [(); N] = core::direct_const_arg!([]);

This is already tracked in tests/crashes/160553.rs so I have not added a test for it.

This is the reason I changed the test from [(); N] to StructWithConstParam<const N: usize>, the RHS has to, like, y'know, actually typecheck :P

r? @BoxyUwU

@rustbot

rustbot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

HIR ty lowering was modified

cc @fmease

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

rustbot commented Sep 16, 2026

Copy link
Copy Markdown
Collaborator

BoxyUwU is currently at their maximum review capacity.
They may take a while to respond.

@khyperia

Copy link
Copy Markdown
Member Author

When implementing this and updating tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs, I ran into #160553 which caused a glaringly obvious issue

opened a PR to fix this #162845

@khyperia khyperia changed the title reintroduce check for ConstParamTy in direct consts reintroduce check RibKind::ConstParamTy did in direct consts Sep 16, 2026

@BoxyUwU BoxyUwU left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

r=me with comment

View changes since this review

tcx.require_lang_item(LangItem::ConstParamTy, span),
);
}
if !tcx.features().generic_const_parameter_types() && item_ty.has_param() {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you add a FIXME about how we might want to move this to type_of so we can return Error from type_of if it references invalid params

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

// FIXME(min_generic_const_args): We *might* want to move this check to `type_of`, so we can
// return `ty::Error` if it references invalid params. However, doing so is hard, because
// `type_of` doesn't know if it's a direct const - `const_of_item` determines that, and
// `const_of_item` calls `type_of`.

@khyperia

Copy link
Copy Markdown
Member Author

@bors r=BoxyUwU rollup

@rust-bors

rust-bors Bot commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 9dce1fc has been approved by BoxyUwU

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 Sep 17, 2026
Zalathar added a commit to Zalathar/rust that referenced this pull request Sep 17, 2026
…yUwU

reintroduce check RibKind::ConstParamTy did in direct consts

The ConstParamTy nameres rib checks were never implemented for `gca!`-rhs direct consts. So, when `type const` got removed in rust-lang#162517 and we now only have `gca!`-rhs direct consts, the lack of checks became very apparent
This PR adds the check again for `gca!`-rhs direct consts.

When implementing this and updating `tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs`, I ran into rust-lang#160553 which caused a glaringly obvious issue - the following succeeds compilation:

```rust
#![feature(min_generic_const_args, generic_const_items, generic_const_parameter_types)]
const BAR<const N: usize>: [(); N] = core::direct_const_arg!([]);
```

This is already tracked in `tests/crashes/160553.rs` so I have not added a test for it.

This is the reason I changed the test from `[(); N]` to `StructWithConstParam<const N: usize>`, the RHS has to, like, y'know, actually typecheck :P

r? @BoxyUwU
rust-bors Bot pushed a commit that referenced this pull request Sep 17, 2026
Rollup of 16 pull requests

Successful merges:

 - #161596 (coretests: Add more pattern tests.)
 - #162796 (libtest: do not early exit from test runners)
 - #162844 (Add loan reachability traces to polonius MIR dumps)
 - #162876 (Move operations out of `rustc_middle::query::job`)
 - #160108 (Stabilize `windows_process_extensions_main_thread_handle`)
 - #160212 (traits: Fix rigid alias liveness matching)
 - #160544 (Stabilize `feature(trim_prefix_suffix)` (`{str, [T], Path}::trim_prefix` and `{str, [T]}::trim_suffix`))
 - #161246 (Normalize non-rigid aliases in ty_known_to_outlive)
 - #161305 (Use the entire type of a dropped local to compute variance (edge direction) for Polonius alpha)
 - #161838 (tests: accept LLVM 24 optimization in this test)
 - #162805 (Add `must_use` lint to `ExitCode`)
 - #162825 (core: Add examples for `debug_closure_helpers`)
 - #162841 (enable asm tests for xtensa targets)
 - #162842 (reintroduce check RibKind::ConstParamTy did in direct consts)
 - #162845 (mgca: fix issue with mismatched array valtree/valtree tys)
 - #162856 (Stabilize CommandExt::show_window)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Sep 17, 2026
…yUwU

reintroduce check RibKind::ConstParamTy did in direct consts

The ConstParamTy nameres rib checks were never implemented for `gca!`-rhs direct consts. So, when `type const` got removed in rust-lang#162517 and we now only have `gca!`-rhs direct consts, the lack of checks became very apparent
This PR adds the check again for `gca!`-rhs direct consts.

When implementing this and updating `tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs`, I ran into rust-lang#160553 which caused a glaringly obvious issue - the following succeeds compilation:

```rust
#![feature(min_generic_const_args, generic_const_items, generic_const_parameter_types)]
const BAR<const N: usize>: [(); N] = core::direct_const_arg!([]);
```

This is already tracked in `tests/crashes/160553.rs` so I have not added a test for it.

This is the reason I changed the test from `[(); N]` to `StructWithConstParam<const N: usize>`, the RHS has to, like, y'know, actually typecheck :P

r? @BoxyUwU
rust-bors Bot pushed a commit that referenced this pull request Sep 17, 2026
…uwer

Rollup of 24 pull requests

Successful merges:

 - #161596 (coretests: Add more pattern tests.)
 - #162177 (Properly implement the gpu-kernel ABI for amdgpu)
 - #162411 (Make Receiver `#[rustc_dyn_incompatible_trait]`)
 - #162760 (yeet alias new_from_def_id)
 - #162796 (libtest: do not early exit from test runners)
 - #162844 (Add loan reachability traces to polonius MIR dumps)
 - #162876 (Move operations out of `rustc_middle::query::job`)
 - #160108 (Stabilize `windows_process_extensions_main_thread_handle`)
 - #160212 (traits: Fix rigid alias liveness matching)
 - #160544 (Stabilize `feature(trim_prefix_suffix)` (`{str, [T], Path}::trim_prefix` and `{str, [T]}::trim_suffix`))
 - #161305 (Use the entire type of a dropped local to compute variance (edge direction) for Polonius alpha)
 - #161838 (tests: accept LLVM 24 optimization in this test)
 - #162312 (core: Rewrite docs for try_as_dyn)
 - #162785 (Avoid creating overlapping assignments in MatchBranchSimplification)
 - #162805 (Add `must_use` lint to `ExitCode`)
 - #162825 (core: Add examples for `debug_closure_helpers`)
 - #162841 (enable asm tests for xtensa targets)
 - #162842 (reintroduce check RibKind::ConstParamTy did in direct consts)
 - #162845 (mgca: fix issue with mismatched array valtree/valtree tys)
 - #162856 (Stabilize CommandExt::show_window)
 - #162865 (Complex conjugate, negation and default)
 - #162874 (Add support for `annotate_snippets::snippet::AnnotationKind::Visible`)
 - #162881 (Simplify the macro for forwarding Decoder methods )
 - #162888 (Fix a typo on the Armv7-R platform docs page)
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.

3 participants