Skip to content

Commit d3bf721

Browse files
committed
Rollup merge of rust-lang#50788 - varkor:missing-const-cast, r=cramertj
Fix an ICE when casting a nonexistent const Fixes rust-lang#50599.
2 parents 9ced69d + a4224eb commit d3bf721

File tree

3 files changed

+31
-1
lines changed

3 files changed

+31
-1
lines changed

src/librustc_passes/rvalue_promotion.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ fn check_expr<'a, 'tcx>(v: &mut CheckCrateVisitor<'a, 'tcx>, e: &hir::Expr, node
275275
hir::ExprCast(ref from, _) => {
276276
debug!("Checking const cast(id={})", from.id);
277277
match v.tables.cast_kinds().get(from.hir_id) {
278-
None => span_bug!(e.span, "no kind for cast"),
278+
None => v.tcx.sess.delay_span_bug(e.span, "no kind for cast"),
279279
Some(&CastKind::PtrAddrCast) | Some(&CastKind::FnPtrAddrCast) => {
280280
v.promotable = false;
281281
}

src/test/ui/issue-50599.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
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+
const N: u32 = 1_000;
13+
const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize; //~ ERROR cannot find value
14+
let mut digits = [0u32; M];
15+
}

src/test/ui/issue-50599.stderr

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0425]: cannot find value `LOG10_2` in module `std::f64`
2+
--> $DIR/issue-50599.rs:13:48
3+
|
4+
LL | const M: usize = (f64::from(N) * std::f64::LOG10_2) as usize; //~ ERROR cannot find value
5+
| ^^^^^^^ not found in `std::f64`
6+
help: possible candidates are found in other modules, you can import them into scope
7+
|
8+
LL | use std::f32::consts::LOG10_2;
9+
|
10+
LL | use std::f64::consts::LOG10_2;
11+
|
12+
13+
error: aborting due to previous error
14+
15+
For more information about this error, try `rustc --explain E0425`.

0 commit comments

Comments
 (0)