Skip to content

mGCA: error on region vars lowering - #157188

Open
Human9000-bit wants to merge 1 commit into
rust-lang:mainfrom
Human9000-bit:mgca-157147
Open

mGCA: error on region vars lowering #157188
Human9000-bit wants to merge 1 commit into
rust-lang:mainfrom
Human9000-bit:mgca-157147

Conversation

@Human9000-bit

@Human9000-bit Human9000-bit commented May 31, 2026

Copy link
Copy Markdown
Member

View all comments

This also needs to error on min_generic_const_args feature

cc @BoxyUwU (didn't r her as she is unavailable rn)

Fixes #157147

@rustbot

rustbot commented May 31, 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 May 31, 2026
@rustbot

rustbot commented May 31, 2026

Copy link
Copy Markdown
Collaborator

Failed to set assignee to her: invalid assignee

Note: Only org members with at least the repository "read" role, users with write permissions, or people who have commented on the PR may be assigned.

@Human9000-bit

Copy link
Copy Markdown
Member Author

@rustbot reroll

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

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

And if you wrap it in backticks, it probably won't be recognized as a command.😄

View changes since this review

Comment thread tests/ui/const-generics/mgca/region_vars_hashed.rs Outdated
@BoxyUwU

BoxyUwU commented Jun 1, 2026

Copy link
Copy Markdown
Member

r? BoxyUwU

@rustbot rustbot assigned BoxyUwU and unassigned chenyukang Jun 1, 2026
@BoxyUwU

BoxyUwU commented Jun 1, 2026

Copy link
Copy Markdown
Member

I expect that a similar case should be possible without min_generic_const_args, instead using generic_const_parameter_types e.g. something like Foo<'a, const N: &'a ()> and then Foo<'_, { &() }> . In general I don't see a problem extending this fix to happen even on stable as it should never be meaningfully reachable (though it would be good to have a test case where it actually matters)

@Human9000-bit
Human9000-bit force-pushed the mgca-157147 branch 3 times, most recently from 60f92d8 to e52b714 Compare June 2, 2026 13:46
@Human9000-bit

Human9000-bit commented Jun 2, 2026

Copy link
Copy Markdown
Member Author

Is that what you meant?

I found a case with generic_const_parameter_types, but it seems that there is no obvious case to trigger the ICE without const generics features
(lowk used ai to find gcpt case)

@Human9000-bit

Human9000-bit commented Jun 3, 2026

Copy link
Copy Markdown
Member Author

it seems that that clanker ai hasn't checked that it triggers ICE even on non-incremental. Is there a problem with that?

EDIT: ofc there is. Removed the gcpt case

@BoxyUwU

BoxyUwU commented Jun 7, 2026

Copy link
Copy Markdown
Member

I actually am somewhat confused here, I thought that the has_free_regions check would trigger if there are region variables in the expected type. For example the following does error:

#![feature(generic_const_parameter_types, adt_const_params, const_param_ty_unchecked)]

fn evil<T, const R: T>() {}

fn foo<const N: usize>() {
    evil::<&u32, { &1_u32 }>();
}

what's the difference in expected types of the { &1_u32 } anon const in this example, and the const { &0_u8 } anon const in the mgca example? I would expect both of these to ICE not just the mGCA one

@BoxyUwU

BoxyUwU commented Jun 7, 2026

Copy link
Copy Markdown
Member

@rustbot author

@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 Jun 7, 2026
@Human9000-bit

Human9000-bit commented Jun 14, 2026

Copy link
Copy Markdown
Member Author

I would expect both of these to ICE not just the mGCA one

Your example is correct in terms of it containing region var, but it being caught by existing check:

if tcx.features().generic_const_parameter_types()
&& (ty.has_free_regions() || ty.has_erased_regions())

, because gcpt enabled and const having free regions. Does that make sense?
@rustbot ready

@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 Jun 14, 2026
@BoxyUwU

BoxyUwU commented Jun 15, 2026

Copy link
Copy Markdown
Member

hmm, what I meant is why does the ICEing example not get caught by that existing check. it too should have free regions in the type. i got confused before though and I realise now it's jsut because the check for this stuff only happens under gcpt but mgca also allows for gcpts implicitly.

I also realise now there's operator precedence jank at play in this diff 😅 :

if tcx.features().generic_const_parameter_types()
    && (ty.has_free_regions() || ty.has_erased_regions())
    || ty.has_infer_regions()
{

is actually

if (tcx.features().generic_const_parameter_types()
    && (ty.has_free_regions() || ty.has_erased_regions()))
    || ty.has_infer_regions()
{

I think your original diff was fine- making it be ``if (mgca || gcpt) && (has_free_regions || has_erased_regions)` seems correct enough to me 🤔

@rust-log-analyzer

This comment has been minimized.

@Human9000-bit

Copy link
Copy Markdown
Member Author

making it be if (mgca || gcpt) && (has_free_regions || has_erased_regions)

But this one gives some false negatives 🤔

@BoxyUwU

BoxyUwU commented Jun 19, 2026

Copy link
Copy Markdown
Member

do you have an example of these false negatives?

@rust-log-analyzer

Copy link
Copy Markdown
Collaborator

The job aarch64-gnu-llvm-21-1 failed! Check out the build log: (web) (plain enhanced) (plain)

Click to see the possible cause of the failure (guessed by this bot)
---- [ui] tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs#nogate stdout ----
Saved the actual stderr to `/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/mgca/type_const-generic-param-in-type.nogate/type_const-generic-param-in-type.nogate.stderr`
diff of stderr:

52 LL |     type const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
53    |                                ^^ the type must not depend on the parameter `'a`
54 
- error: aborting due to 9 previous errors
+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/type_const-generic-param-in-type.rs:16:35
+    |
+ LL | type const BAZ<'a>: [&'a (); 0] = const { [] };
+    |                                   ^^^^^^^^^^^^
+ 
+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/type_const-generic-param-in-type.rs:40:44
+    |
+ LL |     type const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
+    |                                            ^^^^^^^^^^^^
+ 
+ error: aborting due to 11 previous errors
56 
57 For more information about this error, try `rustc --explain E0770`.
---
-   --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:40:44
+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/type_const-generic-param-in-type.rs:16:35
+    |
+ LL | type const BAZ<'a>: [&'a (); 0] = const { [] };
+    |                                   ^^^^^^^^^^^^
+ 
+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/type_const-generic-param-in-type.rs:40:44
+    |
+ LL |     type const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
+    |                                            ^^^^^^^^^^^^
+ 
+ error: aborting due to 11 previous errors


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args const-generics/mgca/type_const-generic-param-in-type.rs`

error in revision `nogate`: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--cfg" "nogate" "--check-cfg" "cfg(test,FALSE,nogate,gate)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/const-generics/mgca/type_const-generic-param-in-type.nogate" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:8:50
   |
LL | type const FOO<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
   |                                                  ^ the type must not depend on the parameter `T`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:12:38
   |
LL | type const BAR<const N: usize>: [(); N] = const { [] };
   |                                      ^ the type must not depend on the parameter `N`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:16:23
   |
LL | type const BAZ<'a>: [&'a (); 0] = const { [] };
   |                       ^^ the type must not depend on the parameter `'a`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:21:56
   |
LL |     type const ASSOC<T: core::marker::ConstParamTy_>: [T; 0];
   |                                                        ^ the type must not depend on the parameter `T`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:24:50
   |
LL |     type const ASSOC_CONST<const N: usize>: [(); N];
   |                                                  ^ the type must not depend on the parameter `N`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:27:32
   |
LL |     type const ASSOC_LT<'a>: [&'a (); 0];
   |                                ^^ the type must not depend on the parameter `'a`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:32:56
   |
LL |     type const ASSOC<T: core::marker::ConstParamTy_>: [T; 0] = const { [] };
   |                                                        ^ the type must not depend on the parameter `T`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:36:50
   |
LL |     type const ASSOC_CONST<const N: usize>: [(); N] = const { [] };
   |                                                  ^ the type must not depend on the parameter `N`

error[E0770]: the type of const parameters must not depend on other generic parameters
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:40:32
   |
LL |     type const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
   |                                ^^ the type must not depend on the parameter `'a`

error: anonymous constants with lifetimes in their type are not yet supported
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:16:35
   |
LL | type const BAZ<'a>: [&'a (); 0] = const { [] };
   |                                   ^^^^^^^^^^^^

error: anonymous constants with lifetimes in their type are not yet supported
##[error]  --> /checkout/tests/ui/const-generics/mgca/type_const-generic-param-in-type.rs:40:44
   |
LL |     type const ASSOC_LT<'a>: [&'a (); 0] = const { [] };
   |                                            ^^^^^^^^^^^^

error: aborting due to 11 previous errors

For more information about this error, try `rustc --explain E0770`.
---

+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/assoc-const-no-infer-ice-115806.rs:17:59
+    |
+ LL | impl<USART, T> Pins<USART> for T where T: PinA<USART, A = const { &() }> {}
+    |                                                           ^^^^^^^^^^^^^
+ 
1 error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin`
2   --> $DIR/assoc-const-no-infer-ice-115806.rs:17:1
3    |

9    |
10    = note: downstream crates may implement trait `PinA<_>` for type `NoPin`
11 
- error: aborting due to 1 previous error
+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/assoc-const-no-infer-ice-115806.rs:12:33
+    |
+ LL |     type const A: &'static () = const { &() };
+    |                                 ^^^^^^^^^^^^^
+ 
+ error: aborting due to 3 previous errors
13 
14 For more information about this error, try `rustc --explain E0119`.
---
-   --> /checkout/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs:12:33
+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/assoc-const-no-infer-ice-115806.rs:17:59
+    |
+ LL | impl<USART, T> Pins<USART> for T where T: PinA<USART, A = const { &() }> {}
+    |                                                           ^^^^^^^^^^^^^
+ 
+ error: anonymous constants with lifetimes in their type are not yet supported
+   --> $DIR/assoc-const-no-infer-ice-115806.rs:12:33
+    |
+ LL |     type const A: &'static () = const { &() };
+    |                                 ^^^^^^^^^^^^^
+ 
+ error: aborting due to 3 previous errors


The actual stderr differed from the expected stderr
To update references, rerun the tests and pass the `--bless` flag
To only update this specific test, also pass `--test-args generic-const-items/assoc-const-no-infer-ice-115806.rs`

error: 1 errors occurred comparing output.
status: exit status: 1
command: env -u RUSTC_LOG_COLOR RUSTC_ICE="0" RUST_BACKTRACE="short" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2/bin/rustc" "/checkout/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs" "-Zthreads=1" "-Zsimulate-remapped-rust-src-base=/rustc/FAKE_PREFIX" "-Ztranslate-remapped-path-to-local-path=no" "-Z" "ignore-directory-in-diagnostics-source-blocks=/cargo" "-Z" "ignore-directory-in-diagnostics-source-blocks=/checkout/vendor" "--sysroot" "/checkout/obj/build/aarch64-unknown-linux-gnu/stage2" "--target=aarch64-unknown-linux-gnu" "--check-cfg" "cfg(test,FALSE)" "--error-format" "json" "--json" "future-incompat" "-Ccodegen-units=1" "-Zui-testing" "-Zdeduplicate-diagnostics=no" "-Zwrite-long-types-to-disk=no" "-Cstrip=debuginfo" "--emit" "metadata" "-C" "prefer-dynamic" "--out-dir" "/checkout/obj/build/aarch64-unknown-linux-gnu/test/ui/generic-const-items/assoc-const-no-infer-ice-115806" "-A" "unused" "-W" "unused_attributes" "-A" "internal_features" "-A" "incomplete_features" "-A" "unused_parens" "-A" "unused_braces" "-Crpath" "-Cdebuginfo=0" "-Lnative=/checkout/obj/build/aarch64-unknown-linux-gnu/native/rust-test-helpers"
stdout: none
--- stderr -------------------------------
error: anonymous constants with lifetimes in their type are not yet supported
##[error]  --> /checkout/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs:17:59
   |
LL | impl<USART, T> Pins<USART> for T where T: PinA<USART, A = const { &() }> {}
   |                                                           ^^^^^^^^^^^^^

error[E0119]: conflicting implementations of trait `Pins<_>` for type `NoPin`
##[error]  --> /checkout/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs:17:1
   |
LL | impl<TA> Pins<TA> for NoPin {}
   | --------------------------- first implementation here
...
LL | impl<USART, T> Pins<USART> for T where T: PinA<USART, A = const { &() }> {}
   | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ conflicting implementation for `NoPin`
   |
   = note: downstream crates may implement trait `PinA<_>` for type `NoPin`

error: anonymous constants with lifetimes in their type are not yet supported
##[error]  --> /checkout/tests/ui/generic-const-items/assoc-const-no-infer-ice-115806.rs:12:33
   |
LL |     type const A: &'static () = const { &() };
   |                                 ^^^^^^^^^^^^^

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0119`.

@Human9000-bit

Copy link
Copy Markdown
Member Author

does this count?

@BoxyUwU

BoxyUwU commented Jun 23, 2026

Copy link
Copy Markdown
Member

those errors seem expected/okay to me

@BoxyUwU

BoxyUwU commented Jul 8, 2026

Copy link
Copy Markdown
Member

@rustbot author

@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 Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

[ICE]: region variables should not be hashed

6 participants