Skip to content

Commit dd1f69b

Browse files
committed
Auto merge of #52314 - varkor:issue-52023, r=oli-obk
Fix ICE when using a pointer cast as array size Fixes #52023. I'm not sure if the comment #52023 (comment) suggested we also emit `E0080`, but just emitting `E0018` seems reasonable for now. r? @oli-obk
2 parents 8475547 + e93de95 commit dd1f69b

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

src/librustc/ty/relate.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use ty::{self, Ty, TyCtxt, TypeFoldable};
2020
use ty::error::{ExpectedFound, TypeError};
2121
use mir::interpret::GlobalId;
2222
use util::common::ErrorReported;
23+
use syntax_pos::DUMMY_SP;
2324
use std::rc::Rc;
2425
use std::iter;
2526
use rustc_target::spec::abi;
@@ -503,7 +504,11 @@ pub fn super_relate_tys<'a, 'gcx, 'tcx, R>(relation: &mut R,
503504
"array length could not be evaluated");
504505
Err(ErrorReported)
505506
}
506-
_ => bug!("arrays should not have {:?} as length", x)
507+
_ => {
508+
tcx.sess.delay_span_bug(DUMMY_SP,
509+
&format!("arrays should not have {:?} as length", x));
510+
Err(ErrorReported)
511+
}
507512
}
508513
};
509514
match (to_u64(sz_a), to_u64(sz_b)) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {
12+
let _ = [0; (&0 as *const i32) as usize]; //~ ERROR raw pointers cannot be cast
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0018]: raw pointers cannot be cast to integers in constants
2+
--> $DIR/issue-52023-array-size-pointer-cast.rs:12:17
3+
|
4+
LL | let _ = [0; (&0 as *const i32) as usize]; //~ ERROR raw pointers cannot be cast
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0018`.

0 commit comments

Comments
 (0)