mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-22 23:04:33 +00:00
Rollup merge of #79951 - LeSeulArtichaut:ty-ir, r=nikomatsakis
Refractor a few more types to `rustc_type_ir` In the continuation of #79169, ~~blocked on that PR~~. This PR: - moves `IntVarValue`, `FloatVarValue`, `InferTy` (and friends) and `Variance` - creates the `IntTy`, `UintTy` and `FloatTy` enums in `rustc_type_ir`, based on their `ast` and `chalk_ir` equilavents, and uses them for types in the rest of the compiler. ~~I will split up that commit to make this easier to review and to have a better commit history.~~ EDIT: done, I split the PR in commits of 200-ish lines each r? `````@nikomatsakis````` cc `````@jackh726`````
This commit is contained in:
commit
446edd1e1a
@ -4345,6 +4345,7 @@ dependencies = [
|
||||
"bitflags",
|
||||
"rustc_data_structures",
|
||||
"rustc_index",
|
||||
"rustc_macros",
|
||||
"rustc_serialize",
|
||||
]
|
||||
|
||||
|
@ -83,7 +83,6 @@ mod vtable;
|
||||
mod prelude {
|
||||
pub(crate) use std::convert::{TryFrom, TryInto};
|
||||
|
||||
pub(crate) use rustc_ast::ast::{FloatTy, IntTy, UintTy};
|
||||
pub(crate) use rustc_span::Span;
|
||||
|
||||
pub(crate) use rustc_hir::def_id::{DefId, LOCAL_CRATE};
|
||||
@ -91,7 +90,7 @@ mod prelude {
|
||||
pub(crate) use rustc_middle::mir::{self, *};
|
||||
pub(crate) use rustc_middle::ty::layout::{self, TyAndLayout};
|
||||
pub(crate) use rustc_middle::ty::{
|
||||
self, FnSig, Instance, InstanceDef, ParamEnv, Ty, TyCtxt, TypeAndMut, TypeFoldable,
|
||||
self, FloatTy, FnSig, Instance, InstanceDef, IntTy, ParamEnv, Ty, TyCtxt, TypeAndMut, TypeFoldable, UintTy,
|
||||
};
|
||||
pub(crate) use rustc_target::abi::{Abi, LayoutOf, Scalar, Size, VariantIdx};
|
||||
|
||||
|
@ -304,9 +304,8 @@ impl BuilderMethods<'a, 'tcx> for Builder<'a, 'll, 'tcx> {
|
||||
lhs: Self::Value,
|
||||
rhs: Self::Value,
|
||||
) -> (Self::Value, Self::Value) {
|
||||
use rustc_ast::IntTy::*;
|
||||
use rustc_ast::UintTy::*;
|
||||
use rustc_middle::ty::{Int, Uint};
|
||||
use rustc_middle::ty::{IntTy::*, UintTy::*};
|
||||
|
||||
let new_kind = match ty.kind() {
|
||||
Int(t @ Isize) => Int(t.normalize(self.tcx.sess.target.pointer_width)),
|
||||
|
@ -18,7 +18,6 @@ use crate::llvm::debuginfo::{
|
||||
};
|
||||
use crate::value::Value;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
use rustc_data_structures::const_cstr;
|
||||
use rustc_data_structures::fingerprint::Fingerprint;
|
||||
@ -830,37 +829,37 @@ trait MsvcBasicName {
|
||||
fn msvc_basic_name(self) -> &'static str;
|
||||
}
|
||||
|
||||
impl MsvcBasicName for ast::IntTy {
|
||||
impl MsvcBasicName for ty::IntTy {
|
||||
fn msvc_basic_name(self) -> &'static str {
|
||||
match self {
|
||||
ast::IntTy::Isize => "ptrdiff_t",
|
||||
ast::IntTy::I8 => "__int8",
|
||||
ast::IntTy::I16 => "__int16",
|
||||
ast::IntTy::I32 => "__int32",
|
||||
ast::IntTy::I64 => "__int64",
|
||||
ast::IntTy::I128 => "__int128",
|
||||
ty::IntTy::Isize => "ptrdiff_t",
|
||||
ty::IntTy::I8 => "__int8",
|
||||
ty::IntTy::I16 => "__int16",
|
||||
ty::IntTy::I32 => "__int32",
|
||||
ty::IntTy::I64 => "__int64",
|
||||
ty::IntTy::I128 => "__int128",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MsvcBasicName for ast::UintTy {
|
||||
impl MsvcBasicName for ty::UintTy {
|
||||
fn msvc_basic_name(self) -> &'static str {
|
||||
match self {
|
||||
ast::UintTy::Usize => "size_t",
|
||||
ast::UintTy::U8 => "unsigned __int8",
|
||||
ast::UintTy::U16 => "unsigned __int16",
|
||||
ast::UintTy::U32 => "unsigned __int32",
|
||||
ast::UintTy::U64 => "unsigned __int64",
|
||||
ast::UintTy::U128 => "unsigned __int128",
|
||||
ty::UintTy::Usize => "size_t",
|
||||
ty::UintTy::U8 => "unsigned __int8",
|
||||
ty::UintTy::U16 => "unsigned __int16",
|
||||
ty::UintTy::U32 => "unsigned __int32",
|
||||
ty::UintTy::U64 => "unsigned __int64",
|
||||
ty::UintTy::U128 => "unsigned __int128",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl MsvcBasicName for ast::FloatTy {
|
||||
impl MsvcBasicName for ty::FloatTy {
|
||||
fn msvc_basic_name(self) -> &'static str {
|
||||
match self {
|
||||
ast::FloatTy::F32 => "float",
|
||||
ast::FloatTy::F64 => "double",
|
||||
ty::FloatTy::F32 => "float",
|
||||
ty::FloatTy::F64 => "double",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -7,13 +7,12 @@ use crate::llvm;
|
||||
use crate::llvm::{Bool, False, True};
|
||||
use crate::type_of::LayoutLlvmExt;
|
||||
use crate::value::Value;
|
||||
use rustc_ast as ast;
|
||||
use rustc_codegen_ssa::common::TypeKind;
|
||||
use rustc_codegen_ssa::traits::*;
|
||||
use rustc_data_structures::small_c_str::SmallCStr;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::layout::TyAndLayout;
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
use rustc_target::abi::call::{CastTarget, FnAbi, Reg};
|
||||
use rustc_target::abi::{AddressSpace, Align, Integer, Size};
|
||||
|
||||
@ -80,32 +79,32 @@ impl CodegenCx<'ll, 'tcx> {
|
||||
self.type_i8()
|
||||
}
|
||||
|
||||
crate fn type_int_from_ty(&self, t: ast::IntTy) -> &'ll Type {
|
||||
crate fn type_int_from_ty(&self, t: ty::IntTy) -> &'ll Type {
|
||||
match t {
|
||||
ast::IntTy::Isize => self.type_isize(),
|
||||
ast::IntTy::I8 => self.type_i8(),
|
||||
ast::IntTy::I16 => self.type_i16(),
|
||||
ast::IntTy::I32 => self.type_i32(),
|
||||
ast::IntTy::I64 => self.type_i64(),
|
||||
ast::IntTy::I128 => self.type_i128(),
|
||||
ty::IntTy::Isize => self.type_isize(),
|
||||
ty::IntTy::I8 => self.type_i8(),
|
||||
ty::IntTy::I16 => self.type_i16(),
|
||||
ty::IntTy::I32 => self.type_i32(),
|
||||
ty::IntTy::I64 => self.type_i64(),
|
||||
ty::IntTy::I128 => self.type_i128(),
|
||||
}
|
||||
}
|
||||
|
||||
crate fn type_uint_from_ty(&self, t: ast::UintTy) -> &'ll Type {
|
||||
crate fn type_uint_from_ty(&self, t: ty::UintTy) -> &'ll Type {
|
||||
match t {
|
||||
ast::UintTy::Usize => self.type_isize(),
|
||||
ast::UintTy::U8 => self.type_i8(),
|
||||
ast::UintTy::U16 => self.type_i16(),
|
||||
ast::UintTy::U32 => self.type_i32(),
|
||||
ast::UintTy::U64 => self.type_i64(),
|
||||
ast::UintTy::U128 => self.type_i128(),
|
||||
ty::UintTy::Usize => self.type_isize(),
|
||||
ty::UintTy::U8 => self.type_i8(),
|
||||
ty::UintTy::U16 => self.type_i16(),
|
||||
ty::UintTy::U32 => self.type_i32(),
|
||||
ty::UintTy::U64 => self.type_i64(),
|
||||
ty::UintTy::U128 => self.type_i128(),
|
||||
}
|
||||
}
|
||||
|
||||
crate fn type_float_from_ty(&self, t: ast::FloatTy) -> &'ll Type {
|
||||
crate fn type_float_from_ty(&self, t: ty::FloatTy) -> &'ll Type {
|
||||
match t {
|
||||
ast::FloatTy::F32 => self.type_f32(),
|
||||
ast::FloatTy::F64 => self.type_f64(),
|
||||
ty::FloatTy::F32 => self.type_f32(),
|
||||
ty::FloatTy::F64 => self.type_f64(),
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -875,20 +875,16 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
ty::Uint(_) => value.to_string(),
|
||||
ty::Int(int_ty) => {
|
||||
match int_ty.normalize(bx.tcx().sess.target.pointer_width) {
|
||||
ast::IntTy::I8 => (value as i8).to_string(),
|
||||
ast::IntTy::I16 => (value as i16).to_string(),
|
||||
ast::IntTy::I32 => (value as i32).to_string(),
|
||||
ast::IntTy::I64 => (value as i64).to_string(),
|
||||
ast::IntTy::I128 => (value as i128).to_string(),
|
||||
ast::IntTy::Isize => unreachable!(),
|
||||
ty::IntTy::I8 => (value as i8).to_string(),
|
||||
ty::IntTy::I16 => (value as i16).to_string(),
|
||||
ty::IntTy::I32 => (value as i32).to_string(),
|
||||
ty::IntTy::I64 => (value as i64).to_string(),
|
||||
ty::IntTy::I128 => (value as i128).to_string(),
|
||||
ty::IntTy::Isize => unreachable!(),
|
||||
}
|
||||
}
|
||||
ty::Float(ast::FloatTy::F32) => {
|
||||
f32::from_bits(value as u32).to_string()
|
||||
}
|
||||
ty::Float(ast::FloatTy::F64) => {
|
||||
f64::from_bits(value as u64).to_string()
|
||||
}
|
||||
ty::Float(ty::FloatTy::F32) => f32::from_bits(value as u32).to_string(),
|
||||
ty::Float(ty::FloatTy::F64) => f64::from_bits(value as u64).to_string(),
|
||||
_ => span_bug!(span, "asm const has bad type {}", ty),
|
||||
};
|
||||
InlineAsmOperandRef::Const { string }
|
||||
|
@ -34,7 +34,6 @@ use super::{InferCtxt, MiscVariable, TypeTrace};
|
||||
|
||||
use crate::traits::{Obligation, PredicateObligations};
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::sso::SsoHashMap;
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_middle::traits::ObligationCause;
|
||||
@ -281,7 +280,7 @@ impl<'infcx, 'tcx> InferCtxt<'infcx, 'tcx> {
|
||||
&self,
|
||||
vid_is_expected: bool,
|
||||
vid: ty::FloatVid,
|
||||
val: ast::FloatTy,
|
||||
val: ty::FloatTy,
|
||||
) -> RelateResult<'tcx, Ty<'tcx>> {
|
||||
self.inner
|
||||
.borrow_mut()
|
||||
|
@ -168,25 +168,25 @@ fn lint_overflowing_range_endpoint<'tcx>(
|
||||
|
||||
// For `isize` & `usize`, be conservative with the warnings, so that the
|
||||
// warnings are consistent between 32- and 64-bit platforms.
|
||||
fn int_ty_range(int_ty: ast::IntTy) -> (i128, i128) {
|
||||
fn int_ty_range(int_ty: ty::IntTy) -> (i128, i128) {
|
||||
match int_ty {
|
||||
ast::IntTy::Isize => (i64::MIN.into(), i64::MAX.into()),
|
||||
ast::IntTy::I8 => (i8::MIN.into(), i8::MAX.into()),
|
||||
ast::IntTy::I16 => (i16::MIN.into(), i16::MAX.into()),
|
||||
ast::IntTy::I32 => (i32::MIN.into(), i32::MAX.into()),
|
||||
ast::IntTy::I64 => (i64::MIN.into(), i64::MAX.into()),
|
||||
ast::IntTy::I128 => (i128::MIN, i128::MAX),
|
||||
ty::IntTy::Isize => (i64::MIN.into(), i64::MAX.into()),
|
||||
ty::IntTy::I8 => (i8::MIN.into(), i8::MAX.into()),
|
||||
ty::IntTy::I16 => (i16::MIN.into(), i16::MAX.into()),
|
||||
ty::IntTy::I32 => (i32::MIN.into(), i32::MAX.into()),
|
||||
ty::IntTy::I64 => (i64::MIN.into(), i64::MAX.into()),
|
||||
ty::IntTy::I128 => (i128::MIN, i128::MAX),
|
||||
}
|
||||
}
|
||||
|
||||
fn uint_ty_range(uint_ty: ast::UintTy) -> (u128, u128) {
|
||||
fn uint_ty_range(uint_ty: ty::UintTy) -> (u128, u128) {
|
||||
let max = match uint_ty {
|
||||
ast::UintTy::Usize => u64::MAX.into(),
|
||||
ast::UintTy::U8 => u8::MAX.into(),
|
||||
ast::UintTy::U16 => u16::MAX.into(),
|
||||
ast::UintTy::U32 => u32::MAX.into(),
|
||||
ast::UintTy::U64 => u64::MAX.into(),
|
||||
ast::UintTy::U128 => u128::MAX,
|
||||
ty::UintTy::Usize => u64::MAX.into(),
|
||||
ty::UintTy::U8 => u8::MAX.into(),
|
||||
ty::UintTy::U16 => u16::MAX.into(),
|
||||
ty::UintTy::U32 => u32::MAX.into(),
|
||||
ty::UintTy::U64 => u64::MAX.into(),
|
||||
ty::UintTy::U128 => u128::MAX,
|
||||
};
|
||||
(0, max)
|
||||
}
|
||||
@ -258,8 +258,8 @@ fn report_bin_hex_error(
|
||||
//
|
||||
// No suggestion for: `isize`, `usize`.
|
||||
fn get_type_suggestion(t: Ty<'_>, val: u128, negative: bool) -> Option<&'static str> {
|
||||
use rustc_ast::IntTy::*;
|
||||
use rustc_ast::UintTy::*;
|
||||
use ty::IntTy::*;
|
||||
use ty::UintTy::*;
|
||||
macro_rules! find_fit {
|
||||
($ty:expr, $val:expr, $negative:expr,
|
||||
$($type:ident => [$($utypes:expr),*] => [$($itypes:expr),*]),+) => {
|
||||
@ -302,7 +302,7 @@ fn lint_int_literal<'tcx>(
|
||||
type_limits: &TypeLimits,
|
||||
e: &'tcx hir::Expr<'tcx>,
|
||||
lit: &hir::Lit,
|
||||
t: ast::IntTy,
|
||||
t: ty::IntTy,
|
||||
v: u128,
|
||||
) {
|
||||
let int_type = t.normalize(cx.sess().target.pointer_width);
|
||||
@ -314,7 +314,14 @@ fn lint_int_literal<'tcx>(
|
||||
// avoiding use of -min to prevent overflow/panic
|
||||
if (negative && v > max + 1) || (!negative && v > max) {
|
||||
if let Some(repr_str) = get_bin_hex_repr(cx, lit) {
|
||||
report_bin_hex_error(cx, e, attr::IntType::SignedInt(t), repr_str, v, negative);
|
||||
report_bin_hex_error(
|
||||
cx,
|
||||
e,
|
||||
attr::IntType::SignedInt(ty::ast_int_ty(t)),
|
||||
repr_str,
|
||||
v,
|
||||
negative,
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -351,7 +358,7 @@ fn lint_uint_literal<'tcx>(
|
||||
cx: &LateContext<'tcx>,
|
||||
e: &'tcx hir::Expr<'tcx>,
|
||||
lit: &hir::Lit,
|
||||
t: ast::UintTy,
|
||||
t: ty::UintTy,
|
||||
) {
|
||||
let uint_type = t.normalize(cx.sess().target.pointer_width);
|
||||
let (min, max) = uint_ty_range(uint_type);
|
||||
@ -391,7 +398,14 @@ fn lint_uint_literal<'tcx>(
|
||||
}
|
||||
}
|
||||
if let Some(repr_str) = get_bin_hex_repr(cx, lit) {
|
||||
report_bin_hex_error(cx, e, attr::IntType::UnsignedInt(t), repr_str, lit_val, false);
|
||||
report_bin_hex_error(
|
||||
cx,
|
||||
e,
|
||||
attr::IntType::UnsignedInt(ty::ast_uint_ty(t)),
|
||||
repr_str,
|
||||
lit_val,
|
||||
false,
|
||||
);
|
||||
return;
|
||||
}
|
||||
cx.struct_span_lint(OVERFLOWING_LITERALS, e.span, |lint| {
|
||||
@ -430,8 +444,8 @@ fn lint_literal<'tcx>(
|
||||
ty::Float(t) => {
|
||||
let is_infinite = match lit.node {
|
||||
ast::LitKind::Float(v, _) => match t {
|
||||
ast::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
|
||||
ast::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
|
||||
ty::FloatTy::F32 => v.as_str().parse().map(f32::is_infinite),
|
||||
ty::FloatTy::F64 => v.as_str().parse().map(f64::is_infinite),
|
||||
},
|
||||
_ => bug!(),
|
||||
};
|
||||
@ -984,7 +998,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
|
||||
help: Some("consider using `u32` or `libc::wchar_t` instead".into()),
|
||||
},
|
||||
|
||||
ty::Int(ast::IntTy::I128) | ty::Uint(ast::UintTy::U128) => FfiUnsafe {
|
||||
ty::Int(ty::IntTy::I128) | ty::Uint(ty::UintTy::U128) => FfiUnsafe {
|
||||
ty,
|
||||
reason: "128-bit integers don't currently have a known stable ABI".into(),
|
||||
help: None,
|
||||
|
@ -1,4 +1,4 @@
|
||||
use crate::ty::{self, FloatVarValue, InferConst, IntVarValue, Ty, TyCtxt};
|
||||
use crate::ty::{self, InferConst, Ty, TyCtxt};
|
||||
use rustc_data_structures::snapshot_vec;
|
||||
use rustc_data_structures::undo_log::UndoLogs;
|
||||
use rustc_data_structures::unify::{
|
||||
@ -15,36 +15,6 @@ pub trait ToType {
|
||||
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx>;
|
||||
}
|
||||
|
||||
/// Raw `TyVid` are used as the unification key for `sub_relations`;
|
||||
/// they carry no values.
|
||||
impl UnifyKey for ty::TyVid {
|
||||
type Value = ();
|
||||
fn index(&self) -> u32 {
|
||||
self.index
|
||||
}
|
||||
fn from_index(i: u32) -> ty::TyVid {
|
||||
ty::TyVid { index: i }
|
||||
}
|
||||
fn tag() -> &'static str {
|
||||
"TyVid"
|
||||
}
|
||||
}
|
||||
|
||||
impl UnifyKey for ty::IntVid {
|
||||
type Value = Option<IntVarValue>;
|
||||
fn index(&self) -> u32 {
|
||||
self.index
|
||||
}
|
||||
fn from_index(i: u32) -> ty::IntVid {
|
||||
ty::IntVid { index: i }
|
||||
}
|
||||
fn tag() -> &'static str {
|
||||
"IntVid"
|
||||
}
|
||||
}
|
||||
|
||||
impl EqUnifyValue for IntVarValue {}
|
||||
|
||||
#[derive(PartialEq, Copy, Clone, Debug)]
|
||||
pub struct RegionVidKey {
|
||||
/// The minimum region vid in the unification set. This is needed
|
||||
@ -80,7 +50,7 @@ impl UnifyKey for ty::RegionVid {
|
||||
}
|
||||
}
|
||||
|
||||
impl ToType for IntVarValue {
|
||||
impl ToType for ty::IntVarValue {
|
||||
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
match *self {
|
||||
ty::IntType(i) => tcx.mk_mach_int(i),
|
||||
@ -89,24 +59,7 @@ impl ToType for IntVarValue {
|
||||
}
|
||||
}
|
||||
|
||||
// Floating point type keys
|
||||
|
||||
impl UnifyKey for ty::FloatVid {
|
||||
type Value = Option<FloatVarValue>;
|
||||
fn index(&self) -> u32 {
|
||||
self.index
|
||||
}
|
||||
fn from_index(i: u32) -> ty::FloatVid {
|
||||
ty::FloatVid { index: i }
|
||||
}
|
||||
fn tag() -> &'static str {
|
||||
"FloatVid"
|
||||
}
|
||||
}
|
||||
|
||||
impl EqUnifyValue for FloatVarValue {}
|
||||
|
||||
impl ToType for FloatVarValue {
|
||||
impl ToType for ty::FloatVarValue {
|
||||
fn to_type<'tcx>(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
tcx.mk_mach_float(self.0)
|
||||
}
|
||||
|
@ -3,13 +3,12 @@
|
||||
|
||||
use crate::ty::{self, Ty};
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_macros::HashStable;
|
||||
|
||||
/// Types that are represented as ints.
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
|
||||
pub enum IntTy {
|
||||
U(ast::UintTy),
|
||||
U(ty::UintTy),
|
||||
I,
|
||||
CEnum,
|
||||
Bool,
|
||||
|
@ -19,10 +19,10 @@ use crate::ty::subst::{GenericArg, GenericArgKind, InternalSubsts, Subst, Substs
|
||||
use crate::ty::TyKind::*;
|
||||
use crate::ty::{
|
||||
self, AdtDef, AdtKind, Binder, BindingMode, BoundVar, CanonicalPolyFnSig, Const, ConstVid,
|
||||
DefIdTree, ExistentialPredicate, FloatVar, FloatVid, GenericParamDefKind, InferConst, InferTy,
|
||||
IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate, PredicateInner, PredicateKind,
|
||||
ProjectionTy, Region, RegionKind, ReprOptions, TraitObjectVisitor, Ty, TyKind, TyS, TyVar,
|
||||
TyVid, TypeAndMut, Visibility,
|
||||
DefIdTree, ExistentialPredicate, FloatTy, FloatVar, FloatVid, GenericParamDefKind, InferConst,
|
||||
InferTy, IntTy, IntVar, IntVid, List, ParamConst, ParamTy, PolyFnSig, Predicate,
|
||||
PredicateInner, PredicateKind, ProjectionTy, Region, RegionKind, ReprOptions,
|
||||
TraitObjectVisitor, Ty, TyKind, TyS, TyVar, TyVid, TypeAndMut, UintTy, Visibility,
|
||||
};
|
||||
use rustc_ast as ast;
|
||||
use rustc_ast::expand::allocator::AllocatorKind;
|
||||
@ -839,20 +839,20 @@ impl<'tcx> CommonTypes<'tcx> {
|
||||
bool: mk(Bool),
|
||||
char: mk(Char),
|
||||
never: mk(Never),
|
||||
isize: mk(Int(ast::IntTy::Isize)),
|
||||
i8: mk(Int(ast::IntTy::I8)),
|
||||
i16: mk(Int(ast::IntTy::I16)),
|
||||
i32: mk(Int(ast::IntTy::I32)),
|
||||
i64: mk(Int(ast::IntTy::I64)),
|
||||
i128: mk(Int(ast::IntTy::I128)),
|
||||
usize: mk(Uint(ast::UintTy::Usize)),
|
||||
u8: mk(Uint(ast::UintTy::U8)),
|
||||
u16: mk(Uint(ast::UintTy::U16)),
|
||||
u32: mk(Uint(ast::UintTy::U32)),
|
||||
u64: mk(Uint(ast::UintTy::U64)),
|
||||
u128: mk(Uint(ast::UintTy::U128)),
|
||||
f32: mk(Float(ast::FloatTy::F32)),
|
||||
f64: mk(Float(ast::FloatTy::F64)),
|
||||
isize: mk(Int(ty::IntTy::Isize)),
|
||||
i8: mk(Int(ty::IntTy::I8)),
|
||||
i16: mk(Int(ty::IntTy::I16)),
|
||||
i32: mk(Int(ty::IntTy::I32)),
|
||||
i64: mk(Int(ty::IntTy::I64)),
|
||||
i128: mk(Int(ty::IntTy::I128)),
|
||||
usize: mk(Uint(ty::UintTy::Usize)),
|
||||
u8: mk(Uint(ty::UintTy::U8)),
|
||||
u16: mk(Uint(ty::UintTy::U16)),
|
||||
u32: mk(Uint(ty::UintTy::U32)),
|
||||
u64: mk(Uint(ty::UintTy::U64)),
|
||||
u128: mk(Uint(ty::UintTy::U128)),
|
||||
f32: mk(Float(ty::FloatTy::F32)),
|
||||
f64: mk(Float(ty::FloatTy::F64)),
|
||||
str_: mk(Str),
|
||||
self_param: mk(ty::Param(ty::ParamTy { index: 0, name: kw::SelfUpper })),
|
||||
|
||||
@ -2102,32 +2102,32 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
if pred.kind() != binder { self.mk_predicate(binder) } else { pred }
|
||||
}
|
||||
|
||||
pub fn mk_mach_int(self, tm: ast::IntTy) -> Ty<'tcx> {
|
||||
pub fn mk_mach_int(self, tm: IntTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
ast::IntTy::Isize => self.types.isize,
|
||||
ast::IntTy::I8 => self.types.i8,
|
||||
ast::IntTy::I16 => self.types.i16,
|
||||
ast::IntTy::I32 => self.types.i32,
|
||||
ast::IntTy::I64 => self.types.i64,
|
||||
ast::IntTy::I128 => self.types.i128,
|
||||
IntTy::Isize => self.types.isize,
|
||||
IntTy::I8 => self.types.i8,
|
||||
IntTy::I16 => self.types.i16,
|
||||
IntTy::I32 => self.types.i32,
|
||||
IntTy::I64 => self.types.i64,
|
||||
IntTy::I128 => self.types.i128,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_mach_uint(self, tm: ast::UintTy) -> Ty<'tcx> {
|
||||
pub fn mk_mach_uint(self, tm: UintTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
ast::UintTy::Usize => self.types.usize,
|
||||
ast::UintTy::U8 => self.types.u8,
|
||||
ast::UintTy::U16 => self.types.u16,
|
||||
ast::UintTy::U32 => self.types.u32,
|
||||
ast::UintTy::U64 => self.types.u64,
|
||||
ast::UintTy::U128 => self.types.u128,
|
||||
UintTy::Usize => self.types.usize,
|
||||
UintTy::U8 => self.types.u8,
|
||||
UintTy::U16 => self.types.u16,
|
||||
UintTy::U32 => self.types.u32,
|
||||
UintTy::U64 => self.types.u64,
|
||||
UintTy::U128 => self.types.u128,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn mk_mach_float(self, tm: ast::FloatTy) -> Ty<'tcx> {
|
||||
pub fn mk_mach_float(self, tm: FloatTy) -> Ty<'tcx> {
|
||||
match tm {
|
||||
ast::FloatTy::F32 => self.types.f32,
|
||||
ast::FloatTy::F64 => self.types.f64,
|
||||
FloatTy::F32 => self.types.f32,
|
||||
FloatTy::F64 => self.types.f64,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,7 @@
|
||||
//! Diagnostics related methods for `TyS`.
|
||||
|
||||
use crate::ty::sty::InferTy;
|
||||
use crate::ty::TyKind::*;
|
||||
use crate::ty::{TyCtxt, TyS};
|
||||
use crate::ty::{InferTy, TyCtxt, TyS};
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
|
@ -1,7 +1,6 @@
|
||||
use crate::traits::{ObligationCause, ObligationCauseCode};
|
||||
use crate::ty::diagnostics::suggest_constraining_type_param;
|
||||
use crate::ty::{self, BoundRegionKind, Region, Ty, TyCtxt};
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::Applicability::{MachineApplicable, MaybeIncorrect};
|
||||
use rustc_errors::{pluralize, DiagnosticBuilder};
|
||||
use rustc_hir as hir;
|
||||
@ -48,7 +47,7 @@ pub enum TypeError<'tcx> {
|
||||
|
||||
Sorts(ExpectedFound<Ty<'tcx>>),
|
||||
IntMismatch(ExpectedFound<ty::IntVarValue>),
|
||||
FloatMismatch(ExpectedFound<ast::FloatTy>),
|
||||
FloatMismatch(ExpectedFound<ty::FloatTy>),
|
||||
Traits(ExpectedFound<DefId>),
|
||||
VariadicMismatch(ExpectedFound<bool>),
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::ich::StableHashingContext;
|
||||
use crate::ty::{self, Ty, TyCtxt};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use std::fmt::Debug;
|
||||
@ -24,9 +23,9 @@ where
|
||||
{
|
||||
BoolSimplifiedType,
|
||||
CharSimplifiedType,
|
||||
IntSimplifiedType(ast::IntTy),
|
||||
UintSimplifiedType(ast::UintTy),
|
||||
FloatSimplifiedType(ast::FloatTy),
|
||||
IntSimplifiedType(ty::IntTy),
|
||||
UintSimplifiedType(ty::UintTy),
|
||||
FloatSimplifiedType(ty::FloatTy),
|
||||
AdtSimplifiedType(D),
|
||||
StrSimplifiedType,
|
||||
ArraySimplifiedType,
|
||||
|
@ -4,7 +4,7 @@ use crate::mir::{GeneratorLayout, GeneratorSavedLocal};
|
||||
use crate::ty::subst::Subst;
|
||||
use crate::ty::{self, subst::SubstsRef, ReprOptions, Ty, TyCtxt, TypeFoldable};
|
||||
|
||||
use rustc_ast::{self as ast, IntTy, UintTy};
|
||||
use rustc_ast as ast;
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_hir as hir;
|
||||
@ -30,6 +30,8 @@ use std::ops::Bound;
|
||||
pub trait IntegerExt {
|
||||
fn to_ty<'tcx>(&self, tcx: TyCtxt<'tcx>, signed: bool) -> Ty<'tcx>;
|
||||
fn from_attr<C: HasDataLayout>(cx: &C, ity: attr::IntType) -> Integer;
|
||||
fn from_int_ty<C: HasDataLayout>(cx: &C, ity: ty::IntTy) -> Integer;
|
||||
fn from_uint_ty<C: HasDataLayout>(cx: &C, uty: ty::UintTy) -> Integer;
|
||||
fn repr_discr<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
ty: Ty<'tcx>,
|
||||
@ -60,17 +62,38 @@ impl IntegerExt for Integer {
|
||||
let dl = cx.data_layout();
|
||||
|
||||
match ity {
|
||||
attr::SignedInt(IntTy::I8) | attr::UnsignedInt(UintTy::U8) => I8,
|
||||
attr::SignedInt(IntTy::I16) | attr::UnsignedInt(UintTy::U16) => I16,
|
||||
attr::SignedInt(IntTy::I32) | attr::UnsignedInt(UintTy::U32) => I32,
|
||||
attr::SignedInt(IntTy::I64) | attr::UnsignedInt(UintTy::U64) => I64,
|
||||
attr::SignedInt(IntTy::I128) | attr::UnsignedInt(UintTy::U128) => I128,
|
||||
attr::SignedInt(IntTy::Isize) | attr::UnsignedInt(UintTy::Usize) => {
|
||||
attr::SignedInt(ast::IntTy::I8) | attr::UnsignedInt(ast::UintTy::U8) => I8,
|
||||
attr::SignedInt(ast::IntTy::I16) | attr::UnsignedInt(ast::UintTy::U16) => I16,
|
||||
attr::SignedInt(ast::IntTy::I32) | attr::UnsignedInt(ast::UintTy::U32) => I32,
|
||||
attr::SignedInt(ast::IntTy::I64) | attr::UnsignedInt(ast::UintTy::U64) => I64,
|
||||
attr::SignedInt(ast::IntTy::I128) | attr::UnsignedInt(ast::UintTy::U128) => I128,
|
||||
attr::SignedInt(ast::IntTy::Isize) | attr::UnsignedInt(ast::UintTy::Usize) => {
|
||||
dl.ptr_sized_integer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn from_int_ty<C: HasDataLayout>(cx: &C, ity: ty::IntTy) -> Integer {
|
||||
match ity {
|
||||
ty::IntTy::I8 => I8,
|
||||
ty::IntTy::I16 => I16,
|
||||
ty::IntTy::I32 => I32,
|
||||
ty::IntTy::I64 => I64,
|
||||
ty::IntTy::I128 => I128,
|
||||
ty::IntTy::Isize => cx.data_layout().ptr_sized_integer(),
|
||||
}
|
||||
}
|
||||
fn from_uint_ty<C: HasDataLayout>(cx: &C, ity: ty::UintTy) -> Integer {
|
||||
match ity {
|
||||
ty::UintTy::U8 => I8,
|
||||
ty::UintTy::U16 => I16,
|
||||
ty::UintTy::U32 => I32,
|
||||
ty::UintTy::U64 => I64,
|
||||
ty::UintTy::U128 => I128,
|
||||
ty::UintTy::Usize => cx.data_layout().ptr_sized_integer(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Finds the appropriate Integer type and signedness for the given
|
||||
/// signed discriminant range and `#[repr]` attribute.
|
||||
/// N.B.: `u128` values above `i128::MAX` will be treated as signed, but
|
||||
@ -487,11 +510,11 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
|
||||
self,
|
||||
Scalar { value: Int(I32, false), valid_range: 0..=0x10FFFF },
|
||||
)),
|
||||
ty::Int(ity) => scalar(Int(Integer::from_attr(dl, attr::SignedInt(ity)), true)),
|
||||
ty::Uint(ity) => scalar(Int(Integer::from_attr(dl, attr::UnsignedInt(ity)), false)),
|
||||
ty::Int(ity) => scalar(Int(Integer::from_int_ty(dl, ity), true)),
|
||||
ty::Uint(ity) => scalar(Int(Integer::from_uint_ty(dl, ity), false)),
|
||||
ty::Float(fty) => scalar(match fty {
|
||||
ast::FloatTy::F32 => F32,
|
||||
ast::FloatTy::F64 => F64,
|
||||
ty::FloatTy::F32 => F32,
|
||||
ty::FloatTy::F64 => F64,
|
||||
}),
|
||||
ty::FnPtr(_) => {
|
||||
let mut ptr = scalar_unit(Pointer);
|
||||
|
@ -65,7 +65,6 @@ use std::ptr;
|
||||
use std::str;
|
||||
|
||||
pub use self::sty::BoundRegionKind::*;
|
||||
pub use self::sty::InferTy::*;
|
||||
pub use self::sty::RegionKind;
|
||||
pub use self::sty::RegionKind::*;
|
||||
pub use self::sty::TyKind::*;
|
||||
@ -74,13 +73,14 @@ pub use self::sty::{BoundRegion, BoundRegionKind, EarlyBoundRegion, FreeRegion,
|
||||
pub use self::sty::{CanonicalPolyFnSig, FnSig, GenSig, PolyFnSig, PolyGenSig};
|
||||
pub use self::sty::{ClosureSubsts, GeneratorSubsts, TypeAndMut, UpvarSubsts};
|
||||
pub use self::sty::{ClosureSubstsParts, GeneratorSubstsParts};
|
||||
pub use self::sty::{ConstVid, FloatVid, IntVid, RegionVid, TyVid};
|
||||
pub use self::sty::{ExistentialPredicate, InferTy, ParamConst, ParamTy, ProjectionTy};
|
||||
pub use self::sty::{ConstVid, RegionVid};
|
||||
pub use self::sty::{ExistentialPredicate, ParamConst, ParamTy, ProjectionTy};
|
||||
pub use self::sty::{ExistentialProjection, PolyExistentialProjection};
|
||||
pub use self::sty::{ExistentialTraitRef, PolyExistentialTraitRef};
|
||||
pub use self::sty::{PolyTraitRef, TraitRef, TyKind};
|
||||
pub use crate::ty::diagnostics::*;
|
||||
pub use rustc_type_ir::{DebruijnIndex, TypeFlags, INNERMOST};
|
||||
pub use rustc_type_ir::InferTy::*;
|
||||
pub use rustc_type_ir::*;
|
||||
|
||||
pub use self::binding::BindingMode;
|
||||
pub use self::binding::BindingMode::*;
|
||||
@ -421,14 +421,6 @@ impl Visibility {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, TyDecodable, TyEncodable, HashStable)]
|
||||
pub enum Variance {
|
||||
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
|
||||
Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
|
||||
Contravariant, // T<A> <: T<B> iff B <: A -- e.g., function param type
|
||||
Bivariant, // T<A> <: T<B> -- e.g., unused type parameter
|
||||
}
|
||||
|
||||
/// The crate variances map is computed during typeck and contains the
|
||||
/// variance of every item in the local crate. You should not use it
|
||||
/// directly, because to do so will make your pass dependent on the
|
||||
@ -443,66 +435,6 @@ pub struct CrateVariancesMap<'tcx> {
|
||||
pub variances: FxHashMap<DefId, &'tcx [ty::Variance]>,
|
||||
}
|
||||
|
||||
impl Variance {
|
||||
/// `a.xform(b)` combines the variance of a context with the
|
||||
/// variance of a type with the following meaning. If we are in a
|
||||
/// context with variance `a`, and we encounter a type argument in
|
||||
/// a position with variance `b`, then `a.xform(b)` is the new
|
||||
/// variance with which the argument appears.
|
||||
///
|
||||
/// Example 1:
|
||||
///
|
||||
/// *mut Vec<i32>
|
||||
///
|
||||
/// Here, the "ambient" variance starts as covariant. `*mut T` is
|
||||
/// invariant with respect to `T`, so the variance in which the
|
||||
/// `Vec<i32>` appears is `Covariant.xform(Invariant)`, which
|
||||
/// yields `Invariant`. Now, the type `Vec<T>` is covariant with
|
||||
/// respect to its type argument `T`, and hence the variance of
|
||||
/// the `i32` here is `Invariant.xform(Covariant)`, which results
|
||||
/// (again) in `Invariant`.
|
||||
///
|
||||
/// Example 2:
|
||||
///
|
||||
/// fn(*const Vec<i32>, *mut Vec<i32)
|
||||
///
|
||||
/// The ambient variance is covariant. A `fn` type is
|
||||
/// contravariant with respect to its parameters, so the variance
|
||||
/// within which both pointer types appear is
|
||||
/// `Covariant.xform(Contravariant)`, or `Contravariant`. `*const
|
||||
/// T` is covariant with respect to `T`, so the variance within
|
||||
/// which the first `Vec<i32>` appears is
|
||||
/// `Contravariant.xform(Covariant)` or `Contravariant`. The same
|
||||
/// is true for its `i32` argument. In the `*mut T` case, the
|
||||
/// variance of `Vec<i32>` is `Contravariant.xform(Invariant)`,
|
||||
/// and hence the outermost type is `Invariant` with respect to
|
||||
/// `Vec<i32>` (and its `i32` argument).
|
||||
///
|
||||
/// Source: Figure 1 of "Taming the Wildcards:
|
||||
/// Combining Definition- and Use-Site Variance" published in PLDI'11.
|
||||
pub fn xform(self, v: ty::Variance) -> ty::Variance {
|
||||
match (self, v) {
|
||||
// Figure 1, column 1.
|
||||
(ty::Covariant, ty::Covariant) => ty::Covariant,
|
||||
(ty::Covariant, ty::Contravariant) => ty::Contravariant,
|
||||
(ty::Covariant, ty::Invariant) => ty::Invariant,
|
||||
(ty::Covariant, ty::Bivariant) => ty::Bivariant,
|
||||
|
||||
// Figure 1, column 2.
|
||||
(ty::Contravariant, ty::Covariant) => ty::Contravariant,
|
||||
(ty::Contravariant, ty::Contravariant) => ty::Covariant,
|
||||
(ty::Contravariant, ty::Invariant) => ty::Invariant,
|
||||
(ty::Contravariant, ty::Bivariant) => ty::Bivariant,
|
||||
|
||||
// Figure 1, column 3.
|
||||
(ty::Invariant, _) => ty::Invariant,
|
||||
|
||||
// Figure 1, column 4.
|
||||
(ty::Bivariant, _) => ty::Bivariant,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Contains information needed to resolve types and (in the future) look up
|
||||
// the types of AST nodes.
|
||||
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||
@ -804,15 +736,6 @@ pub struct CaptureInfo<'tcx> {
|
||||
pub type UpvarListMap = FxHashMap<DefId, FxIndexMap<hir::HirId, UpvarId>>;
|
||||
pub type UpvarCaptureMap<'tcx> = FxHashMap<UpvarId, UpvarCapture<'tcx>>;
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum IntVarValue {
|
||||
IntType(ast::IntTy),
|
||||
UintType(ast::UintTy),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct FloatVarValue(pub ast::FloatTy);
|
||||
|
||||
impl ty::EarlyBoundRegion {
|
||||
/// Does this early bound region have a name? Early bound regions normally
|
||||
/// always have names except when using anonymous lifetimes (`'_`).
|
||||
@ -3122,6 +3045,57 @@ pub fn is_impl_trait_defn(tcx: TyCtxt<'_>, def_id: DefId) -> Option<DefId> {
|
||||
None
|
||||
}
|
||||
|
||||
pub fn int_ty(ity: ast::IntTy) -> IntTy {
|
||||
match ity {
|
||||
ast::IntTy::Isize => IntTy::Isize,
|
||||
ast::IntTy::I8 => IntTy::I8,
|
||||
ast::IntTy::I16 => IntTy::I16,
|
||||
ast::IntTy::I32 => IntTy::I32,
|
||||
ast::IntTy::I64 => IntTy::I64,
|
||||
ast::IntTy::I128 => IntTy::I128,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn uint_ty(uty: ast::UintTy) -> UintTy {
|
||||
match uty {
|
||||
ast::UintTy::Usize => UintTy::Usize,
|
||||
ast::UintTy::U8 => UintTy::U8,
|
||||
ast::UintTy::U16 => UintTy::U16,
|
||||
ast::UintTy::U32 => UintTy::U32,
|
||||
ast::UintTy::U64 => UintTy::U64,
|
||||
ast::UintTy::U128 => UintTy::U128,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn float_ty(fty: ast::FloatTy) -> FloatTy {
|
||||
match fty {
|
||||
ast::FloatTy::F32 => FloatTy::F32,
|
||||
ast::FloatTy::F64 => FloatTy::F64,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ast_int_ty(ity: IntTy) -> ast::IntTy {
|
||||
match ity {
|
||||
IntTy::Isize => ast::IntTy::Isize,
|
||||
IntTy::I8 => ast::IntTy::I8,
|
||||
IntTy::I16 => ast::IntTy::I16,
|
||||
IntTy::I32 => ast::IntTy::I32,
|
||||
IntTy::I64 => ast::IntTy::I64,
|
||||
IntTy::I128 => ast::IntTy::I128,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn ast_uint_ty(uty: UintTy) -> ast::UintTy {
|
||||
match uty {
|
||||
UintTy::Usize => ast::UintTy::Usize,
|
||||
UintTy::U8 => ast::UintTy::U8,
|
||||
UintTy::U16 => ast::UintTy::U16,
|
||||
UintTy::U32 => ast::UintTy::U32,
|
||||
UintTy::U64 => ast::UintTy::U64,
|
||||
UintTy::U128 => ast::UintTy::U128,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn provide(providers: &mut ty::query::Providers) {
|
||||
context::provide(providers);
|
||||
erase_regions::provide(providers);
|
||||
|
@ -3,7 +3,6 @@ use crate::mir::interpret::{AllocId, ConstValue, GlobalAlloc, Pointer, Scalar};
|
||||
use crate::ty::subst::{GenericArg, GenericArgKind, Subst};
|
||||
use crate::ty::{self, ConstInt, DefIdTree, ParamConst, ScalarInt, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_apfloat::ieee::{Double, Single};
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{self, CtorKind, DefKind, Namespace};
|
||||
@ -557,14 +556,19 @@ pub trait PrettyPrinter<'tcx>:
|
||||
}
|
||||
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),
|
||||
ty::Infer(infer_ty) => {
|
||||
let verbose = self.tcx().sess.verbose();
|
||||
if let ty::TyVar(ty_vid) = infer_ty {
|
||||
if let Some(name) = self.infer_ty_name(ty_vid) {
|
||||
p!(write("{}", name))
|
||||
} else {
|
||||
p!(write("{}", infer_ty))
|
||||
if verbose {
|
||||
p!(write("{:?}", infer_ty))
|
||||
} else {
|
||||
p!(write("{}", infer_ty))
|
||||
}
|
||||
}
|
||||
} else {
|
||||
p!(write("{}", infer_ty))
|
||||
if verbose { p!(write("{:?}", infer_ty)) } else { p!(write("{}", infer_ty)) }
|
||||
}
|
||||
}
|
||||
ty::Error(_) => p!("[type error]"),
|
||||
@ -968,7 +972,7 @@ pub trait PrettyPrinter<'tcx>:
|
||||
ty::TyS {
|
||||
kind:
|
||||
ty::Array(
|
||||
ty::TyS { kind: ty::Uint(ast::UintTy::U8), .. },
|
||||
ty::TyS { kind: ty::Uint(ty::UintTy::U8), .. },
|
||||
ty::Const {
|
||||
val: ty::ConstKind::Value(ConstValue::Scalar(int)),
|
||||
..
|
||||
@ -997,10 +1001,10 @@ pub trait PrettyPrinter<'tcx>:
|
||||
(Scalar::Int(int), ty::Bool) if int == ScalarInt::FALSE => p!("false"),
|
||||
(Scalar::Int(int), ty::Bool) if int == ScalarInt::TRUE => p!("true"),
|
||||
// Float
|
||||
(Scalar::Int(int), ty::Float(ast::FloatTy::F32)) => {
|
||||
(Scalar::Int(int), ty::Float(ty::FloatTy::F32)) => {
|
||||
p!(write("{}f32", Single::try_from(int).unwrap()))
|
||||
}
|
||||
(Scalar::Int(int), ty::Float(ast::FloatTy::F64)) => {
|
||||
(Scalar::Int(int), ty::Float(ty::FloatTy::F64)) => {
|
||||
p!(write("{}f64", Double::try_from(int).unwrap()))
|
||||
}
|
||||
// Int
|
||||
@ -1246,7 +1250,7 @@ pub struct FmtPrinterData<'a, 'tcx, F> {
|
||||
|
||||
pub region_highlight_mode: RegionHighlightMode,
|
||||
|
||||
pub name_resolver: Option<Box<&'a dyn Fn(ty::sty::TyVid) -> Option<String>>>,
|
||||
pub name_resolver: Option<Box<&'a dyn Fn(ty::TyVid) -> Option<String>>>,
|
||||
}
|
||||
|
||||
impl<F> Deref for FmtPrinter<'a, 'tcx, F> {
|
||||
@ -2007,21 +2011,6 @@ define_print_and_forward_display! {
|
||||
p!("fn", pretty_fn_sig(self.inputs(), self.c_variadic, self.output()));
|
||||
}
|
||||
|
||||
ty::InferTy {
|
||||
if cx.tcx().sess.verbose() {
|
||||
p!(write("{:?}", self));
|
||||
return Ok(cx);
|
||||
}
|
||||
match *self {
|
||||
ty::TyVar(_) => p!("_"),
|
||||
ty::IntVar(_) => p!(write("{}", "{integer}")),
|
||||
ty::FloatVar(_) => p!(write("{}", "{float}")),
|
||||
ty::FreshTy(v) => p!(write("FreshTy({})", v)),
|
||||
ty::FreshIntTy(v) => p!(write("FreshIntTy({})", v)),
|
||||
ty::FreshFloatTy(v) => p!(write("FreshFloatTy({})", v))
|
||||
}
|
||||
}
|
||||
|
||||
ty::TraitRef<'tcx> {
|
||||
p!(write("<{} as {}>", self.self_ty(), self.print_only_trait_path()))
|
||||
}
|
||||
|
@ -111,81 +111,24 @@ impl fmt::Debug for ty::FreeRegion {
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::Variance {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match *self {
|
||||
ty::Covariant => "+",
|
||||
ty::Contravariant => "-",
|
||||
ty::Invariant => "o",
|
||||
ty::Bivariant => "*",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::FnSig<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "({:?}; c_variadic: {})->{:?}", self.inputs(), self.c_variadic, self.output())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::TyVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "_#{}t", self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> fmt::Debug for ty::ConstVid<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "_#{}c", self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::IntVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "_#{}i", self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::FloatVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "_#{}f", self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::RegionVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "'_#{}r", self.index())
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::InferTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ty::TyVar(ref v) => v.fmt(f),
|
||||
ty::IntVar(ref v) => v.fmt(f),
|
||||
ty::FloatVar(ref v) => v.fmt(f),
|
||||
ty::FreshTy(v) => write!(f, "FreshTy({:?})", v),
|
||||
ty::FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
|
||||
ty::FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::IntVarValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
ty::IntType(ref v) => v.fmt(f),
|
||||
ty::UintType(ref v) => v.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::FloatVarValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for ty::TraitRef<'tcx> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
with_no_trimmed_paths(|| fmt::Display::fmt(self, f))
|
||||
@ -274,7 +217,7 @@ TrivialTypeFoldableAndLiftImpls! {
|
||||
u64,
|
||||
String,
|
||||
crate::middle::region::Scope,
|
||||
::rustc_ast::FloatTy,
|
||||
crate::ty::FloatTy,
|
||||
::rustc_ast::InlineAsmOptions,
|
||||
::rustc_ast::InlineAsmTemplatePiece,
|
||||
::rustc_ast::NodeId,
|
||||
|
@ -2,17 +2,16 @@
|
||||
|
||||
#![allow(rustc::usage_of_ty_tykind)]
|
||||
|
||||
use self::InferTy::*;
|
||||
use self::TyKind::*;
|
||||
|
||||
use crate::infer::canonical::Canonical;
|
||||
use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
|
||||
use crate::ty::InferTy::{self, *};
|
||||
use crate::ty::{
|
||||
self, AdtDef, DefIdTree, Discr, Ty, TyCtxt, TypeFlags, TypeFoldable, WithConstness,
|
||||
};
|
||||
use crate::ty::{DelaySpanBugEmitted, List, ParamEnv, TyS};
|
||||
use polonius_engine::Atom;
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def_id::DefId;
|
||||
@ -104,13 +103,13 @@ pub enum TyKind<'tcx> {
|
||||
Char,
|
||||
|
||||
/// A primitive signed integer type. For example, `i32`.
|
||||
Int(ast::IntTy),
|
||||
Int(ty::IntTy),
|
||||
|
||||
/// A primitive unsigned integer type. For example, `u32`.
|
||||
Uint(ast::UintTy),
|
||||
Uint(ty::UintTy),
|
||||
|
||||
/// A primitive floating-point type. For example, `f64`.
|
||||
Float(ast::FloatTy),
|
||||
Float(ty::FloatTy),
|
||||
|
||||
/// Algebraic data types (ADT). For example: structures, enumerations and unions.
|
||||
///
|
||||
@ -1426,12 +1425,6 @@ pub struct EarlyBoundRegion {
|
||||
pub name: Symbol,
|
||||
}
|
||||
|
||||
/// A **ty**pe **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct TyVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
/// A **`const`** **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct ConstVid<'tcx> {
|
||||
@ -1439,18 +1432,6 @@ pub struct ConstVid<'tcx> {
|
||||
pub phantom: PhantomData<&'tcx ()>,
|
||||
}
|
||||
|
||||
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct IntVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
pub struct FloatVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
/// A **region** (lifetime) **v**ariable **ID**.
|
||||
pub struct RegionVid {
|
||||
@ -1464,43 +1445,6 @@ impl Atom for RegionVid {
|
||||
}
|
||||
}
|
||||
|
||||
/// A placeholder for a type that hasn't been inferred yet.
|
||||
///
|
||||
/// E.g., if we have an empty array (`[]`), then we create a fresh
|
||||
/// type variable for the element type since we won't know until it's
|
||||
/// used what the element type is supposed to be.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, TyEncodable, TyDecodable)]
|
||||
#[derive(HashStable)]
|
||||
pub enum InferTy {
|
||||
/// A type variable.
|
||||
TyVar(TyVid),
|
||||
/// An integral type variable (`{integer}`).
|
||||
///
|
||||
/// These are created when the compiler sees an integer literal like
|
||||
/// `1` that could be several different types (`u8`, `i32`, `u32`, etc.).
|
||||
/// We don't know until it's used what type it's supposed to be, so
|
||||
/// we create a fresh type variable.
|
||||
IntVar(IntVid),
|
||||
/// A floating-point type variable (`{float}`).
|
||||
///
|
||||
/// These are created when the compiler sees an float literal like
|
||||
/// `1.0` that could be either an `f32` or an `f64`.
|
||||
/// We don't know until it's used what type it's supposed to be, so
|
||||
/// we create a fresh type variable.
|
||||
FloatVar(FloatVid),
|
||||
|
||||
/// A [`FreshTy`][Self::FreshTy] is one that is generated as a replacement
|
||||
/// for an unbound type variable. This is convenient for caching etc. See
|
||||
/// `rustc_infer::infer::freshen` for more details.
|
||||
///
|
||||
/// Compare with [`TyVar`][Self::TyVar].
|
||||
FreshTy(u32),
|
||||
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar].
|
||||
FreshIntTy(u32),
|
||||
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar].
|
||||
FreshFloatTy(u32),
|
||||
}
|
||||
|
||||
rustc_index::newtype_index! {
|
||||
pub struct BoundVar { .. }
|
||||
}
|
||||
@ -1853,7 +1797,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
pub fn sequence_element_type(&self, tcx: TyCtxt<'tcx>) -> Ty<'tcx> {
|
||||
match self.kind() {
|
||||
Array(ty, _) | Slice(ty) => ty,
|
||||
Str => tcx.mk_mach_uint(ast::UintTy::U8),
|
||||
Str => tcx.mk_mach_uint(ty::UintTy::U8),
|
||||
_ => bug!("`sequence_element_type` called on non-sequence value: {}", self),
|
||||
}
|
||||
}
|
||||
@ -1993,7 +1937,7 @@ impl<'tcx> TyS<'tcx> {
|
||||
|
||||
#[inline]
|
||||
pub fn is_ptr_sized_integral(&self) -> bool {
|
||||
matches!(self.kind(), Int(ast::IntTy::Isize) | Uint(ast::UintTy::Usize))
|
||||
matches!(self.kind(), Int(ty::IntTy::Isize) | Uint(ty::UintTy::Usize))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@ -2181,9 +2125,9 @@ impl<'tcx> TyS<'tcx> {
|
||||
pub fn to_opt_closure_kind(&self) -> Option<ty::ClosureKind> {
|
||||
match self.kind() {
|
||||
Int(int_ty) => match int_ty {
|
||||
ast::IntTy::I8 => Some(ty::ClosureKind::Fn),
|
||||
ast::IntTy::I16 => Some(ty::ClosureKind::FnMut),
|
||||
ast::IntTy::I32 => Some(ty::ClosureKind::FnOnce),
|
||||
ty::IntTy::I8 => Some(ty::ClosureKind::Fn),
|
||||
ty::IntTy::I16 => Some(ty::ClosureKind::FnMut),
|
||||
ty::IntTy::I32 => Some(ty::ClosureKind::FnOnce),
|
||||
_ => bug!("cannot convert type `{:?}` to a closure kind", self),
|
||||
},
|
||||
|
||||
|
@ -34,7 +34,7 @@ impl<'tcx> fmt::Display for Discr<'tcx> {
|
||||
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self.ty.kind() {
|
||||
ty::Int(ity) => {
|
||||
let size = ty::tls::with(|tcx| Integer::from_attr(&tcx, SignedInt(ity)).size());
|
||||
let size = ty::tls::with(|tcx| Integer::from_int_ty(&tcx, ity).size());
|
||||
let x = self.val;
|
||||
// sign extend the raw representation to be an i128
|
||||
let x = size.sign_extend(x) as i128;
|
||||
@ -59,8 +59,8 @@ fn unsigned_max(size: Size) -> u128 {
|
||||
|
||||
fn int_size_and_signed<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> (Size, bool) {
|
||||
let (int, signed) = match *ty.kind() {
|
||||
Int(ity) => (Integer::from_attr(&tcx, SignedInt(ity)), true),
|
||||
Uint(uty) => (Integer::from_attr(&tcx, UnsignedInt(uty)), false),
|
||||
Int(ity) => (Integer::from_int_ty(&tcx, ity), true),
|
||||
Uint(uty) => (Integer::from_uint_ty(&tcx, uty), false),
|
||||
_ => bug!("non integer discriminant"),
|
||||
};
|
||||
(int.size(), signed)
|
||||
@ -642,8 +642,8 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
ty::Char => Some(std::char::MAX as u128),
|
||||
ty::Float(fty) => Some(match fty {
|
||||
ast::FloatTy::F32 => rustc_apfloat::ieee::Single::INFINITY.to_bits(),
|
||||
ast::FloatTy::F64 => rustc_apfloat::ieee::Double::INFINITY.to_bits(),
|
||||
ty::FloatTy::F32 => rustc_apfloat::ieee::Single::INFINITY.to_bits(),
|
||||
ty::FloatTy::F64 => rustc_apfloat::ieee::Double::INFINITY.to_bits(),
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
@ -661,8 +661,8 @@ impl<'tcx> ty::TyS<'tcx> {
|
||||
}
|
||||
ty::Char => Some(0),
|
||||
ty::Float(fty) => Some(match fty {
|
||||
ast::FloatTy::F32 => (-::rustc_apfloat::ieee::Single::INFINITY).to_bits(),
|
||||
ast::FloatTy::F64 => (-::rustc_apfloat::ieee::Double::INFINITY).to_bits(),
|
||||
ty::FloatTy::F32 => (-::rustc_apfloat::ieee::Single::INFINITY).to_bits(),
|
||||
ty::FloatTy::F64 => (-::rustc_apfloat::ieee::Double::INFINITY).to_bits(),
|
||||
}),
|
||||
_ => None,
|
||||
};
|
||||
|
@ -2,13 +2,11 @@ use std::convert::TryFrom;
|
||||
|
||||
use rustc_apfloat::ieee::{Double, Single};
|
||||
use rustc_apfloat::{Float, FloatConvert};
|
||||
use rustc_ast::FloatTy;
|
||||
use rustc_attr as attr;
|
||||
use rustc_middle::mir::interpret::{InterpResult, PointerArithmetic, Scalar};
|
||||
use rustc_middle::mir::CastKind;
|
||||
use rustc_middle::ty::adjustment::PointerCast;
|
||||
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
|
||||
use rustc_middle::ty::{self, Ty, TypeAndMut};
|
||||
use rustc_middle::ty::{self, FloatTy, Ty, TypeAndMut};
|
||||
use rustc_span::symbol::sym;
|
||||
use rustc_target::abi::{Integer, LayoutOf, Variants};
|
||||
|
||||
@ -203,8 +201,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
match *cast_ty.kind() {
|
||||
Int(_) | Uint(_) | RawPtr(_) => {
|
||||
let size = match *cast_ty.kind() {
|
||||
Int(t) => Integer::from_attr(self, attr::IntType::SignedInt(t)).size(),
|
||||
Uint(t) => Integer::from_attr(self, attr::IntType::UnsignedInt(t)).size(),
|
||||
Int(t) => Integer::from_int_ty(self, t).size(),
|
||||
Uint(t) => Integer::from_uint_ty(self, t).size(),
|
||||
RawPtr(_) => self.pointer_size(),
|
||||
_ => bug!(),
|
||||
};
|
||||
@ -235,7 +233,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
match *dest_ty.kind() {
|
||||
// float -> uint
|
||||
Uint(t) => {
|
||||
let size = Integer::from_attr(self, attr::IntType::UnsignedInt(t)).size();
|
||||
let size = Integer::from_uint_ty(self, t).size();
|
||||
// `to_u128` is a saturating cast, which is what we need
|
||||
// (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r).
|
||||
let v = f.to_u128(size.bits_usize()).value;
|
||||
@ -244,7 +242,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
}
|
||||
// float -> int
|
||||
Int(t) => {
|
||||
let size = Integer::from_attr(self, attr::IntType::SignedInt(t)).size();
|
||||
let size = Integer::from_int_ty(self, t).size();
|
||||
// `to_i128` is a saturating cast, which is what we need
|
||||
// (https://doc.rust-lang.org/nightly/nightly-rustc/rustc_apfloat/trait.Float.html#method.to_i128_r).
|
||||
let v = f.to_i128(size.bits_usize()).value;
|
||||
|
@ -1,10 +1,9 @@
|
||||
use std::convert::TryFrom;
|
||||
|
||||
use rustc_apfloat::Float;
|
||||
use rustc_ast::FloatTy;
|
||||
use rustc_middle::mir;
|
||||
use rustc_middle::mir::interpret::{InterpResult, Scalar};
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout, Ty};
|
||||
use rustc_middle::ty::{self, layout::TyAndLayout, FloatTy, Ty};
|
||||
use rustc_target::abi::LayoutOf;
|
||||
|
||||
use super::{ImmTy, Immediate, InterpCx, Machine, PlaceTy};
|
||||
|
@ -15,7 +15,6 @@
|
||||
use crate::build::matches::{Ascription, Binding, Candidate, MatchPair};
|
||||
use crate::build::Builder;
|
||||
use crate::thir::{self, *};
|
||||
use rustc_attr::{SignedInt, UnsignedInt};
|
||||
use rustc_hir::RangeEnd;
|
||||
use rustc_middle::mir::Place;
|
||||
use rustc_middle::ty;
|
||||
@ -203,13 +202,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
(Some(('\u{0000}' as u128, '\u{10FFFF}' as u128, Size::from_bits(32))), 0)
|
||||
}
|
||||
ty::Int(ity) => {
|
||||
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
|
||||
let size = Integer::from_int_ty(&tcx, ity).size();
|
||||
let max = size.truncate(u128::MAX);
|
||||
let bias = 1u128 << (size.bits() - 1);
|
||||
(Some((0, max, size)), bias)
|
||||
}
|
||||
ty::Uint(uty) => {
|
||||
let size = Integer::from_attr(&tcx, UnsignedInt(uty)).size();
|
||||
let size = Integer::from_uint_ty(&tcx, uty).size();
|
||||
let max = size.truncate(u128::MAX);
|
||||
(Some((0, max, size)), 0)
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ crate fn lit_to_const<'tcx>(
|
||||
let id = tcx.allocate_bytes(data);
|
||||
ConstValue::Scalar(Scalar::Ptr(id.into()))
|
||||
}
|
||||
(ast::LitKind::Byte(n), ty::Uint(ast::UintTy::U8)) => {
|
||||
(ast::LitKind::Byte(n), ty::Uint(ty::UintTy::U8)) => {
|
||||
ConstValue::Scalar(Scalar::from_uint(*n, Size::from_bytes(1)))
|
||||
}
|
||||
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
|
||||
@ -56,11 +56,11 @@ crate fn lit_to_const<'tcx>(
|
||||
Ok(ty::Const::from_value(tcx, lit, ty))
|
||||
}
|
||||
|
||||
fn parse_float<'tcx>(num: Symbol, fty: ast::FloatTy, neg: bool) -> Result<ConstValue<'tcx>, ()> {
|
||||
fn parse_float<'tcx>(num: Symbol, fty: ty::FloatTy, neg: bool) -> Result<ConstValue<'tcx>, ()> {
|
||||
let num = num.as_str();
|
||||
use rustc_apfloat::ieee::{Double, Single};
|
||||
let scalar = match fty {
|
||||
ast::FloatTy::F32 => {
|
||||
ty::FloatTy::F32 => {
|
||||
num.parse::<f32>().map_err(|_| ())?;
|
||||
let mut f = num.parse::<Single>().unwrap_or_else(|e| {
|
||||
panic!("apfloat::ieee::Single failed to parse `{}`: {:?}", num, e)
|
||||
@ -70,7 +70,7 @@ fn parse_float<'tcx>(num: Symbol, fty: ast::FloatTy, neg: bool) -> Result<ConstV
|
||||
}
|
||||
Scalar::from_f32(f)
|
||||
}
|
||||
ast::FloatTy::F64 => {
|
||||
ty::FloatTy::F64 => {
|
||||
num.parse::<f64>().map_err(|_| ())?;
|
||||
let mut f = num.parse::<Double>().unwrap_or_else(|e| {
|
||||
panic!("apfloat::ieee::Double failed to parse `{}`: {:?}", num, e)
|
||||
|
@ -52,7 +52,6 @@ use super::{FieldPat, Pat, PatKind, PatRange};
|
||||
use rustc_data_structures::captures::Captures;
|
||||
use rustc_index::vec::Idx;
|
||||
|
||||
use rustc_attr::{SignedInt, UnsignedInt};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_hir::{HirId, RangeEnd};
|
||||
use rustc_middle::mir::interpret::ConstValue;
|
||||
@ -103,10 +102,10 @@ impl IntRange {
|
||||
ty::Bool => Some((Size::from_bytes(1), 0)),
|
||||
ty::Char => Some((Size::from_bytes(4), 0)),
|
||||
ty::Int(ity) => {
|
||||
let size = Integer::from_attr(&tcx, SignedInt(ity)).size();
|
||||
let size = Integer::from_int_ty(&tcx, ity).size();
|
||||
Some((size, 1u128 << (size.bits() as u128 - 1)))
|
||||
}
|
||||
ty::Uint(uty) => Some((Integer::from_attr(&tcx, UnsignedInt(uty)).size(), 0)),
|
||||
ty::Uint(uty) => Some((Integer::from_uint_ty(&tcx, uty).size(), 0)),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@ -167,7 +166,7 @@ impl IntRange {
|
||||
fn signed_bias(tcx: TyCtxt<'_>, ty: Ty<'_>) -> u128 {
|
||||
match *ty.kind() {
|
||||
ty::Int(ity) => {
|
||||
let bits = Integer::from_attr(&tcx, SignedInt(ity)).size().bits() as u128;
|
||||
let bits = Integer::from_int_ty(&tcx, ity).size().bits() as u128;
|
||||
1u128 << (bits - 1)
|
||||
}
|
||||
_ => 0,
|
||||
@ -959,13 +958,13 @@ impl<'tcx> SplitWildcard<'tcx> {
|
||||
smallvec![NonExhaustive]
|
||||
}
|
||||
&ty::Int(ity) => {
|
||||
let bits = Integer::from_attr(&cx.tcx, SignedInt(ity)).size().bits() as u128;
|
||||
let bits = Integer::from_int_ty(&cx.tcx, ity).size().bits() as u128;
|
||||
let min = 1u128 << (bits - 1);
|
||||
let max = min - 1;
|
||||
smallvec![make_range(min, max)]
|
||||
}
|
||||
&ty::Uint(uty) => {
|
||||
let size = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size();
|
||||
let size = Integer::from_uint_ty(&cx.tcx, uty).size();
|
||||
let max = size.truncate(u128::MAX);
|
||||
smallvec![make_range(0, max)]
|
||||
}
|
||||
|
@ -9,7 +9,6 @@ pub(crate) use self::check_match::check_match;
|
||||
|
||||
use crate::thir::util::UserAnnotatedTyHelpers;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
|
||||
@ -1069,20 +1068,19 @@ crate fn compare_const_vals<'tcx>(
|
||||
if let (Some(a), Some(b)) = (a_bits, b_bits) {
|
||||
use rustc_apfloat::Float;
|
||||
return match *ty.kind() {
|
||||
ty::Float(ast::FloatTy::F32) => {
|
||||
ty::Float(ty::FloatTy::F32) => {
|
||||
let l = rustc_apfloat::ieee::Single::from_bits(a);
|
||||
let r = rustc_apfloat::ieee::Single::from_bits(b);
|
||||
l.partial_cmp(&r)
|
||||
}
|
||||
ty::Float(ast::FloatTy::F64) => {
|
||||
ty::Float(ty::FloatTy::F64) => {
|
||||
let l = rustc_apfloat::ieee::Double::from_bits(a);
|
||||
let r = rustc_apfloat::ieee::Double::from_bits(b);
|
||||
l.partial_cmp(&r)
|
||||
}
|
||||
ty::Int(ity) => {
|
||||
use rustc_attr::SignedInt;
|
||||
use rustc_middle::ty::layout::IntegerExt;
|
||||
let size = rustc_target::abi::Integer::from_attr(&tcx, SignedInt(ity)).size();
|
||||
let size = rustc_target::abi::Integer::from_int_ty(&tcx, ity).size();
|
||||
let a = size.sign_extend(a);
|
||||
let b = size.sign_extend(b);
|
||||
Some((a as i128).cmp(&(b as i128)))
|
||||
|
@ -1,4 +1,4 @@
|
||||
use rustc_ast::{FloatTy, InlineAsmTemplatePiece, IntTy, UintTy};
|
||||
use rustc_ast::InlineAsmTemplatePiece;
|
||||
use rustc_errors::struct_span_err;
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
@ -7,7 +7,7 @@ use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
|
||||
use rustc_index::vec::Idx;
|
||||
use rustc_middle::ty::layout::{LayoutError, SizeSkeleton};
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
|
||||
use rustc_target::abi::{Pointer, VariantIdx};
|
||||
|
@ -1,4 +1,3 @@
|
||||
use rustc_ast::{FloatTy, IntTy, UintTy};
|
||||
use rustc_data_structures::base_n;
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_hir as hir;
|
||||
@ -6,7 +5,7 @@ use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::definitions::{DefPathData, DisambiguatedDefPathData};
|
||||
use rustc_middle::ty::print::{Print, Printer};
|
||||
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
|
||||
use rustc_middle::ty::{self, Instance, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{self, FloatTy, Instance, IntTy, Ty, TyCtxt, TypeFoldable, UintTy};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
|
||||
use std::fmt::Write;
|
||||
|
@ -346,26 +346,26 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
|
||||
(ty::Char, Scalar(Char)) => true,
|
||||
(ty::Int(ty1), Scalar(Int(ty2))) => matches!(
|
||||
(ty1, ty2),
|
||||
(ast::IntTy::Isize, chalk_ir::IntTy::Isize)
|
||||
| (ast::IntTy::I8, chalk_ir::IntTy::I8)
|
||||
| (ast::IntTy::I16, chalk_ir::IntTy::I16)
|
||||
| (ast::IntTy::I32, chalk_ir::IntTy::I32)
|
||||
| (ast::IntTy::I64, chalk_ir::IntTy::I64)
|
||||
| (ast::IntTy::I128, chalk_ir::IntTy::I128)
|
||||
(ty::IntTy::Isize, chalk_ir::IntTy::Isize)
|
||||
| (ty::IntTy::I8, chalk_ir::IntTy::I8)
|
||||
| (ty::IntTy::I16, chalk_ir::IntTy::I16)
|
||||
| (ty::IntTy::I32, chalk_ir::IntTy::I32)
|
||||
| (ty::IntTy::I64, chalk_ir::IntTy::I64)
|
||||
| (ty::IntTy::I128, chalk_ir::IntTy::I128)
|
||||
),
|
||||
(ty::Uint(ty1), Scalar(Uint(ty2))) => matches!(
|
||||
(ty1, ty2),
|
||||
(ast::UintTy::Usize, chalk_ir::UintTy::Usize)
|
||||
| (ast::UintTy::U8, chalk_ir::UintTy::U8)
|
||||
| (ast::UintTy::U16, chalk_ir::UintTy::U16)
|
||||
| (ast::UintTy::U32, chalk_ir::UintTy::U32)
|
||||
| (ast::UintTy::U64, chalk_ir::UintTy::U64)
|
||||
| (ast::UintTy::U128, chalk_ir::UintTy::U128)
|
||||
(ty::UintTy::Usize, chalk_ir::UintTy::Usize)
|
||||
| (ty::UintTy::U8, chalk_ir::UintTy::U8)
|
||||
| (ty::UintTy::U16, chalk_ir::UintTy::U16)
|
||||
| (ty::UintTy::U32, chalk_ir::UintTy::U32)
|
||||
| (ty::UintTy::U64, chalk_ir::UintTy::U64)
|
||||
| (ty::UintTy::U128, chalk_ir::UintTy::U128)
|
||||
),
|
||||
(ty::Float(ty1), Scalar(Float(ty2))) => matches!(
|
||||
(ty1, ty2),
|
||||
(ast::FloatTy::F32, chalk_ir::FloatTy::F32)
|
||||
| (ast::FloatTy::F64, chalk_ir::FloatTy::F64)
|
||||
(ty::FloatTy::F32, chalk_ir::FloatTy::F32)
|
||||
| (ty::FloatTy::F64, chalk_ir::FloatTy::F64)
|
||||
),
|
||||
(&ty::Tuple(substs), Tuple(len, _)) => substs.len() == *len,
|
||||
(&ty::Array(..), Array(..)) => true,
|
||||
|
@ -233,8 +233,6 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::AliasEq<RustInterner<'tcx>>>
|
||||
|
||||
impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
|
||||
fn lower_into(self, interner: &RustInterner<'tcx>) -> chalk_ir::Ty<RustInterner<'tcx>> {
|
||||
use rustc_ast as ast;
|
||||
|
||||
let int = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Int(i));
|
||||
let uint = |i| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Uint(i));
|
||||
let float = |f| chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Float(f));
|
||||
@ -243,24 +241,24 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Ty<RustInterner<'tcx>>> for Ty<'tcx> {
|
||||
ty::Bool => chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Bool),
|
||||
ty::Char => chalk_ir::TyKind::Scalar(chalk_ir::Scalar::Char),
|
||||
ty::Int(ty) => match ty {
|
||||
ast::IntTy::Isize => int(chalk_ir::IntTy::Isize),
|
||||
ast::IntTy::I8 => int(chalk_ir::IntTy::I8),
|
||||
ast::IntTy::I16 => int(chalk_ir::IntTy::I16),
|
||||
ast::IntTy::I32 => int(chalk_ir::IntTy::I32),
|
||||
ast::IntTy::I64 => int(chalk_ir::IntTy::I64),
|
||||
ast::IntTy::I128 => int(chalk_ir::IntTy::I128),
|
||||
ty::IntTy::Isize => int(chalk_ir::IntTy::Isize),
|
||||
ty::IntTy::I8 => int(chalk_ir::IntTy::I8),
|
||||
ty::IntTy::I16 => int(chalk_ir::IntTy::I16),
|
||||
ty::IntTy::I32 => int(chalk_ir::IntTy::I32),
|
||||
ty::IntTy::I64 => int(chalk_ir::IntTy::I64),
|
||||
ty::IntTy::I128 => int(chalk_ir::IntTy::I128),
|
||||
},
|
||||
ty::Uint(ty) => match ty {
|
||||
ast::UintTy::Usize => uint(chalk_ir::UintTy::Usize),
|
||||
ast::UintTy::U8 => uint(chalk_ir::UintTy::U8),
|
||||
ast::UintTy::U16 => uint(chalk_ir::UintTy::U16),
|
||||
ast::UintTy::U32 => uint(chalk_ir::UintTy::U32),
|
||||
ast::UintTy::U64 => uint(chalk_ir::UintTy::U64),
|
||||
ast::UintTy::U128 => uint(chalk_ir::UintTy::U128),
|
||||
ty::UintTy::Usize => uint(chalk_ir::UintTy::Usize),
|
||||
ty::UintTy::U8 => uint(chalk_ir::UintTy::U8),
|
||||
ty::UintTy::U16 => uint(chalk_ir::UintTy::U16),
|
||||
ty::UintTy::U32 => uint(chalk_ir::UintTy::U32),
|
||||
ty::UintTy::U64 => uint(chalk_ir::UintTy::U64),
|
||||
ty::UintTy::U128 => uint(chalk_ir::UintTy::U128),
|
||||
},
|
||||
ty::Float(ty) => match ty {
|
||||
ast::FloatTy::F32 => float(chalk_ir::FloatTy::F32),
|
||||
ast::FloatTy::F64 => float(chalk_ir::FloatTy::F64),
|
||||
ty::FloatTy::F32 => float(chalk_ir::FloatTy::F32),
|
||||
ty::FloatTy::F64 => float(chalk_ir::FloatTy::F64),
|
||||
},
|
||||
ty::Adt(def, substs) => {
|
||||
chalk_ir::TyKind::Adt(chalk_ir::AdtId(def), substs.lower_into(interner))
|
||||
@ -347,24 +345,24 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty<RustInterner<'tcx>> {
|
||||
chalk_ir::Scalar::Bool => ty::Bool,
|
||||
chalk_ir::Scalar::Char => ty::Char,
|
||||
chalk_ir::Scalar::Int(int_ty) => match int_ty {
|
||||
chalk_ir::IntTy::Isize => ty::Int(ast::IntTy::Isize),
|
||||
chalk_ir::IntTy::I8 => ty::Int(ast::IntTy::I8),
|
||||
chalk_ir::IntTy::I16 => ty::Int(ast::IntTy::I16),
|
||||
chalk_ir::IntTy::I32 => ty::Int(ast::IntTy::I32),
|
||||
chalk_ir::IntTy::I64 => ty::Int(ast::IntTy::I64),
|
||||
chalk_ir::IntTy::I128 => ty::Int(ast::IntTy::I128),
|
||||
chalk_ir::IntTy::Isize => ty::Int(ty::IntTy::Isize),
|
||||
chalk_ir::IntTy::I8 => ty::Int(ty::IntTy::I8),
|
||||
chalk_ir::IntTy::I16 => ty::Int(ty::IntTy::I16),
|
||||
chalk_ir::IntTy::I32 => ty::Int(ty::IntTy::I32),
|
||||
chalk_ir::IntTy::I64 => ty::Int(ty::IntTy::I64),
|
||||
chalk_ir::IntTy::I128 => ty::Int(ty::IntTy::I128),
|
||||
},
|
||||
chalk_ir::Scalar::Uint(int_ty) => match int_ty {
|
||||
chalk_ir::UintTy::Usize => ty::Uint(ast::UintTy::Usize),
|
||||
chalk_ir::UintTy::U8 => ty::Uint(ast::UintTy::U8),
|
||||
chalk_ir::UintTy::U16 => ty::Uint(ast::UintTy::U16),
|
||||
chalk_ir::UintTy::U32 => ty::Uint(ast::UintTy::U32),
|
||||
chalk_ir::UintTy::U64 => ty::Uint(ast::UintTy::U64),
|
||||
chalk_ir::UintTy::U128 => ty::Uint(ast::UintTy::U128),
|
||||
chalk_ir::UintTy::Usize => ty::Uint(ty::UintTy::Usize),
|
||||
chalk_ir::UintTy::U8 => ty::Uint(ty::UintTy::U8),
|
||||
chalk_ir::UintTy::U16 => ty::Uint(ty::UintTy::U16),
|
||||
chalk_ir::UintTy::U32 => ty::Uint(ty::UintTy::U32),
|
||||
chalk_ir::UintTy::U64 => ty::Uint(ty::UintTy::U64),
|
||||
chalk_ir::UintTy::U128 => ty::Uint(ty::UintTy::U128),
|
||||
},
|
||||
chalk_ir::Scalar::Float(float_ty) => match float_ty {
|
||||
chalk_ir::FloatTy::F32 => ty::Float(ast::FloatTy::F32),
|
||||
chalk_ir::FloatTy::F64 => ty::Float(ast::FloatTy::F64),
|
||||
chalk_ir::FloatTy::F32 => ty::Float(ty::FloatTy::F32),
|
||||
chalk_ir::FloatTy::F64 => ty::Float(ty::FloatTy::F64),
|
||||
},
|
||||
},
|
||||
TyKind::Array(ty, c) => {
|
||||
|
@ -12,3 +12,4 @@ bitflags = "1.2.1"
|
||||
rustc_index = { path = "../rustc_index" }
|
||||
rustc_serialize = { path = "../rustc_serialize" }
|
||||
rustc_data_structures = { path = "../rustc_data_structures" }
|
||||
rustc_macros = { path = "../rustc_macros" }
|
||||
|
@ -4,8 +4,13 @@
|
||||
|
||||
#[macro_use]
|
||||
extern crate bitflags;
|
||||
#[macro_use]
|
||||
extern crate rustc_macros;
|
||||
|
||||
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
|
||||
use rustc_data_structures::unify::{EqUnifyValue, UnifyKey};
|
||||
use std::fmt;
|
||||
use std::mem::discriminant;
|
||||
|
||||
bitflags! {
|
||||
/// Flags that we track on types. These flags are propagated upwards
|
||||
@ -197,8 +202,409 @@ impl DebruijnIndex {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Encodable, Decodable)]
|
||||
pub enum IntTy {
|
||||
Isize,
|
||||
I8,
|
||||
I16,
|
||||
I32,
|
||||
I64,
|
||||
I128,
|
||||
}
|
||||
|
||||
impl IntTy {
|
||||
pub fn name_str(&self) -> &'static str {
|
||||
match *self {
|
||||
IntTy::Isize => "isize",
|
||||
IntTy::I8 => "i8",
|
||||
IntTy::I16 => "i16",
|
||||
IntTy::I32 => "i32",
|
||||
IntTy::I64 => "i64",
|
||||
IntTy::I128 => "i128",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bit_width(&self) -> Option<u64> {
|
||||
Some(match *self {
|
||||
IntTy::Isize => return None,
|
||||
IntTy::I8 => 8,
|
||||
IntTy::I16 => 16,
|
||||
IntTy::I32 => 32,
|
||||
IntTy::I64 => 64,
|
||||
IntTy::I128 => 128,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn normalize(&self, target_width: u32) -> Self {
|
||||
match self {
|
||||
IntTy::Isize => match target_width {
|
||||
16 => IntTy::I16,
|
||||
32 => IntTy::I32,
|
||||
64 => IntTy::I64,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => *self,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Copy, Debug)]
|
||||
#[derive(Encodable, Decodable)]
|
||||
pub enum UintTy {
|
||||
Usize,
|
||||
U8,
|
||||
U16,
|
||||
U32,
|
||||
U64,
|
||||
U128,
|
||||
}
|
||||
|
||||
impl UintTy {
|
||||
pub fn name_str(&self) -> &'static str {
|
||||
match *self {
|
||||
UintTy::Usize => "usize",
|
||||
UintTy::U8 => "u8",
|
||||
UintTy::U16 => "u16",
|
||||
UintTy::U32 => "u32",
|
||||
UintTy::U64 => "u64",
|
||||
UintTy::U128 => "u128",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bit_width(&self) -> Option<u64> {
|
||||
Some(match *self {
|
||||
UintTy::Usize => return None,
|
||||
UintTy::U8 => 8,
|
||||
UintTy::U16 => 16,
|
||||
UintTy::U32 => 32,
|
||||
UintTy::U64 => 64,
|
||||
UintTy::U128 => 128,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn normalize(&self, target_width: u32) -> Self {
|
||||
match self {
|
||||
UintTy::Usize => match target_width {
|
||||
16 => UintTy::U16,
|
||||
32 => UintTy::U32,
|
||||
64 => UintTy::U64,
|
||||
_ => unreachable!(),
|
||||
},
|
||||
_ => *self,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
|
||||
#[derive(Encodable, Decodable)]
|
||||
pub enum FloatTy {
|
||||
F32,
|
||||
F64,
|
||||
}
|
||||
|
||||
impl FloatTy {
|
||||
pub fn name_str(self) -> &'static str {
|
||||
match self {
|
||||
FloatTy::F32 => "f32",
|
||||
FloatTy::F64 => "f64",
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bit_width(self) -> u64 {
|
||||
match self {
|
||||
FloatTy::F32 => 32,
|
||||
FloatTy::F64 => 64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub enum IntVarValue {
|
||||
IntType(IntTy),
|
||||
UintType(UintTy),
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, PartialEq, Eq)]
|
||||
pub struct FloatVarValue(pub FloatTy);
|
||||
|
||||
/// A **ty**pe **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
pub struct TyVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
/// An **int**egral (`u32`, `i32`, `usize`, etc.) type **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
pub struct IntVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
/// An **float**ing-point (`f32` or `f64`) type **v**ariable **ID**.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
pub struct FloatVid {
|
||||
pub index: u32,
|
||||
}
|
||||
|
||||
/// A placeholder for a type that hasn't been inferred yet.
|
||||
///
|
||||
/// E.g., if we have an empty array (`[]`), then we create a fresh
|
||||
/// type variable for the element type since we won't know until it's
|
||||
/// used what the element type is supposed to be.
|
||||
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable, Decodable)]
|
||||
pub enum InferTy {
|
||||
/// A type variable.
|
||||
TyVar(TyVid),
|
||||
/// An integral type variable (`{integer}`).
|
||||
///
|
||||
/// These are created when the compiler sees an integer literal like
|
||||
/// `1` that could be several different types (`u8`, `i32`, `u32`, etc.).
|
||||
/// We don't know until it's used what type it's supposed to be, so
|
||||
/// we create a fresh type variable.
|
||||
IntVar(IntVid),
|
||||
/// A floating-point type variable (`{float}`).
|
||||
///
|
||||
/// These are created when the compiler sees an float literal like
|
||||
/// `1.0` that could be either an `f32` or an `f64`.
|
||||
/// We don't know until it's used what type it's supposed to be, so
|
||||
/// we create a fresh type variable.
|
||||
FloatVar(FloatVid),
|
||||
|
||||
/// A [`FreshTy`][Self::FreshTy] is one that is generated as a replacement
|
||||
/// for an unbound type variable. This is convenient for caching etc. See
|
||||
/// `rustc_infer::infer::freshen` for more details.
|
||||
///
|
||||
/// Compare with [`TyVar`][Self::TyVar].
|
||||
FreshTy(u32),
|
||||
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`IntVar`][Self::IntVar].
|
||||
FreshIntTy(u32),
|
||||
/// Like [`FreshTy`][Self::FreshTy], but as a replacement for [`FloatVar`][Self::FloatVar].
|
||||
FreshFloatTy(u32),
|
||||
}
|
||||
|
||||
/// Raw `TyVid` are used as the unification key for `sub_relations`;
|
||||
/// they carry no values.
|
||||
impl UnifyKey for TyVid {
|
||||
type Value = ();
|
||||
fn index(&self) -> u32 {
|
||||
self.index
|
||||
}
|
||||
fn from_index(i: u32) -> TyVid {
|
||||
TyVid { index: i }
|
||||
}
|
||||
fn tag() -> &'static str {
|
||||
"TyVid"
|
||||
}
|
||||
}
|
||||
|
||||
impl EqUnifyValue for IntVarValue {}
|
||||
|
||||
impl UnifyKey for IntVid {
|
||||
type Value = Option<IntVarValue>;
|
||||
fn index(&self) -> u32 {
|
||||
self.index
|
||||
}
|
||||
fn from_index(i: u32) -> IntVid {
|
||||
IntVid { index: i }
|
||||
}
|
||||
fn tag() -> &'static str {
|
||||
"IntVid"
|
||||
}
|
||||
}
|
||||
|
||||
impl EqUnifyValue for FloatVarValue {}
|
||||
|
||||
impl UnifyKey for FloatVid {
|
||||
type Value = Option<FloatVarValue>;
|
||||
fn index(&self) -> u32 {
|
||||
self.index
|
||||
}
|
||||
fn from_index(i: u32) -> FloatVid {
|
||||
FloatVid { index: i }
|
||||
}
|
||||
fn tag() -> &'static str {
|
||||
"FloatVid"
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone, PartialEq, Decodable, Encodable)]
|
||||
pub enum Variance {
|
||||
Covariant, // T<A> <: T<B> iff A <: B -- e.g., function return type
|
||||
Invariant, // T<A> <: T<B> iff B == A -- e.g., type of mutable cell
|
||||
Contravariant, // T<A> <: T<B> iff B <: A -- e.g., function param type
|
||||
Bivariant, // T<A> <: T<B> -- e.g., unused type parameter
|
||||
}
|
||||
|
||||
impl Variance {
|
||||
/// `a.xform(b)` combines the variance of a context with the
|
||||
/// variance of a type with the following meaning. If we are in a
|
||||
/// context with variance `a`, and we encounter a type argument in
|
||||
/// a position with variance `b`, then `a.xform(b)` is the new
|
||||
/// variance with which the argument appears.
|
||||
///
|
||||
/// Example 1:
|
||||
///
|
||||
/// *mut Vec<i32>
|
||||
///
|
||||
/// Here, the "ambient" variance starts as covariant. `*mut T` is
|
||||
/// invariant with respect to `T`, so the variance in which the
|
||||
/// `Vec<i32>` appears is `Covariant.xform(Invariant)`, which
|
||||
/// yields `Invariant`. Now, the type `Vec<T>` is covariant with
|
||||
/// respect to its type argument `T`, and hence the variance of
|
||||
/// the `i32` here is `Invariant.xform(Covariant)`, which results
|
||||
/// (again) in `Invariant`.
|
||||
///
|
||||
/// Example 2:
|
||||
///
|
||||
/// fn(*const Vec<i32>, *mut Vec<i32)
|
||||
///
|
||||
/// The ambient variance is covariant. A `fn` type is
|
||||
/// contravariant with respect to its parameters, so the variance
|
||||
/// within which both pointer types appear is
|
||||
/// `Covariant.xform(Contravariant)`, or `Contravariant`. `*const
|
||||
/// T` is covariant with respect to `T`, so the variance within
|
||||
/// which the first `Vec<i32>` appears is
|
||||
/// `Contravariant.xform(Covariant)` or `Contravariant`. The same
|
||||
/// is true for its `i32` argument. In the `*mut T` case, the
|
||||
/// variance of `Vec<i32>` is `Contravariant.xform(Invariant)`,
|
||||
/// and hence the outermost type is `Invariant` with respect to
|
||||
/// `Vec<i32>` (and its `i32` argument).
|
||||
///
|
||||
/// Source: Figure 1 of "Taming the Wildcards:
|
||||
/// Combining Definition- and Use-Site Variance" published in PLDI'11.
|
||||
pub fn xform(self, v: Variance) -> Variance {
|
||||
match (self, v) {
|
||||
// Figure 1, column 1.
|
||||
(Variance::Covariant, Variance::Covariant) => Variance::Covariant,
|
||||
(Variance::Covariant, Variance::Contravariant) => Variance::Contravariant,
|
||||
(Variance::Covariant, Variance::Invariant) => Variance::Invariant,
|
||||
(Variance::Covariant, Variance::Bivariant) => Variance::Bivariant,
|
||||
|
||||
// Figure 1, column 2.
|
||||
(Variance::Contravariant, Variance::Covariant) => Variance::Contravariant,
|
||||
(Variance::Contravariant, Variance::Contravariant) => Variance::Covariant,
|
||||
(Variance::Contravariant, Variance::Invariant) => Variance::Invariant,
|
||||
(Variance::Contravariant, Variance::Bivariant) => Variance::Bivariant,
|
||||
|
||||
// Figure 1, column 3.
|
||||
(Variance::Invariant, _) => Variance::Invariant,
|
||||
|
||||
// Figure 1, column 4.
|
||||
(Variance::Bivariant, _) => Variance::Bivariant,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for DebruijnIndex {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
self.as_u32().hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for IntTy {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
discriminant(self).hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for UintTy {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
discriminant(self).hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for FloatTy {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
discriminant(self).hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for InferTy {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
use InferTy::*;
|
||||
match self {
|
||||
TyVar(v) => v.index.hash_stable(ctx, hasher),
|
||||
IntVar(v) => v.index.hash_stable(ctx, hasher),
|
||||
FloatVar(v) => v.index.hash_stable(ctx, hasher),
|
||||
FreshTy(v) | FreshIntTy(v) | FreshFloatTy(v) => v.hash_stable(ctx, hasher),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl<CTX> HashStable<CTX> for Variance {
|
||||
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
|
||||
discriminant(self).hash_stable(ctx, hasher);
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for IntVarValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match *self {
|
||||
IntVarValue::IntType(ref v) => v.fmt(f),
|
||||
IntVarValue::UintType(ref v) => v.fmt(f),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for FloatVarValue {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
self.0.fmt(f)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for TyVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "_#{}t", self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for IntVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "_#{}i", self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for FloatVid {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "_#{}f", self.index)
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for InferTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use InferTy::*;
|
||||
match *self {
|
||||
TyVar(ref v) => v.fmt(f),
|
||||
IntVar(ref v) => v.fmt(f),
|
||||
FloatVar(ref v) => v.fmt(f),
|
||||
FreshTy(v) => write!(f, "FreshTy({:?})", v),
|
||||
FreshIntTy(v) => write!(f, "FreshIntTy({:?})", v),
|
||||
FreshFloatTy(v) => write!(f, "FreshFloatTy({:?})", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Debug for Variance {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
f.write_str(match *self {
|
||||
Variance::Covariant => "+",
|
||||
Variance::Contravariant => "-",
|
||||
Variance::Invariant => "o",
|
||||
Variance::Bivariant => "*",
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for InferTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
use InferTy::*;
|
||||
match *self {
|
||||
TyVar(_) => write!(f, "_"),
|
||||
IntVar(_) => write!(f, "{}", "{integer}"),
|
||||
FloatVar(_) => write!(f, "{}", "{float}"),
|
||||
FreshTy(v) => write!(f, "FreshTy({})", v),
|
||||
FreshIntTy(v) => write!(f, "FreshIntTy({})", v),
|
||||
FreshFloatTy(v) => write!(f, "FreshFloatTy({})", v),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2059,9 +2059,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
||||
match prim_ty {
|
||||
hir::PrimTy::Bool => tcx.types.bool,
|
||||
hir::PrimTy::Char => tcx.types.char,
|
||||
hir::PrimTy::Int(it) => tcx.mk_mach_int(it),
|
||||
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(uit),
|
||||
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ft),
|
||||
hir::PrimTy::Int(it) => tcx.mk_mach_int(ty::int_ty(it)),
|
||||
hir::PrimTy::Uint(uit) => tcx.mk_mach_uint(ty::uint_ty(uit)),
|
||||
hir::PrimTy::Float(ft) => tcx.mk_mach_float(ty::float_ty(ft)),
|
||||
hir::PrimTy::Str => tcx.types.str_,
|
||||
}
|
||||
}
|
||||
|
@ -32,7 +32,6 @@ use super::FnCtxt;
|
||||
|
||||
use crate::hir::def_id::DefId;
|
||||
use crate::type_error_struct;
|
||||
use rustc_ast as ast;
|
||||
use rustc_errors::{struct_span_err, Applicability, DiagnosticBuilder, ErrorReported};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
@ -660,7 +659,7 @@ impl<'a, 'tcx> CastCheck<'tcx> {
|
||||
(_, Int(Bool)) => Err(CastError::CastToBool),
|
||||
|
||||
// * -> Char
|
||||
(Int(U(ast::UintTy::U8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
|
||||
(Int(U(ty::UintTy::U8)), Int(Char)) => Ok(CastKind::U8CharCast), // u8-char-cast
|
||||
(_, Int(Char)) => Err(CastError::CastToChar),
|
||||
|
||||
// prim -> float,ptr
|
||||
|
@ -372,13 +372,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// in C but we just error out instead and require explicit casts.
|
||||
let arg_ty = self.structurally_resolved_type(arg.span, arg_ty);
|
||||
match arg_ty.kind() {
|
||||
ty::Float(ast::FloatTy::F32) => {
|
||||
ty::Float(ty::FloatTy::F32) => {
|
||||
variadic_error(tcx.sess, arg.span, arg_ty, "c_double");
|
||||
}
|
||||
ty::Int(ast::IntTy::I8 | ast::IntTy::I16) | ty::Bool => {
|
||||
ty::Int(ty::IntTy::I8 | ty::IntTy::I16) | ty::Bool => {
|
||||
variadic_error(tcx.sess, arg.span, arg_ty, "c_int");
|
||||
}
|
||||
ty::Uint(ast::UintTy::U8 | ast::UintTy::U16) => {
|
||||
ty::Uint(ty::UintTy::U8 | ty::UintTy::U16) => {
|
||||
variadic_error(tcx.sess, arg.span, arg_ty, "c_uint");
|
||||
}
|
||||
ty::FnDef(..) => {
|
||||
@ -407,8 +407,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
}
|
||||
ast::LitKind::Byte(_) => tcx.types.u8,
|
||||
ast::LitKind::Char(_) => tcx.types.char,
|
||||
ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk_mach_int(t),
|
||||
ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => tcx.mk_mach_uint(t),
|
||||
ast::LitKind::Int(_, ast::LitIntType::Signed(t)) => tcx.mk_mach_int(ty::int_ty(t)),
|
||||
ast::LitKind::Int(_, ast::LitIntType::Unsigned(t)) => tcx.mk_mach_uint(ty::uint_ty(t)),
|
||||
ast::LitKind::Int(_, ast::LitIntType::Unsuffixed) => {
|
||||
let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() {
|
||||
ty::Int(_) | ty::Uint(_) => Some(ty),
|
||||
@ -419,7 +419,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
});
|
||||
opt_ty.unwrap_or_else(|| self.next_int_var())
|
||||
}
|
||||
ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => tcx.mk_mach_float(t),
|
||||
ast::LitKind::Float(_, ast::LitFloatType::Suffixed(t)) => {
|
||||
tcx.mk_mach_float(ty::float_ty(t))
|
||||
}
|
||||
ast::LitKind::Float(_, ast::LitFloatType::Unsuffixed) => {
|
||||
let opt_ty = expected.to_option(self).and_then(|ty| match ty.kind() {
|
||||
ty::Float(_) => Some(ty),
|
||||
|
@ -8,7 +8,6 @@ use crate::errors::MethodCallOnUnknownType;
|
||||
use crate::hir::def::DefKind;
|
||||
use crate::hir::def_id::DefId;
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir as hir;
|
||||
@ -662,30 +661,30 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
}
|
||||
ty::Int(i) => {
|
||||
let lang_def_id = match i {
|
||||
ast::IntTy::I8 => lang_items.i8_impl(),
|
||||
ast::IntTy::I16 => lang_items.i16_impl(),
|
||||
ast::IntTy::I32 => lang_items.i32_impl(),
|
||||
ast::IntTy::I64 => lang_items.i64_impl(),
|
||||
ast::IntTy::I128 => lang_items.i128_impl(),
|
||||
ast::IntTy::Isize => lang_items.isize_impl(),
|
||||
ty::IntTy::I8 => lang_items.i8_impl(),
|
||||
ty::IntTy::I16 => lang_items.i16_impl(),
|
||||
ty::IntTy::I32 => lang_items.i32_impl(),
|
||||
ty::IntTy::I64 => lang_items.i64_impl(),
|
||||
ty::IntTy::I128 => lang_items.i128_impl(),
|
||||
ty::IntTy::Isize => lang_items.isize_impl(),
|
||||
};
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::Uint(i) => {
|
||||
let lang_def_id = match i {
|
||||
ast::UintTy::U8 => lang_items.u8_impl(),
|
||||
ast::UintTy::U16 => lang_items.u16_impl(),
|
||||
ast::UintTy::U32 => lang_items.u32_impl(),
|
||||
ast::UintTy::U64 => lang_items.u64_impl(),
|
||||
ast::UintTy::U128 => lang_items.u128_impl(),
|
||||
ast::UintTy::Usize => lang_items.usize_impl(),
|
||||
ty::UintTy::U8 => lang_items.u8_impl(),
|
||||
ty::UintTy::U16 => lang_items.u16_impl(),
|
||||
ty::UintTy::U32 => lang_items.u32_impl(),
|
||||
ty::UintTy::U64 => lang_items.u64_impl(),
|
||||
ty::UintTy::U128 => lang_items.u128_impl(),
|
||||
ty::UintTy::Usize => lang_items.usize_impl(),
|
||||
};
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id);
|
||||
}
|
||||
ty::Float(f) => {
|
||||
let (lang_def_id1, lang_def_id2) = match f {
|
||||
ast::FloatTy::F32 => (lang_items.f32_impl(), lang_items.f32_runtime_impl()),
|
||||
ast::FloatTy::F64 => (lang_items.f64_impl(), lang_items.f64_runtime_impl()),
|
||||
ty::FloatTy::F32 => (lang_items.f32_impl(), lang_items.f32_runtime_impl()),
|
||||
ty::FloatTy::F64 => (lang_items.f64_impl(), lang_items.f64_runtime_impl()),
|
||||
};
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id1);
|
||||
self.assemble_inherent_impl_for_primitive(lang_def_id2);
|
||||
|
@ -13,7 +13,6 @@ use rustc_hir::def_id::{CrateNum, DefId, LocalDefId, LOCAL_CRATE};
|
||||
use rustc_hir::itemlikevisit::ItemLikeVisitor;
|
||||
use rustc_middle::ty::{self, CrateInherentImpls, TyCtxt};
|
||||
|
||||
use rustc_ast as ast;
|
||||
use rustc_span::Span;
|
||||
|
||||
/// On-demand query: yields a map containing all types mapped to their inherent impls.
|
||||
@ -178,7 +177,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Int(ast::IntTy::I8) => {
|
||||
ty::Int(ty::IntTy::I8) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.i8_impl(),
|
||||
@ -189,7 +188,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Int(ast::IntTy::I16) => {
|
||||
ty::Int(ty::IntTy::I16) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.i16_impl(),
|
||||
@ -200,7 +199,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Int(ast::IntTy::I32) => {
|
||||
ty::Int(ty::IntTy::I32) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.i32_impl(),
|
||||
@ -211,7 +210,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Int(ast::IntTy::I64) => {
|
||||
ty::Int(ty::IntTy::I64) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.i64_impl(),
|
||||
@ -222,7 +221,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Int(ast::IntTy::I128) => {
|
||||
ty::Int(ty::IntTy::I128) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.i128_impl(),
|
||||
@ -233,7 +232,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Int(ast::IntTy::Isize) => {
|
||||
ty::Int(ty::IntTy::Isize) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.isize_impl(),
|
||||
@ -244,7 +243,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Uint(ast::UintTy::U8) => {
|
||||
ty::Uint(ty::UintTy::U8) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.u8_impl(),
|
||||
@ -255,7 +254,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Uint(ast::UintTy::U16) => {
|
||||
ty::Uint(ty::UintTy::U16) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.u16_impl(),
|
||||
@ -266,7 +265,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Uint(ast::UintTy::U32) => {
|
||||
ty::Uint(ty::UintTy::U32) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.u32_impl(),
|
||||
@ -277,7 +276,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Uint(ast::UintTy::U64) => {
|
||||
ty::Uint(ty::UintTy::U64) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.u64_impl(),
|
||||
@ -288,7 +287,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Uint(ast::UintTy::U128) => {
|
||||
ty::Uint(ty::UintTy::U128) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.u128_impl(),
|
||||
@ -299,7 +298,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Uint(ast::UintTy::Usize) => {
|
||||
ty::Uint(ty::UintTy::Usize) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.usize_impl(),
|
||||
@ -310,7 +309,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Float(ast::FloatTy::F32) => {
|
||||
ty::Float(ty::FloatTy::F32) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.f32_impl(),
|
||||
@ -321,7 +320,7 @@ impl ItemLikeVisitor<'v> for InherentCollect<'tcx> {
|
||||
assoc_items,
|
||||
);
|
||||
}
|
||||
ty::Float(ast::FloatTy::F64) => {
|
||||
ty::Float(ty::FloatTy::F64) => {
|
||||
self.check_primitive_impl(
|
||||
def_id,
|
||||
lang_items.f64_impl(),
|
||||
|
@ -11,7 +11,6 @@ use std::{slice, vec};
|
||||
use rustc_ast::attr;
|
||||
use rustc_ast::util::comments::beautify_doc_string;
|
||||
use rustc_ast::{self as ast, AttrStyle};
|
||||
use rustc_ast::{FloatTy, IntTy, UintTy};
|
||||
use rustc_attr::{ConstStability, Deprecation, Stability, StabilityLevel};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_feature::UnstableFeatures;
|
||||
@ -21,7 +20,7 @@ use rustc_hir::def_id::{CrateNum, DefId};
|
||||
use rustc_hir::lang_items::LangItem;
|
||||
use rustc_hir::Mutability;
|
||||
use rustc_index::vec::IndexVec;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_middle::ty::{self, TyCtxt};
|
||||
use rustc_session::Session;
|
||||
use rustc_span::hygiene::MacroKind;
|
||||
use rustc_span::source_map::DUMMY_SP;
|
||||
@ -1456,6 +1455,7 @@ impl GetDefId for Type {
|
||||
|
||||
impl PrimitiveType {
|
||||
crate fn from_hir(prim: hir::PrimTy) -> PrimitiveType {
|
||||
use ast::{FloatTy, IntTy, UintTy};
|
||||
match prim {
|
||||
hir::PrimTy::Int(IntTy::Isize) => PrimitiveType::Isize,
|
||||
hir::PrimTy::Int(IntTy::I8) => PrimitiveType::I8,
|
||||
@ -1690,6 +1690,41 @@ impl From<ast::FloatTy> for PrimitiveType {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ty::IntTy> for PrimitiveType {
|
||||
fn from(int_ty: ty::IntTy) -> PrimitiveType {
|
||||
match int_ty {
|
||||
ty::IntTy::Isize => PrimitiveType::Isize,
|
||||
ty::IntTy::I8 => PrimitiveType::I8,
|
||||
ty::IntTy::I16 => PrimitiveType::I16,
|
||||
ty::IntTy::I32 => PrimitiveType::I32,
|
||||
ty::IntTy::I64 => PrimitiveType::I64,
|
||||
ty::IntTy::I128 => PrimitiveType::I128,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ty::UintTy> for PrimitiveType {
|
||||
fn from(uint_ty: ty::UintTy) -> PrimitiveType {
|
||||
match uint_ty {
|
||||
ty::UintTy::Usize => PrimitiveType::Usize,
|
||||
ty::UintTy::U8 => PrimitiveType::U8,
|
||||
ty::UintTy::U16 => PrimitiveType::U16,
|
||||
ty::UintTy::U32 => PrimitiveType::U32,
|
||||
ty::UintTy::U64 => PrimitiveType::U64,
|
||||
ty::UintTy::U128 => PrimitiveType::U128,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<ty::FloatTy> for PrimitiveType {
|
||||
fn from(float_ty: ty::FloatTy) -> PrimitiveType {
|
||||
match float_ty {
|
||||
ty::FloatTy::F32 => PrimitiveType::F32,
|
||||
ty::FloatTy::F64 => PrimitiveType::F64,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<hir::PrimTy> for PrimitiveType {
|
||||
fn from(prim_ty: hir::PrimTy) -> PrimitiveType {
|
||||
match prim_ty {
|
||||
|
@ -2,11 +2,10 @@ use crate::utils::{
|
||||
contains_name, get_pat_name, match_type, paths, single_segment_path, snippet_with_applicability, span_lint_and_sugg,
|
||||
};
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::UintTy;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir::{BinOpKind, BorrowKind, Expr, ExprKind, UnOp};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::{self, UintTy};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use rustc_span::sym;
|
||||
use rustc_span::Symbol;
|
||||
|
@ -2,14 +2,14 @@
|
||||
|
||||
use crate::utils::{clip, sext, unsext};
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
|
||||
use rustc_ast::ast::{self, LitFloatType, LitKind};
|
||||
use rustc_data_structures::sync::Lrc;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::{BinOp, BinOpKind, Block, Expr, ExprKind, HirId, QPath, UnOp};
|
||||
use rustc_lint::LateContext;
|
||||
use rustc_middle::mir::interpret::Scalar;
|
||||
use rustc_middle::ty::subst::{Subst, SubstsRef};
|
||||
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
|
||||
use rustc_middle::ty::{self, FloatTy, ScalarInt, Ty, TyCtxt};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::symbol::Symbol;
|
||||
use std::cmp::Ordering::{self, Equal};
|
||||
@ -167,8 +167,8 @@ pub fn lit_to_constant(lit: &LitKind, ty: Option<Ty<'_>>) -> Constant {
|
||||
LitKind::Char(c) => Constant::Char(c),
|
||||
LitKind::Int(n, _) => Constant::Int(n),
|
||||
LitKind::Float(ref is, LitFloatType::Suffixed(fty)) => match fty {
|
||||
FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
|
||||
FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
|
||||
ast::FloatTy::F32 => Constant::F32(is.as_str().parse().unwrap()),
|
||||
ast::FloatTy::F64 => Constant::F64(is.as_str().parse().unwrap()),
|
||||
},
|
||||
LitKind::Float(ref is, LitFloatType::Unsuffixed) => match ty.expect("type of float is known").kind() {
|
||||
ty::Float(FloatTy::F32) => Constant::F32(is.as_str().parse().unwrap()),
|
||||
|
@ -3,10 +3,9 @@
|
||||
|
||||
use crate::consts::{miri_to_const, Constant};
|
||||
use crate::utils::span_lint;
|
||||
use rustc_ast::ast::{IntTy, UintTy};
|
||||
use rustc_hir::{Item, ItemKind};
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::{self, IntTy, UintTy};
|
||||
use rustc_middle::ty::util::IntTypeExt;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use std::convert::TryFrom;
|
||||
|
@ -1,10 +1,10 @@
|
||||
use crate::utils::{numeric_literal, span_lint_and_sugg};
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::{FloatTy, LitFloatType, LitKind};
|
||||
use rustc_ast::ast::{self, LitFloatType, LitKind};
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty;
|
||||
use rustc_middle::ty::{self, FloatTy};
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint};
|
||||
use std::fmt;
|
||||
|
||||
@ -75,8 +75,8 @@ impl<'tcx> LateLintPass<'tcx> for FloatLiteral {
|
||||
let digits = count_digits(&sym_str);
|
||||
let max = max_digits(fty);
|
||||
let type_suffix = match lit_float_ty {
|
||||
LitFloatType::Suffixed(FloatTy::F32) => Some("f32"),
|
||||
LitFloatType::Suffixed(FloatTy::F64) => Some("f64"),
|
||||
LitFloatType::Suffixed(ast::FloatTy::F32) => Some("f32"),
|
||||
LitFloatType::Suffixed(ast::FloatTy::F64) => Some("f64"),
|
||||
LitFloatType::Unsuffixed => None
|
||||
};
|
||||
let (is_whole, mut float_str) = match fty {
|
||||
|
@ -3,7 +3,6 @@
|
||||
//! This lint is **warn** by default
|
||||
|
||||
use crate::utils::{is_type_diagnostic_item, span_lint};
|
||||
use rustc_ast::ast;
|
||||
use rustc_hir::Expr;
|
||||
use rustc_lint::{LateContext, LateLintPass};
|
||||
use rustc_middle::ty::{self, Ty};
|
||||
@ -77,8 +76,8 @@ impl<'tcx> LateLintPass<'tcx> for Mutex {
|
||||
atomic_name
|
||||
);
|
||||
match *mutex_param.kind() {
|
||||
ty::Uint(t) if t != ast::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
|
||||
ty::Int(t) if t != ast::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
|
||||
ty::Uint(t) if t != ty::UintTy::Usize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
|
||||
ty::Int(t) if t != ty::IntTy::Isize => span_lint(cx, MUTEX_INTEGER, expr.span, &msg),
|
||||
_ => span_lint(cx, MUTEX_ATOMIC, expr.span, &msg),
|
||||
};
|
||||
}
|
||||
|
@ -443,7 +443,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
|
||||
);
|
||||
},
|
||||
),
|
||||
(ty::Int(ast::IntTy::I32) | ty::Uint(ast::UintTy::U32), &ty::Char) => {
|
||||
(ty::Int(ty::IntTy::I32) | ty::Uint(ty::UintTy::U32), &ty::Char) => {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTE_INT_TO_CHAR,
|
||||
@ -468,7 +468,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
|
||||
(ty::Ref(_, ty_from, from_mutbl), ty::Ref(_, ty_to, to_mutbl)) => {
|
||||
if_chain! {
|
||||
if let (&ty::Slice(slice_ty), &ty::Str) = (&ty_from.kind(), &ty_to.kind());
|
||||
if let ty::Uint(ast::UintTy::U8) = slice_ty.kind();
|
||||
if let ty::Uint(ty::UintTy::U8) = slice_ty.kind();
|
||||
if from_mutbl == to_mutbl;
|
||||
then {
|
||||
let postfix = if *from_mutbl == Mutability::Mut {
|
||||
@ -536,7 +536,7 @@ impl<'tcx> LateLintPass<'tcx> for Transmute {
|
||||
}
|
||||
},
|
||||
),
|
||||
(ty::Int(ast::IntTy::I8) | ty::Uint(ast::UintTy::U8), ty::Bool) => {
|
||||
(ty::Int(ty::IntTy::I8) | ty::Uint(ty::UintTy::U8), ty::Bool) => {
|
||||
span_lint_and_then(
|
||||
cx,
|
||||
TRANSMUTE_INT_TO_BOOL,
|
||||
|
@ -5,7 +5,7 @@ use std::cmp::Ordering;
|
||||
use std::collections::BTreeMap;
|
||||
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::{FloatTy, IntTy, LitFloatType, LitIntType, LitKind, UintTy};
|
||||
use rustc_ast::{LitFloatType, LitIntType, LitKind};
|
||||
use rustc_errors::{Applicability, DiagnosticBuilder};
|
||||
use rustc_hir as hir;
|
||||
use rustc_hir::intravisit::{walk_body, walk_expr, walk_ty, FnKind, NestedVisitorMap, Visitor};
|
||||
@ -18,7 +18,7 @@ use rustc_lint::{LateContext, LateLintPass, LintContext};
|
||||
use rustc_middle::hir::map::Map;
|
||||
use rustc_middle::lint::in_external_macro;
|
||||
use rustc_middle::ty::TypeFoldable;
|
||||
use rustc_middle::ty::{self, InferTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults};
|
||||
use rustc_middle::ty::{self, FloatTy, InferTy, IntTy, Ty, TyCtxt, TyS, TypeAndMut, TypeckResults, UintTy};
|
||||
use rustc_semver::RustcVersion;
|
||||
use rustc_session::{declare_lint_pass, declare_tool_lint, impl_lint_pass};
|
||||
use rustc_span::hygiene::{ExpnKind, MacroKind};
|
||||
@ -1106,9 +1106,7 @@ fn is_empty_block(expr: &Expr<'_>) -> bool {
|
||||
expr.kind,
|
||||
ExprKind::Block(
|
||||
Block {
|
||||
stmts: &[],
|
||||
expr: None,
|
||||
..
|
||||
stmts: &[], expr: None, ..
|
||||
},
|
||||
_,
|
||||
)
|
||||
|
@ -35,7 +35,6 @@ use std::mem;
|
||||
|
||||
use if_chain::if_chain;
|
||||
use rustc_ast::ast::{self, Attribute, LitKind};
|
||||
use rustc_attr as attr;
|
||||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_errors::Applicability;
|
||||
use rustc_hir as hir;
|
||||
@ -1224,27 +1223,27 @@ pub fn get_arg_name(pat: &Pat<'_>) -> Option<Symbol> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn int_bits(tcx: TyCtxt<'_>, ity: ast::IntTy) -> u64 {
|
||||
Integer::from_attr(&tcx, attr::IntType::SignedInt(ity)).size().bits()
|
||||
pub fn int_bits(tcx: TyCtxt<'_>, ity: ty::IntTy) -> u64 {
|
||||
Integer::from_int_ty(&tcx, ity).size().bits()
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_possible_wrap)]
|
||||
/// Turn a constant int byte representation into an i128
|
||||
pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ast::IntTy) -> i128 {
|
||||
pub fn sext(tcx: TyCtxt<'_>, u: u128, ity: ty::IntTy) -> i128 {
|
||||
let amt = 128 - int_bits(tcx, ity);
|
||||
((u as i128) << amt) >> amt
|
||||
}
|
||||
|
||||
#[allow(clippy::cast_sign_loss)]
|
||||
/// clip unused bytes
|
||||
pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ast::IntTy) -> u128 {
|
||||
pub fn unsext(tcx: TyCtxt<'_>, u: i128, ity: ty::IntTy) -> u128 {
|
||||
let amt = 128 - int_bits(tcx, ity);
|
||||
((u as u128) << amt) >> amt
|
||||
}
|
||||
|
||||
/// clip unused bytes
|
||||
pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ast::UintTy) -> u128 {
|
||||
let bits = Integer::from_attr(&tcx, attr::IntType::UnsignedInt(ity)).size().bits();
|
||||
pub fn clip(tcx: TyCtxt<'_>, u: u128, ity: ty::UintTy) -> u128 {
|
||||
let bits = Integer::from_uint_ty(&tcx, ity).size().bits();
|
||||
let amt = 128 - bits;
|
||||
(u << amt) >> amt
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user