Skip to content

Commit 0e32036

Browse files
committed
gce: don't ICE on non-local const
1 parent 13c46fd commit 0e32036

File tree

4 files changed

+23
-16
lines changed

4 files changed

+23
-16
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -421,7 +421,9 @@ fn const_evaluatable_predicates_of<'tcx>(
421421
impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ConstCollector<'tcx> {
422422
fn visit_const(&mut self, c: ty::Const<'tcx>) {
423423
if let ty::ConstKind::Unevaluated(uv) = c.kind() {
424-
if is_const_param_default(self.tcx, uv.def.expect_local()) {
424+
if let Some(local) = uv.def.as_local()
425+
&& is_const_param_default(self.tcx, local)
426+
{
425427
// Do not look into const param defaults,
426428
// these get checked when they are actually instantiated.
427429
//

tests/crashes/133808.rs

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// regression test for #133808.
2+
3+
#![feature(generic_const_exprs)]
4+
#![feature(min_generic_const_args)]
5+
#![allow(incomplete_features)]
6+
#![crate_type = "lib"]
7+
8+
pub trait Foo {}
9+
impl Foo for [u8; std::path::MAIN_SEPARATOR] {}
10+
//~^ ERROR the constant `MAIN_SEPARATOR` is not of type `usize`
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
error: the constant `MAIN_SEPARATOR` is not of type `usize`
2+
--> $DIR/non-local-const.rs:9:14
3+
|
4+
LL | impl Foo for [u8; std::path::MAIN_SEPARATOR] {}
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `usize`, found `char`
6+
|
7+
= note: the length of array `[u8; MAIN_SEPARATOR]` must be type `usize`
8+
9+
error: aborting due to 1 previous error
10+

0 commit comments

Comments
 (0)