Skip to content

Commit 6aca330

Browse files
committed
Handle casts to integer/float variables
These can happen if prior errors disable defaulting. Fixes #43825.
1 parent ce58d96 commit 6aca330

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/librustc/ty/cast.rs

+3
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use syntax::ast;
2020
pub enum IntTy {
2121
U(ast::UintTy),
2222
I,
23+
Ivar,
2324
CEnum,
2425
Bool,
2526
Char
@@ -63,6 +64,8 @@ impl<'tcx> CastTy<'tcx> {
6364
ty::TyBool => Some(CastTy::Int(IntTy::Bool)),
6465
ty::TyChar => Some(CastTy::Int(IntTy::Char)),
6566
ty::TyInt(_) => Some(CastTy::Int(IntTy::I)),
67+
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::Ivar)),
68+
ty::TyInfer(ty::InferTy::FloatVar(_)) => Some(CastTy::Float),
6669
ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))),
6770
ty::TyFloat(_) => Some(CastTy::Float),
6871
ty::TyAdt(d,_) if d.is_enum() && d.is_payloadfree() =>
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// Copyright 2017 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 error = error; //~ ERROR cannot find value `error`
13+
14+
// These used to cause errors.
15+
0 as f32;
16+
0.0 as u32;
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error[E0425]: cannot find value `error` in this scope
2+
--> $DIR/cast-errors-issue-43825.rs:12:17
3+
|
4+
12 | let error = error; //~ ERROR cannot find value `error`
5+
| ^^^^^ not found in this scope
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)