about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMatthias Krüger <476013+matthiaskrgr@users.noreply.github.com>2025-06-27 22:13:07 +0200
committerGitHub <noreply@github.com>2025-06-27 22:13:07 +0200
commit0e79b8914dd3cc372d34968b24fd05132a4a7f1f (patch)
tree5c5a786b08ab8c40943c73c1b9bb459b1ac5ebf1
parent0f89445e39c3a0e1769f4e386e92c07ee9068993 (diff)
parent0e32036debd1daba5bd079a47eeaf93ec7da99b3 (diff)
downloadrust-0e79b8914dd3cc372d34968b24fd05132a4a7f1f.tar.gz
rust-0e79b8914dd3cc372d34968b24fd05132a4a7f1f.zip
Rollup merge of #143106 - yotamofek:pr/gce/non-local-ice, r=BoxyUwU
gce: don't ICE on non-local const

Fixes rust-lang/rust#133808

I have absolutely no idea what I'm doing here, but I followed `@BoxyUwU` 's [instructions](https://github.com/rust-lang/rust/issues/133808#issuecomment-3009122957), and turns out this small change fixes rust-lang/rust#133808, and doesn't seem to break anything else.
(This code path is only reachable when the GCE feature gate is enabled, so even if it does break in a way that is not caught by current test coverage, I guess it's not as bad as breaking stable or non-incomplete features?)

Anyways, r? `@BoxyUwU` , if you don't mind.
-rw-r--r--compiler/rustc_hir_analysis/src/collect/predicates_of.rs4
-rw-r--r--tests/crashes/133808.rs15
-rw-r--r--tests/ui/const-generics/generic_const_exprs/non-local-const.rs10
-rw-r--r--tests/ui/const-generics/generic_const_exprs/non-local-const.stderr10
4 files changed, 23 insertions, 16 deletions
diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
index 2813d4204a7..a93e58b101f 100644
--- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
+++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs
@@ -421,7 +421,9 @@ fn const_evaluatable_predicates_of<'tcx>(
     impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> {
         fn visit_const(&mut self, c: ty::Const<'tcx>) {
             if let ty::ConstKind::Unevaluated(uv) = c.kind() {
-                if is_const_param_default(self.tcx, uv.def.expect_local()) {
+                if let Some(local) = uv.def.as_local()
+                    && is_const_param_default(self.tcx, local)
+                {
                     // Do not look into const param defaults,
                     // these get checked when they are actually instantiated.
                     //
diff --git a/tests/crashes/133808.rs b/tests/crashes/133808.rs
deleted file mode 100644
index 9c6a23d1e35..00000000000
--- a/tests/crashes/133808.rs
+++ /dev/null
@@ -1,15 +0,0 @@
-//@ known-bug: #133808
-
-#![feature(generic_const_exprs, transmutability)]
-
-mod assert {
-    use std::mem::TransmuteFrom;
-
-    pub fn is_transmutable<Src, Dst>()
-    where
-        Dst: TransmuteFrom<Src>,
-    {
-    }
-}
-
-pub fn main() {}
diff --git a/tests/ui/const-generics/generic_const_exprs/non-local-const.rs b/tests/ui/const-generics/generic_const_exprs/non-local-const.rs
new file mode 100644
index 00000000000..0a30cc385ac
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/non-local-const.rs
@@ -0,0 +1,10 @@
+// regression test for #133808.
+
+#![feature(generic_const_exprs)]
+#![feature(min_generic_const_args)]
+#![allow(incomplete_features)]
+#![crate_type = "lib"]
+
+pub trait Foo {}
+impl Foo for [u8; std::path::MAIN_SEPARATOR] {}
+//~^ ERROR the constant `MAIN_SEPARATOR` is not of type `usize`
diff --git a/tests/ui/const-generics/generic_const_exprs/non-local-const.stderr b/tests/ui/const-generics/generic_const_exprs/non-local-const.stderr
new file mode 100644
index 00000000000..d8df3269a19
--- /dev/null
+++ b/tests/ui/const-generics/generic_const_exprs/non-local-const.stderr
@@ -0,0 +1,10 @@
+error: the constant `MAIN_SEPARATOR` is not of type `usize`
+  --> $DIR/non-local-const.rs:9:14
+   |
+LL | impl Foo for [u8; std::path::MAIN_SEPARATOR] {}
+   |              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `char`
+   |
+   = note: the length of array `[u8; MAIN_SEPARATOR]` must be type `usize`
+
+error: aborting due to 1 previous error
+