1
Fork 0

Handle casts to integer/float variables

These can happen if prior errors disable defaulting.

Fixes #43825.
This commit is contained in:
Ariel Ben-Yehuda 2017-12-24 11:40:54 +02:00
parent ce58d965ef
commit 6aca330149
3 changed files with 28 additions and 0 deletions

View file

@ -20,6 +20,7 @@ use syntax::ast;
pub enum IntTy { pub enum IntTy {
U(ast::UintTy), U(ast::UintTy),
I, I,
Ivar,
CEnum, CEnum,
Bool, Bool,
Char Char
@ -63,6 +64,8 @@ impl<'tcx> CastTy<'tcx> {
ty::TyBool => Some(CastTy::Int(IntTy::Bool)), ty::TyBool => Some(CastTy::Int(IntTy::Bool)),
ty::TyChar => Some(CastTy::Int(IntTy::Char)), ty::TyChar => Some(CastTy::Int(IntTy::Char)),
ty::TyInt(_) => Some(CastTy::Int(IntTy::I)), ty::TyInt(_) => Some(CastTy::Int(IntTy::I)),
ty::TyInfer(ty::InferTy::IntVar(_)) => Some(CastTy::Int(IntTy::Ivar)),
ty::TyInfer(ty::InferTy::FloatVar(_)) => Some(CastTy::Float),
ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))), ty::TyUint(u) => Some(CastTy::Int(IntTy::U(u))),
ty::TyFloat(_) => Some(CastTy::Float), ty::TyFloat(_) => Some(CastTy::Float),
ty::TyAdt(d,_) if d.is_enum() && d.is_payloadfree() => ty::TyAdt(d,_) if d.is_enum() && d.is_payloadfree() =>

View file

@ -0,0 +1,17 @@
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let error = error; //~ ERROR cannot find value `error`
// These used to cause errors.
0 as f32;
0.0 as u32;
}

View file

@ -0,0 +1,8 @@
error[E0425]: cannot find value `error` in this scope
--> $DIR/cast-errors-issue-43825.rs:12:17
|
12 | let error = error; //~ ERROR cannot find value `error`
| ^^^^^ not found in this scope
error: aborting due to previous error