fix inference variables leaking into HIR const literal lowering logic#153557
fix inference variables leaking into HIR const literal lowering logic#153557rust-bors[bot] merged 2 commits intorust-lang:mainfrom
Conversation
|
HIR ty lowering was modified cc @fmease |
|
rustbot has assigned @dingxiangfei2009. Use Why was this reviewer chosen?The reviewer was selected based on:
|
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
r? BoxyUwU |
995857f to
28de380
Compare
This comment has been minimized.
This comment has been minimized.
28de380 to
a39c4a4
Compare
| let tcx = self.tcx(); | ||
|
|
||
| if ty.has_infer() { | ||
| let e = self.dcx().span_err(span, "inference variables are not supported in constants"); |
There was a problem hiding this comment.
I am sure this is pretty suboptimal error message. Could we think about a correct one?
|
this is interesting, ideally we to support cases where the expected type was unknown if the literal was explicitly typed, e.g. I think it would make sense to make the type in LitToConstInput optional and pass None in if there are inference variables in the expected type. This should allow the following to compile: #![allow(incomplete_features)]
#![feature(adt_const_params, min_generic_const_args, generic_const_parameter_types)]
fn main() {
foo::<_, 2_i32>();
}
fn foo<T: ConstParamTy_, const N: T>() {} |
the thing here is that we don't want inference variables in query inputs/outputs. it's not that we can't hash them but that at a conceptual level it's not desirable to have them in queries. an inference variable only makes sense as part of its the typical thing you do for that use case is something called canonicalization (which we unfortunately dont really have many docs for other than this https://rustc-dev-guide.rust-lang.org/solve/canonicalization.html). an alternative solution for this ICE would be to make the lit_to_const query a canonical query but that doesn't seem worth it to me. we dont actually want to handle infer vars inside the query and it would impose a perf overhead |
|
Ah, that makes sense. Thank you for the explanation. |
|
Some changes occurred in match checking cc @Nadrieril Some changes occurred in cc @BoxyUwU |
tests/ui/const-generics/mgca/infer-vars-in-const-args-correct.rs
Outdated
Show resolved
Hide resolved
8cd3ba8 to
03168e2
Compare
This comment has been minimized.
This comment has been minimized.
Co-authored-by: BoxyUwU <rust@boxyuwu.dev>
03168e2 to
5113488
Compare
|
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. |
|
Github is having a moment today |
|
@bors r+ rollup thx |
fix inference variables leaking into HIR const literal lowering logic Inference variables could leak into further const lowering logic It ICEs when query system tries to cache `lit_to_const()` after its execution and panics, because inference variables are not hashable for some reason Fixes rust-lang#153524 Fixes rust-lang#153525
|
thank you for the review |
…uwer Rollup of 5 pull requests Successful merges: - #153308 (Add hygiene annotations for tokens in `macro_rules!` bodies) - #153557 (fix inference variables leaking into HIR const literal lowering logic) - #153913 (Fix some suggestions of the `for-loops-over-fallibles` lint) - #153987 (mGCA: Lower const generic args to infer when needed) - #153992 (bootstrap: Optionally print a backtrace if a command fails)
fix inference variables leaking into HIR const literal lowering logic Inference variables could leak into further const lowering logic It ICEs when query system tries to cache `lit_to_const()` after its execution and panics, because inference variables are not hashable for some reason Fixes rust-lang#153524 Fixes rust-lang#153525
…uwer Rollup of 9 pull requests Successful merges: - #153957 (Add bootstrap step for stdarch-verify) - #153727 (When single impl can satisfy inference error, suggest type) - #153308 (Add hygiene annotations for tokens in `macro_rules!` bodies) - #153557 (fix inference variables leaking into HIR const literal lowering logic) - #153913 (Fix some suggestions of the `for-loops-over-fallibles` lint) - #153987 (mGCA: Lower const generic args to infer when needed) - #153992 (bootstrap: Optionally print a backtrace if a command fails) - #154036 (borrowck/type_check: remove helper left-over from unsized locals) - #154038 (merge `regions-outlives-nominal-type-*` tests into one file)
fix inference variables leaking into HIR const literal lowering logic Inference variables could leak into further const lowering logic It ICEs when query system tries to cache `lit_to_const()` after its execution and panics, because inference variables are not hashable for some reason Fixes rust-lang#153524 Fixes rust-lang#153525
fix inference variables leaking into HIR const literal lowering logic Inference variables could leak into further const lowering logic It ICEs when query system tries to cache `lit_to_const()` after its execution and panics, because inference variables are not hashable for some reason Fixes rust-lang#153524 Fixes rust-lang#153525
…uwer Rollup of 9 pull requests Successful merges: - #153957 (Add bootstrap step for stdarch-verify) - #153727 (When single impl can satisfy inference error, suggest type) - #153308 (Add hygiene annotations for tokens in `macro_rules!` bodies) - #153557 (fix inference variables leaking into HIR const literal lowering logic) - #153913 (Fix some suggestions of the `for-loops-over-fallibles` lint) - #153987 (mGCA: Lower const generic args to infer when needed) - #153992 (bootstrap: Optionally print a backtrace if a command fails) - #154036 (borrowck/type_check: remove helper left-over from unsized locals) - #154038 (merge `regions-outlives-nominal-type-*` tests into one file)
…uwer Rollup of 9 pull requests Successful merges: - #153957 (Add bootstrap step for stdarch-verify) - #153727 (When single impl can satisfy inference error, suggest type) - #153308 (Add hygiene annotations for tokens in `macro_rules!` bodies) - #153557 (fix inference variables leaking into HIR const literal lowering logic) - #153913 (Fix some suggestions of the `for-loops-over-fallibles` lint) - #153987 (mGCA: Lower const generic args to infer when needed) - #153992 (bootstrap: Optionally print a backtrace if a command fails) - #154036 (borrowck/type_check: remove helper left-over from unsized locals) - #154038 (merge `regions-outlives-nominal-type-*` tests into one file)
fix inference variables leaking into HIR const literal lowering logic Inference variables could leak into further const lowering logic It ICEs when query system tries to cache `lit_to_const()` after its execution and panics, because inference variables are not hashable for some reason Fixes rust-lang#153524 Fixes rust-lang#153525
…uwer Rollup of 19 pull requests Successful merges: - #152870 (Do not enable split debuginfo for windows-gnu) - #153333 (Fix bootstrap rust build failure for vxworks) - #153681 (ci: add runners for vanilla LLVM 22) - #153727 (When single impl can satisfy inference error, suggest type) - #153824 (Add `Wake` diagnostic item for `alloc::task::Wake`) - #154077 (Optimize 128-bit integer formatting) - #154078 (`define_callbacks` tweaks) - #151905 (Split the `dec2flt::RawFloat` trait for easier reuse) - #153170 (Add is_disconnected functions to mpsc and mpmc channels) - #153308 (Add hygiene annotations for tokens in `macro_rules!` bodies) - #153557 (fix inference variables leaking into HIR const literal lowering logic) - #153804 (Derive Macro Eq: link to more detailed documentation) - #153913 (Fix some suggestions of the `for-loops-over-fallibles` lint) - #153974 (Point at return type when it is the source of the type expectation) - #153987 (mGCA: Lower const generic args to infer when needed) - #154018 (simplify and remove `tests/ui/kindck` and related tests) - #154036 (borrowck/type_check: remove helper left-over from unsized locals) - #154038 (merge `regions-outlives-nominal-type-*` tests into one file) - #154041 (bootstrap: Allow `--bless`ing changes to editor settings files)
…uwer Rollup of 19 pull requests Successful merges: - #152870 (Do not enable split debuginfo for windows-gnu) - #153333 (Fix bootstrap rust build failure for vxworks) - #153681 (ci: add runners for vanilla LLVM 22) - #153727 (When single impl can satisfy inference error, suggest type) - #153824 (Add `Wake` diagnostic item for `alloc::task::Wake`) - #154077 (Optimize 128-bit integer formatting) - #154078 (`define_callbacks` tweaks) - #151905 (Split the `dec2flt::RawFloat` trait for easier reuse) - #153170 (Add is_disconnected functions to mpsc and mpmc channels) - #153308 (Add hygiene annotations for tokens in `macro_rules!` bodies) - #153557 (fix inference variables leaking into HIR const literal lowering logic) - #153804 (Derive Macro Eq: link to more detailed documentation) - #153913 (Fix some suggestions of the `for-loops-over-fallibles` lint) - #153974 (Point at return type when it is the source of the type expectation) - #153987 (mGCA: Lower const generic args to infer when needed) - #154018 (simplify and remove `tests/ui/kindck` and related tests) - #154036 (borrowck/type_check: remove helper left-over from unsized locals) - #154038 (merge `regions-outlives-nominal-type-*` tests into one file) - #154041 (bootstrap: Allow `--bless`ing changes to editor settings files)
Inference variables could leak into further const lowering logic
It ICEs when query system tries to cache
lit_to_const()after its execution and panics, because inference variables are not hashable for some reasonFixes #153524
Fixes #153525