Stop relying on rustc_type_ir in non-type-system crates
This commit is contained in:
parent
19c84c8812
commit
b88f85a410
37 changed files with 136 additions and 163 deletions
|
@ -3440,7 +3440,6 @@ dependencies = [
|
|||
"rustc_symbol_mangling",
|
||||
"rustc_target",
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"serde_json",
|
||||
"smallvec",
|
||||
"tempfile",
|
||||
|
@ -3473,7 +3472,6 @@ dependencies = [
|
|||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
|
@ -3736,7 +3734,6 @@ dependencies = [
|
|||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"smallvec",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -3775,7 +3772,6 @@ dependencies = [
|
|||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"smallvec",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -3922,7 +3918,6 @@ dependencies = [
|
|||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"smallvec",
|
||||
"tracing",
|
||||
"unicode-security",
|
||||
|
@ -3998,7 +3993,6 @@ dependencies = [
|
|||
"rustc_session",
|
||||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_type_ir",
|
||||
"tempfile",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -4114,7 +4108,6 @@ dependencies = [
|
|||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"smallvec",
|
||||
"tracing",
|
||||
]
|
||||
|
@ -4538,7 +4531,6 @@ dependencies = [
|
|||
"rustc_span",
|
||||
"rustc_target",
|
||||
"rustc_trait_selection",
|
||||
"rustc_type_ir",
|
||||
"tracing",
|
||||
]
|
||||
|
||||
|
|
|
@ -40,7 +40,6 @@ rustc_span = { path = "../rustc_span" }
|
|||
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
serde_json = "1.0.59"
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
tempfile = "3.2"
|
||||
|
|
|
@ -12,10 +12,9 @@ use rustc_errors::{
|
|||
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
|
||||
};
|
||||
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
|
||||
use rustc_middle::ty::Ty;
|
||||
use rustc_middle::ty::layout::LayoutError;
|
||||
use rustc_middle::ty::{FloatTy, Ty};
|
||||
use rustc_span::{Span, Symbol};
|
||||
use rustc_type_ir::FloatTy;
|
||||
|
||||
use crate::assert_module_sources::CguReuse;
|
||||
use crate::back::command::Command;
|
||||
|
|
|
@ -43,7 +43,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
|||
mir::Const::Ty(_, c) => match c.kind() {
|
||||
// A constant that came from a const generic but was then used as an argument to
|
||||
// old-style simd_shuffle (passing as argument instead of as a generic param).
|
||||
rustc_type_ir::ConstKind::Value(cv) => return Ok(Ok(cv.valtree)),
|
||||
ty::ConstKind::Value(cv) => return Ok(Ok(cv.valtree)),
|
||||
other => span_bug!(constant.span, "{other:#?}"),
|
||||
},
|
||||
// We should never encounter `Const::Val` unless MIR opts (like const prop) evaluate
|
||||
|
|
|
@ -23,6 +23,5 @@ rustc_session = { path = "../rustc_session" }
|
|||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -9,7 +9,6 @@ use rustc_middle::ty::adjustment::PointerCoercion;
|
|||
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, TyAndLayout};
|
||||
use rustc_middle::ty::{self, FloatTy, Ty};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_type_ir::TyKind::*;
|
||||
use tracing::trace;
|
||||
|
||||
use super::util::ensure_monomorphic_enough;
|
||||
|
@ -182,9 +181,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
src: &ImmTy<'tcx, M::Provenance>,
|
||||
cast_to: TyAndLayout<'tcx>,
|
||||
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
|
||||
use rustc_type_ir::TyKind::*;
|
||||
|
||||
let Float(fty) = src.layout.ty.kind() else {
|
||||
let ty::Float(fty) = src.layout.ty.kind() else {
|
||||
bug!("FloatToFloat/FloatToInt cast: source type {} is not a float type", src.layout.ty)
|
||||
};
|
||||
let val = match fty {
|
||||
|
@ -277,19 +274,19 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
let signed = src_layout.backend_repr.is_signed(); // Also asserts that abi is `Scalar`.
|
||||
|
||||
let v = match src_layout.ty.kind() {
|
||||
Uint(_) | RawPtr(..) | FnPtr(..) => scalar.to_uint(src_layout.size)?,
|
||||
Int(_) => scalar.to_int(src_layout.size)? as u128, // we will cast back to `i128` below if the sign matters
|
||||
Bool => scalar.to_bool()?.into(),
|
||||
Char => scalar.to_char()?.into(),
|
||||
ty::Uint(_) | ty::RawPtr(..) | ty::FnPtr(..) => scalar.to_uint(src_layout.size)?,
|
||||
ty::Int(_) => scalar.to_int(src_layout.size)? as u128, // we will cast back to `i128` below if the sign matters
|
||||
ty::Bool => scalar.to_bool()?.into(),
|
||||
ty::Char => scalar.to_char()?.into(),
|
||||
_ => span_bug!(self.cur_span(), "invalid int-like cast from {}", src_layout.ty),
|
||||
};
|
||||
|
||||
interp_ok(match *cast_ty.kind() {
|
||||
// int -> int
|
||||
Int(_) | Uint(_) => {
|
||||
ty::Int(_) | ty::Uint(_) => {
|
||||
let size = match *cast_ty.kind() {
|
||||
Int(t) => Integer::from_int_ty(self, t).size(),
|
||||
Uint(t) => Integer::from_uint_ty(self, t).size(),
|
||||
ty::Int(t) => Integer::from_int_ty(self, t).size(),
|
||||
ty::Uint(t) => Integer::from_uint_ty(self, t).size(),
|
||||
_ => bug!(),
|
||||
};
|
||||
let v = size.truncate(v);
|
||||
|
@ -297,7 +294,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
}
|
||||
|
||||
// signed int -> float
|
||||
Float(fty) if signed => {
|
||||
ty::Float(fty) if signed => {
|
||||
let v = v as i128;
|
||||
match fty {
|
||||
FloatTy::F16 => Scalar::from_f16(Half::from_i128(v).value),
|
||||
|
@ -307,7 +304,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
}
|
||||
}
|
||||
// unsigned int -> float
|
||||
Float(fty) => match fty {
|
||||
ty::Float(fty) => match fty {
|
||||
FloatTy::F16 => Scalar::from_f16(Half::from_u128(v).value),
|
||||
FloatTy::F32 => Scalar::from_f32(Single::from_u128(v).value),
|
||||
FloatTy::F64 => Scalar::from_f64(Double::from_u128(v).value),
|
||||
|
@ -315,7 +312,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
},
|
||||
|
||||
// u8 -> char
|
||||
Char => Scalar::from_u32(u8::try_from(v).unwrap().into()),
|
||||
ty::Char => Scalar::from_u32(u8::try_from(v).unwrap().into()),
|
||||
|
||||
// Casts to bool are not permitted by rustc, no need to handle them here.
|
||||
_ => span_bug!(self.cur_span(), "invalid int to {} cast", cast_ty),
|
||||
|
@ -332,11 +329,9 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
+ FloatConvert<Double>
|
||||
+ FloatConvert<Quad>,
|
||||
{
|
||||
use rustc_type_ir::TyKind::*;
|
||||
|
||||
match *dest_ty.kind() {
|
||||
// float -> uint
|
||||
Uint(t) => {
|
||||
ty::Uint(t) => {
|
||||
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).
|
||||
|
@ -345,7 +340,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
Scalar::from_uint(v, size)
|
||||
}
|
||||
// float -> int
|
||||
Int(t) => {
|
||||
ty::Int(t) => {
|
||||
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).
|
||||
|
@ -353,7 +348,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
|
|||
Scalar::from_int(v, size)
|
||||
}
|
||||
// float -> float
|
||||
Float(fty) => match fty {
|
||||
ty::Float(fty) => match fty {
|
||||
FloatTy::F16 => {
|
||||
Scalar::from_f16(self.adjust_nan(f.convert(&mut false).value, &[f]))
|
||||
}
|
||||
|
|
|
@ -28,7 +28,6 @@ rustc_session = { path = "../rustc_session" }
|
|||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -21,15 +21,14 @@ use rustc_middle::ty::error::TypeErrorToStringExt;
|
|||
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
|
||||
use rustc_middle::ty::util::{Discr, IntTypeExt};
|
||||
use rustc_middle::ty::{
|
||||
AdtDef, BottomUpFolder, GenericArgKind, RegionKind, TypeSuperVisitable, TypeVisitable,
|
||||
TypeVisitableExt, fold_regions,
|
||||
AdtDef, BottomUpFolder, GenericArgKind, RegionKind, TypeFoldable, TypeSuperVisitable,
|
||||
TypeVisitable, TypeVisitableExt, fold_regions,
|
||||
};
|
||||
use rustc_session::lint::builtin::UNINHABITED_STATIC;
|
||||
use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
|
||||
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
|
||||
use rustc_trait_selection::traits;
|
||||
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
|
||||
use rustc_type_ir::TypeFoldable;
|
||||
use tracing::{debug, instrument};
|
||||
use ty::TypingMode;
|
||||
use {rustc_attr_parsing as attr, rustc_hir as hir};
|
||||
|
|
|
@ -16,10 +16,12 @@ use rustc_lint_defs::builtin::SUPERTRAIT_ITEM_SHADOWING_DEFINITION;
|
|||
use rustc_macros::LintDiagnostic;
|
||||
use rustc_middle::mir::interpret::ErrorHandled;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::traits::solve::NoSolution;
|
||||
use rustc_middle::ty::trait_def::TraitSpecializationKind;
|
||||
use rustc_middle::ty::{
|
||||
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
|
||||
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
|
||||
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags,
|
||||
TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
|
||||
Upcast,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::parse::feature_err;
|
||||
|
@ -34,8 +36,6 @@ use rustc_trait_selection::traits::{
|
|||
self, FulfillmentError, Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,
|
||||
WellFormedLoc,
|
||||
};
|
||||
use rustc_type_ir::TypeFlags;
|
||||
use rustc_type_ir::solve::NoSolution;
|
||||
use tracing::{debug, instrument};
|
||||
use {rustc_ast as ast, rustc_hir as hir};
|
||||
|
||||
|
|
|
@ -250,13 +250,16 @@ fn visit_implementation_of_dispatch_from_dyn(checker: &Checker<'_>) -> Result<()
|
|||
// trait, they *do* satisfy the repr(transparent) rules, and then we assume that everything else
|
||||
// in the compiler (in particular, all the call ABI logic) will treat them as repr(transparent)
|
||||
// even if they do not carry that attribute.
|
||||
use rustc_type_ir::TyKind::*;
|
||||
match (source.kind(), target.kind()) {
|
||||
(&Ref(r_a, _, mutbl_a), Ref(r_b, _, mutbl_b)) if r_a == *r_b && mutbl_a == *mutbl_b => {
|
||||
(&ty::Ref(r_a, _, mutbl_a), ty::Ref(r_b, _, mutbl_b))
|
||||
if r_a == *r_b && mutbl_a == *mutbl_b =>
|
||||
{
|
||||
Ok(())
|
||||
}
|
||||
(&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()),
|
||||
(&Adt(def_a, args_a), &Adt(def_b, args_b)) if def_a.is_struct() && def_b.is_struct() => {
|
||||
(&ty::RawPtr(_, a_mutbl), &ty::RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()),
|
||||
(&ty::Adt(def_a, args_a), &ty::Adt(def_b, args_b))
|
||||
if def_a.is_struct() && def_b.is_struct() =>
|
||||
{
|
||||
if def_a != def_b {
|
||||
let source_path = tcx.def_path_str(def_a.did());
|
||||
let target_path = tcx.def_path_str(def_b.did());
|
||||
|
|
|
@ -10,10 +10,9 @@ use rustc_errors::struct_span_code_err;
|
|||
use rustc_hir::LangItem;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt};
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitableExt, elaborate};
|
||||
use rustc_session::parse::feature_err;
|
||||
use rustc_span::{ErrorGuaranteed, sym};
|
||||
use rustc_type_ir::elaborate;
|
||||
use tracing::debug;
|
||||
|
||||
use crate::check::always_applicable;
|
||||
|
|
|
@ -3,12 +3,11 @@ use rustc_hir as hir;
|
|||
use rustc_infer::traits::util;
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgs, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
|
||||
shift_vars,
|
||||
Upcast, shift_vars,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::Span;
|
||||
use rustc_span::def_id::{DefId, LocalDefId};
|
||||
use rustc_type_ir::Upcast;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use super::ItemCtxt;
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
use rustc_data_structures::fx::FxHashSet;
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitor};
|
||||
use rustc_span::Span;
|
||||
use rustc_type_ir::TypeFoldable;
|
||||
use tracing::debug;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
|
|
|
@ -7,9 +7,10 @@ use std::assert_matches::debug_assert_matches;
|
|||
use rustc_data_structures::fx::FxHashMap;
|
||||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable};
|
||||
use rustc_middle::ty::{
|
||||
self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
|
||||
};
|
||||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
use rustc_type_ir::TypeVisitableExt;
|
||||
|
||||
type RemapTable = FxHashMap<u32, u32>;
|
||||
|
||||
|
|
|
@ -8,10 +8,12 @@ use rustc_hir::HirId;
|
|||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_middle::bug;
|
||||
use rustc_middle::ty::{self as ty, IsSuggestable, Ty, TyCtxt, Upcast};
|
||||
use rustc_middle::ty::{
|
||||
self as ty, IsSuggestable, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt,
|
||||
TypeVisitor, Upcast,
|
||||
};
|
||||
use rustc_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
|
||||
use rustc_trait_selection::traits;
|
||||
use rustc_type_ir::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
|
||||
use smallvec::SmallVec;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
|
|
|
@ -4,6 +4,7 @@ use rustc_errors::struct_span_code_err;
|
|||
use rustc_hir as hir;
|
||||
use rustc_hir::def::{DefKind, Res};
|
||||
use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS;
|
||||
use rustc_middle::ty::elaborate::ClauseWithSupertraitSpan;
|
||||
use rustc_middle::ty::{
|
||||
self, BottomUpFolder, DynKind, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable,
|
||||
TypeVisitableExt, Upcast,
|
||||
|
@ -11,7 +12,6 @@ use rustc_middle::ty::{
|
|||
use rustc_span::{ErrorGuaranteed, Span};
|
||||
use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility;
|
||||
use rustc_trait_selection::traits::{self, hir_ty_lowering_dyn_compatibility_violations};
|
||||
use rustc_type_ir::elaborate::ClauseWithSupertraitSpan;
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
|
|
|
@ -39,7 +39,7 @@ use rustc_middle::mir::interpret::LitToConstInput;
|
|||
use rustc_middle::ty::print::PrintPolyTraitRefExt as _;
|
||||
use rustc_middle::ty::{
|
||||
self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, ParamEnv, Ty, TyCtxt,
|
||||
TypeVisitableExt, TypingMode, fold_regions,
|
||||
TypeVisitableExt, TypingMode, Upcast, fold_regions,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
|
||||
|
@ -49,7 +49,6 @@ use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
|
|||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::wf::object_region_bounds;
|
||||
use rustc_trait_selection::traits::{self, ObligationCtxt};
|
||||
use rustc_type_ir::Upcast;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use self::errors::assoc_kind_str;
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
use rustc_data_structures::fx::FxIndexMap;
|
||||
use rustc_middle::ty::outlives::{Component, push_outlives_components};
|
||||
use rustc_middle::ty::{self, GenericArg, GenericArgKind, Region, Ty, TyCtxt};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_span::Span;
|
||||
use rustc_type_ir::outlives::{Component, push_outlives_components};
|
||||
use smallvec::smallvec;
|
||||
|
||||
/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred
|
||||
|
|
|
@ -23,7 +23,6 @@ rustc_middle = { path = "../rustc_middle" }
|
|||
rustc_session = { path = "../rustc_session" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -40,13 +40,12 @@ use rustc_middle::mir::Mutability;
|
|||
use rustc_middle::ty::adjustment::AllowTwoPhase;
|
||||
use rustc_middle::ty::cast::{CastKind, CastTy};
|
||||
use rustc_middle::ty::error::TypeError;
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, VariantDef};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeAndMut, TypeVisitableExt, VariantDef, elaborate};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_session::lint;
|
||||
use rustc_span::def_id::LOCAL_CRATE;
|
||||
use rustc_span::{DUMMY_SP, Span, sym};
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_type_ir::elaborate;
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
use super::FnCtxt;
|
||||
|
|
|
@ -13,13 +13,13 @@ use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
|
|||
use rustc_macros::{TypeFoldable, TypeVisitable};
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor,
|
||||
self, ClosureKind, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
|
||||
TypeVisitableExt, TypeVisitor,
|
||||
};
|
||||
use rustc_span::def_id::LocalDefId;
|
||||
use rustc_span::{DUMMY_SP, Span};
|
||||
use rustc_trait_selection::error_reporting::traits::ArgKind;
|
||||
use rustc_trait_selection::traits;
|
||||
use rustc_type_ir::ClosureKind;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use super::{CoroutineTypes, Expectation, FnCtxt, check_fn};
|
||||
|
|
|
@ -1,13 +1,12 @@
|
|||
//! A utility module to inspect currently ambiguous obligations in the current context.
|
||||
|
||||
use rustc_infer::traits::{self, ObligationCause, PredicateObligations};
|
||||
use rustc_middle::traits::solve::Goal;
|
||||
use rustc_middle::traits::solve::{Goal, GoalSource};
|
||||
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
|
||||
use rustc_span::Span;
|
||||
use rustc_trait_selection::solve::inspect::{
|
||||
InspectConfig, InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor,
|
||||
};
|
||||
use rustc_type_ir::solve::GoalSource;
|
||||
use tracing::{debug, instrument, trace};
|
||||
|
||||
use crate::FnCtxt;
|
||||
|
|
|
@ -14,6 +14,7 @@ use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
|
|||
use rustc_infer::traits::ObligationCauseCode;
|
||||
use rustc_middle::middle::stability;
|
||||
use rustc_middle::query::Providers;
|
||||
use rustc_middle::ty::elaborate::supertrait_def_ids;
|
||||
use rustc_middle::ty::fast_reject::{TreatParams, simplify_type};
|
||||
use rustc_middle::ty::{
|
||||
self, AssocItem, AssocItemContainer, GenericArgs, GenericArgsRef, GenericParamDefKind,
|
||||
|
@ -34,7 +35,6 @@ use rustc_trait_selection::traits::query::method_autoderef::{
|
|||
CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
|
||||
};
|
||||
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
|
||||
use rustc_type_ir::elaborate::supertrait_def_ids;
|
||||
use smallvec::{SmallVec, smallvec};
|
||||
use tracing::{debug, instrument};
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ use rustc_span::source_map::Spanned;
|
|||
use rustc_span::{Ident, Span, sym};
|
||||
use rustc_trait_selection::infer::InferCtxtExt;
|
||||
use rustc_trait_selection::traits::{FulfillmentError, Obligation, ObligationCtxt};
|
||||
use rustc_type_ir::TyKind::*;
|
||||
use tracing::debug;
|
||||
use {rustc_ast as ast, rustc_hir as hir};
|
||||
|
||||
|
@ -519,7 +518,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
{
|
||||
suggest_deref_binop(&mut err, lhs_deref_ty);
|
||||
} else if is_assign == IsAssign::No
|
||||
&& let Ref(region, lhs_deref_ty, mutbl) = lhs_ty.kind()
|
||||
&& let ty::Ref(region, lhs_deref_ty, mutbl) = lhs_ty.kind()
|
||||
{
|
||||
if self.type_is_copy_modulo_regions(self.param_env, *lhs_deref_ty) {
|
||||
suggest_deref_binop(&mut err, *lhs_deref_ty);
|
||||
|
@ -536,7 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
None,
|
||||
);
|
||||
|
||||
if let Ref(region, rhs_deref_ty, mutbl) = rhs_ty.kind() {
|
||||
if let ty::Ref(region, rhs_deref_ty, mutbl) = rhs_ty.kind() {
|
||||
let rhs_inv_mutbl = mutbl.invert();
|
||||
let rhs_inv_mutbl_ty =
|
||||
Ty::new_ref(self.tcx, *region, *rhs_deref_ty, rhs_inv_mutbl);
|
||||
|
@ -726,12 +725,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
|ty: Ty<'tcx>| ty.ty_adt_def().is_some_and(|ty_def| Some(ty_def.did()) == string_type);
|
||||
|
||||
match (lhs_ty.kind(), rhs_ty.kind()) {
|
||||
(&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str
|
||||
if (*l_ty.kind() == Str || is_std_string(l_ty))
|
||||
&& (*r_ty.kind() == Str
|
||||
(&ty::Ref(_, l_ty, _), &ty::Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str
|
||||
if (*l_ty.kind() == ty::Str || is_std_string(l_ty))
|
||||
&& (*r_ty.kind() == ty::Str
|
||||
|| is_std_string(r_ty)
|
||||
|| matches!(
|
||||
r_ty.kind(), Ref(_, inner_ty, _) if *inner_ty.kind() == Str
|
||||
r_ty.kind(), ty::Ref(_, inner_ty, _) if *inner_ty.kind() == ty::Str
|
||||
)) =>
|
||||
{
|
||||
if let IsAssign::No = is_assign { // Do not supply this message if `&str += &str`
|
||||
|
@ -755,8 +754,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
}
|
||||
true
|
||||
}
|
||||
(&Ref(_, l_ty, _), &Adt(..)) // Handle `&str` & `&String` + `String`
|
||||
if (*l_ty.kind() == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) =>
|
||||
(&ty::Ref(_, l_ty, _), &ty::Adt(..)) // Handle `&str` & `&String` + `String`
|
||||
if (*l_ty.kind() == ty::Str || is_std_string(l_ty)) && is_std_string(rhs_ty) =>
|
||||
{
|
||||
err.span_label(
|
||||
op.span,
|
||||
|
@ -847,7 +846,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
|
||||
} else {
|
||||
match actual.kind() {
|
||||
Uint(_) if op == hir::UnOp::Neg => {
|
||||
ty::Uint(_) if op == hir::UnOp::Neg => {
|
||||
err.note("unsigned values cannot be negated");
|
||||
|
||||
if let hir::ExprKind::Unary(
|
||||
|
@ -881,8 +880,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
);
|
||||
}
|
||||
}
|
||||
Str | Never | Char | Tuple(_) | Array(_, _) => {}
|
||||
Ref(_, lty, _) if *lty.kind() == Str => {}
|
||||
ty::Str | ty::Never | ty::Char | ty::Tuple(_) | ty::Array(_, _) => {}
|
||||
ty::Ref(_, lty, _) if *lty.kind() == ty::Str => {}
|
||||
_ => {
|
||||
self.note_unmet_impls_on_type(&mut err, errors, true);
|
||||
}
|
||||
|
|
|
@ -23,7 +23,6 @@ rustc_session = { path = "../rustc_session" }
|
|||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
tracing = "0.1"
|
||||
unicode-security = "0.1.0"
|
||||
|
|
|
@ -2582,34 +2582,35 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
|||
) -> Option<InitError> {
|
||||
let ty = cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty).unwrap_or(ty);
|
||||
|
||||
use rustc_type_ir::TyKind::*;
|
||||
match ty.kind() {
|
||||
// Primitive types that don't like 0 as a value.
|
||||
Ref(..) => Some("references must be non-null".into()),
|
||||
Adt(..) if ty.is_box() => Some("`Box` must be non-null".into()),
|
||||
FnPtr(..) => Some("function pointers must be non-null".into()),
|
||||
Never => Some("the `!` type has no valid value".into()),
|
||||
RawPtr(ty, _) if matches!(ty.kind(), Dynamic(..)) =>
|
||||
ty::Ref(..) => Some("references must be non-null".into()),
|
||||
ty::Adt(..) if ty.is_box() => Some("`Box` must be non-null".into()),
|
||||
ty::FnPtr(..) => Some("function pointers must be non-null".into()),
|
||||
ty::Never => Some("the `!` type has no valid value".into()),
|
||||
ty::RawPtr(ty, _) if matches!(ty.kind(), ty::Dynamic(..)) =>
|
||||
// raw ptr to dyn Trait
|
||||
{
|
||||
Some("the vtable of a wide raw pointer must be non-null".into())
|
||||
}
|
||||
// Primitive types with other constraints.
|
||||
Bool if init == InitKind::Uninit => {
|
||||
ty::Bool if init == InitKind::Uninit => {
|
||||
Some("booleans must be either `true` or `false`".into())
|
||||
}
|
||||
Char if init == InitKind::Uninit => {
|
||||
ty::Char if init == InitKind::Uninit => {
|
||||
Some("characters must be a valid Unicode codepoint".into())
|
||||
}
|
||||
Int(_) | Uint(_) if init == InitKind::Uninit => {
|
||||
ty::Int(_) | ty::Uint(_) if init == InitKind::Uninit => {
|
||||
Some("integers must be initialized".into())
|
||||
}
|
||||
Float(_) if init == InitKind::Uninit => Some("floats must be initialized".into()),
|
||||
RawPtr(_, _) if init == InitKind::Uninit => {
|
||||
ty::Float(_) if init == InitKind::Uninit => {
|
||||
Some("floats must be initialized".into())
|
||||
}
|
||||
ty::RawPtr(_, _) if init == InitKind::Uninit => {
|
||||
Some("raw pointers must be initialized".into())
|
||||
}
|
||||
// Recurse and checks for some compound types. (but not unions)
|
||||
Adt(adt_def, args) if !adt_def.is_union() => {
|
||||
ty::Adt(adt_def, args) if !adt_def.is_union() => {
|
||||
// Handle structs.
|
||||
if adt_def.is_struct() {
|
||||
return variant_find_init_error(
|
||||
|
@ -2675,11 +2676,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
|
|||
// We couldn't find anything wrong here.
|
||||
None
|
||||
}
|
||||
Tuple(..) => {
|
||||
ty::Tuple(..) => {
|
||||
// Proceed recursively, check all fields.
|
||||
ty.tuple_fields().iter().find_map(|field| ty_find_init_error(cx, field, init))
|
||||
}
|
||||
Array(ty, len) => {
|
||||
ty::Array(ty, len) => {
|
||||
if matches!(len.try_to_target_usize(cx.tcx), Some(v) if v > 0) {
|
||||
// Array length known at array non-empty -- recurse.
|
||||
ty_find_init_error(cx, *ty, init)
|
||||
|
|
|
@ -270,14 +270,12 @@ fn structurally_same_type_impl<'tcx>(
|
|||
true
|
||||
} else {
|
||||
// Do a full, depth-first comparison between the two.
|
||||
use rustc_type_ir::TyKind::*;
|
||||
|
||||
let is_primitive_or_pointer =
|
||||
|ty: Ty<'tcx>| ty.is_primitive() || matches!(ty.kind(), RawPtr(..) | Ref(..));
|
||||
|ty: Ty<'tcx>| ty.is_primitive() || matches!(ty.kind(), ty::RawPtr(..) | ty::Ref(..));
|
||||
|
||||
ensure_sufficient_stack(|| {
|
||||
match (a.kind(), b.kind()) {
|
||||
(&Adt(a_def, a_gen_args), &Adt(b_def, b_gen_args)) => {
|
||||
(&ty::Adt(a_def, a_gen_args), &ty::Adt(b_def, b_gen_args)) => {
|
||||
// Only `repr(C)` types can be compared structurally.
|
||||
if !(a_def.repr().c() && b_def.repr().c()) {
|
||||
return false;
|
||||
|
@ -308,30 +306,30 @@ fn structurally_same_type_impl<'tcx>(
|
|||
},
|
||||
)
|
||||
}
|
||||
(Array(a_ty, a_len), Array(b_ty, b_len)) => {
|
||||
(ty::Array(a_ty, a_len), ty::Array(b_ty, b_len)) => {
|
||||
// For arrays, we also check the length.
|
||||
a_len == b_len
|
||||
&& structurally_same_type_impl(
|
||||
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
|
||||
)
|
||||
}
|
||||
(Slice(a_ty), Slice(b_ty)) => {
|
||||
(ty::Slice(a_ty), ty::Slice(b_ty)) => {
|
||||
structurally_same_type_impl(seen_types, tcx, typing_env, *a_ty, *b_ty, ckind)
|
||||
}
|
||||
(RawPtr(a_ty, a_mutbl), RawPtr(b_ty, b_mutbl)) => {
|
||||
(ty::RawPtr(a_ty, a_mutbl), ty::RawPtr(b_ty, b_mutbl)) => {
|
||||
a_mutbl == b_mutbl
|
||||
&& structurally_same_type_impl(
|
||||
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
|
||||
)
|
||||
}
|
||||
(Ref(_a_region, a_ty, a_mut), Ref(_b_region, b_ty, b_mut)) => {
|
||||
(ty::Ref(_a_region, a_ty, a_mut), ty::Ref(_b_region, b_ty, b_mut)) => {
|
||||
// For structural sameness, we don't need the region to be same.
|
||||
a_mut == b_mut
|
||||
&& structurally_same_type_impl(
|
||||
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind,
|
||||
)
|
||||
}
|
||||
(FnDef(..), FnDef(..)) => {
|
||||
(ty::FnDef(..), ty::FnDef(..)) => {
|
||||
let a_poly_sig = a.fn_sig(tcx);
|
||||
let b_poly_sig = b.fn_sig(tcx);
|
||||
|
||||
|
@ -354,35 +352,38 @@ fn structurally_same_type_impl<'tcx>(
|
|||
ckind,
|
||||
)
|
||||
}
|
||||
(Tuple(..), Tuple(..)) => {
|
||||
(ty::Tuple(..), ty::Tuple(..)) => {
|
||||
// Tuples are not `repr(C)` so these cannot be compared structurally.
|
||||
false
|
||||
}
|
||||
// For these, it's not quite as easy to define structural-sameness quite so easily.
|
||||
// For the purposes of this lint, take the conservative approach and mark them as
|
||||
// not structurally same.
|
||||
(Dynamic(..), Dynamic(..))
|
||||
| (Error(..), Error(..))
|
||||
| (Closure(..), Closure(..))
|
||||
| (Coroutine(..), Coroutine(..))
|
||||
| (CoroutineWitness(..), CoroutineWitness(..))
|
||||
| (Alias(ty::Projection, ..), Alias(ty::Projection, ..))
|
||||
| (Alias(ty::Inherent, ..), Alias(ty::Inherent, ..))
|
||||
| (Alias(ty::Opaque, ..), Alias(ty::Opaque, ..)) => false,
|
||||
(ty::Dynamic(..), ty::Dynamic(..))
|
||||
| (ty::Error(..), ty::Error(..))
|
||||
| (ty::Closure(..), ty::Closure(..))
|
||||
| (ty::Coroutine(..), ty::Coroutine(..))
|
||||
| (ty::CoroutineWitness(..), ty::CoroutineWitness(..))
|
||||
| (ty::Alias(ty::Projection, ..), ty::Alias(ty::Projection, ..))
|
||||
| (ty::Alias(ty::Inherent, ..), ty::Alias(ty::Inherent, ..))
|
||||
| (ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => false,
|
||||
|
||||
// These definitely should have been caught above.
|
||||
(Bool, Bool) | (Char, Char) | (Never, Never) | (Str, Str) => unreachable!(),
|
||||
(ty::Bool, ty::Bool)
|
||||
| (ty::Char, ty::Char)
|
||||
| (ty::Never, ty::Never)
|
||||
| (ty::Str, ty::Str) => unreachable!(),
|
||||
|
||||
// An Adt and a primitive or pointer type. This can be FFI-safe if non-null
|
||||
// enum layout optimisation is being applied.
|
||||
(Adt(..) | Pat(..), _) if is_primitive_or_pointer(b) => {
|
||||
(ty::Adt(..) | ty::Pat(..), _) if is_primitive_or_pointer(b) => {
|
||||
if let Some(a_inner) = types::repr_nullable_ptr(tcx, typing_env, a, ckind) {
|
||||
a_inner == b
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(_, Adt(..) | Pat(..)) if is_primitive_or_pointer(a) => {
|
||||
(_, ty::Adt(..) | ty::Pat(..)) if is_primitive_or_pointer(a) => {
|
||||
if let Some(b_inner) = types::repr_nullable_ptr(tcx, typing_env, b, ckind) {
|
||||
b_inner == a
|
||||
} else {
|
||||
|
|
|
@ -506,9 +506,9 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for FunctionalVariances<'tcx> {
|
|||
self.tcx
|
||||
}
|
||||
|
||||
fn relate_with_variance<T: ty::relate::Relate<TyCtxt<'tcx>>>(
|
||||
fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
|
||||
&mut self,
|
||||
variance: rustc_type_ir::Variance,
|
||||
variance: ty::Variance,
|
||||
_: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
|
||||
a: T,
|
||||
b: T,
|
||||
|
|
|
@ -27,7 +27,6 @@ rustc_serialize = { path = "../rustc_serialize" }
|
|||
rustc_session = { path = "../rustc_session" }
|
||||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
tempfile = "3.2"
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -26,7 +26,6 @@ rustc_session = { path = "../rustc_session" }
|
|||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -2,7 +2,7 @@ use std::cell::RefCell;
|
|||
use std::collections::hash_map;
|
||||
use std::rc::Rc;
|
||||
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
|
||||
use rustc_data_structures::fx::{FxHashMap, FxHashSet, FxIndexMap};
|
||||
use rustc_data_structures::unord::{UnordMap, UnordSet};
|
||||
use rustc_errors::Subdiagnostic;
|
||||
use rustc_hir::CRATE_HIR_ID;
|
||||
|
@ -25,7 +25,6 @@ use rustc_mir_dataflow::{Analysis, MaybeReachable, ResultsCursor};
|
|||
use rustc_session::lint::builtin::TAIL_EXPR_DROP_ORDER;
|
||||
use rustc_session::lint::{self};
|
||||
use rustc_span::{DUMMY_SP, Span, Symbol};
|
||||
use rustc_type_ir::data_structures::IndexMap;
|
||||
use tracing::debug;
|
||||
|
||||
fn place_has_common_prefix<'tcx>(left: &Place<'tcx>, right: &Place<'tcx>) -> bool {
|
||||
|
@ -199,7 +198,7 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
|
|||
// and, for each block, the vector of locations.
|
||||
//
|
||||
// We group them per-block because they tend to scheduled in the same drop ladder block.
|
||||
let mut bid_per_block = IndexMap::default();
|
||||
let mut bid_per_block = FxIndexMap::default();
|
||||
let mut bid_places = UnordSet::new();
|
||||
|
||||
let mut ty_dropped_components = UnordMap::default();
|
||||
|
@ -455,8 +454,8 @@ pub(crate) fn run_lint<'tcx>(tcx: TyCtxt<'tcx>, def_id: LocalDefId, body: &Body<
|
|||
}
|
||||
|
||||
/// Extract binding names if available for diagnosis
|
||||
fn collect_user_names(body: &Body<'_>) -> IndexMap<Local, Symbol> {
|
||||
let mut names = IndexMap::default();
|
||||
fn collect_user_names(body: &Body<'_>) -> FxIndexMap<Local, Symbol> {
|
||||
let mut names = FxIndexMap::default();
|
||||
for var_debug_info in &body.var_debug_info {
|
||||
if let mir::VarDebugInfoContents::Place(place) = &var_debug_info.value
|
||||
&& let Some(local) = place.local_or_deref_local()
|
||||
|
@ -470,9 +469,9 @@ fn collect_user_names(body: &Body<'_>) -> IndexMap<Local, Symbol> {
|
|||
/// Assign names for anonymous or temporary values for diagnosis
|
||||
fn assign_observables_names(
|
||||
locals: impl IntoIterator<Item = Local>,
|
||||
user_names: &IndexMap<Local, Symbol>,
|
||||
) -> IndexMap<Local, (String, bool)> {
|
||||
let mut names = IndexMap::default();
|
||||
user_names: &FxIndexMap<Local, Symbol>,
|
||||
) -> FxIndexMap<Local, (String, bool)> {
|
||||
let mut names = FxIndexMap::default();
|
||||
let mut assigned_names = FxHashSet::default();
|
||||
let mut idx = 0u64;
|
||||
let mut fresh_name = || {
|
||||
|
|
|
@ -5,7 +5,6 @@ use rustc_index::IndexSlice;
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::layout::{IntegerExt, TyAndLayout};
|
||||
use rustc_middle::ty::{self, ScalarInt, Ty, TyCtxt};
|
||||
use rustc_type_ir::TyKind::*;
|
||||
use tracing::instrument;
|
||||
|
||||
use super::simplify::simplify_cfg;
|
||||
|
@ -293,13 +292,13 @@ fn can_cast(
|
|||
) -> bool {
|
||||
let from_scalar = ScalarInt::try_from_uint(src_val.into(), src_layout.size).unwrap();
|
||||
let v = match src_layout.ty.kind() {
|
||||
Uint(_) => from_scalar.to_uint(src_layout.size),
|
||||
Int(_) => from_scalar.to_int(src_layout.size) as u128,
|
||||
ty::Uint(_) => from_scalar.to_uint(src_layout.size),
|
||||
ty::Int(_) => from_scalar.to_int(src_layout.size) as u128,
|
||||
_ => unreachable!("invalid int"),
|
||||
};
|
||||
let size = match *cast_ty.kind() {
|
||||
Int(t) => Integer::from_int_ty(&tcx, t).size(),
|
||||
Uint(t) => Integer::from_uint_ty(&tcx, t).size(),
|
||||
ty::Int(t) => Integer::from_int_ty(&tcx, t).size(),
|
||||
ty::Uint(t) => Integer::from_uint_ty(&tcx, t).size(),
|
||||
_ => unreachable!("invalid int"),
|
||||
};
|
||||
let v = size.truncate(v);
|
||||
|
|
|
@ -13,11 +13,10 @@ use rustc_middle::mir::visit::{NonUseContext, PlaceContext, Visitor};
|
|||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::adjustment::PointerCoercion;
|
||||
use rustc_middle::ty::{
|
||||
self, CoroutineArgsExt, InstanceKind, ScalarInt, Ty, TyCtxt, TypeVisitableExt, Variance,
|
||||
self, CoroutineArgsExt, InstanceKind, ScalarInt, Ty, TyCtxt, TypeVisitableExt, Upcast, Variance,
|
||||
};
|
||||
use rustc_middle::{bug, span_bug};
|
||||
use rustc_trait_selection::traits::ObligationCtxt;
|
||||
use rustc_type_ir::Upcast;
|
||||
|
||||
use crate::util::{self, is_within_packed};
|
||||
|
||||
|
|
|
@ -21,6 +21,5 @@ rustc_session = { path = "../rustc_session" }
|
|||
rustc_span = { path = "../rustc_span" }
|
||||
rustc_target = { path = "../rustc_target" }
|
||||
rustc_trait_selection = { path = "../rustc_trait_selection" }
|
||||
rustc_type_ir = { path = "../rustc_type_ir" }
|
||||
tracing = "0.1"
|
||||
# tidy-alphabetical-end
|
||||
|
|
|
@ -7,11 +7,10 @@ use rustc_middle::query::Providers;
|
|||
use rustc_middle::traits::{BuiltinImplSource, CodegenObligationError};
|
||||
use rustc_middle::ty::util::AsyncDropGlueMorphology;
|
||||
use rustc_middle::ty::{
|
||||
self, GenericArgsRef, Instance, PseudoCanonicalInput, TyCtxt, TypeVisitableExt,
|
||||
self, ClosureKind, GenericArgsRef, Instance, PseudoCanonicalInput, TyCtxt, TypeVisitableExt,
|
||||
};
|
||||
use rustc_span::sym;
|
||||
use rustc_trait_selection::traits;
|
||||
use rustc_type_ir::ClosureKind;
|
||||
use tracing::debug;
|
||||
use traits::translate_args;
|
||||
|
||||
|
|
|
@ -4,9 +4,8 @@
|
|||
use rustc_hir::def::DefKind;
|
||||
use rustc_hir::def_id::LocalDefId;
|
||||
use rustc_middle::span_bug;
|
||||
use rustc_middle::ty::{self, TyCtxt, VisitorResult, try_visit};
|
||||
use rustc_middle::ty::{self, TyCtxt, TypeVisitable, VisitorResult, try_visit};
|
||||
use rustc_span::Span;
|
||||
use rustc_type_ir::TypeVisitable;
|
||||
use tracing::{instrument, trace};
|
||||
|
||||
pub trait SpannedTypeVisitor<'tcx> {
|
||||
|
|
|
@ -15,49 +15,49 @@ use tracing::instrument;
|
|||
|
||||
#[instrument(level = "debug", skip(tcx), ret)]
|
||||
fn sized_constraint_for_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
|
||||
use rustc_type_ir::TyKind::*;
|
||||
|
||||
match ty.kind() {
|
||||
// these are always sized
|
||||
Bool
|
||||
| Char
|
||||
| Int(..)
|
||||
| Uint(..)
|
||||
| Float(..)
|
||||
| RawPtr(..)
|
||||
| Ref(..)
|
||||
| FnDef(..)
|
||||
| FnPtr(..)
|
||||
| Array(..)
|
||||
| Closure(..)
|
||||
| CoroutineClosure(..)
|
||||
| Coroutine(..)
|
||||
| CoroutineWitness(..)
|
||||
| Never
|
||||
| Dynamic(_, _, ty::DynStar) => None,
|
||||
ty::Bool
|
||||
| ty::Char
|
||||
| ty::Int(..)
|
||||
| ty::Uint(..)
|
||||
| ty::Float(..)
|
||||
| ty::RawPtr(..)
|
||||
| ty::Ref(..)
|
||||
| ty::FnDef(..)
|
||||
| ty::FnPtr(..)
|
||||
| ty::Array(..)
|
||||
| ty::Closure(..)
|
||||
| ty::CoroutineClosure(..)
|
||||
| ty::Coroutine(..)
|
||||
| ty::CoroutineWitness(..)
|
||||
| ty::Never
|
||||
| ty::Dynamic(_, _, ty::DynStar) => None,
|
||||
|
||||
// these are never sized
|
||||
Str | Slice(..) | Dynamic(_, _, ty::Dyn) | Foreign(..) => Some(ty),
|
||||
ty::Str | ty::Slice(..) | ty::Dynamic(_, _, ty::Dyn) | ty::Foreign(..) => Some(ty),
|
||||
|
||||
Pat(ty, _) => sized_constraint_for_ty(tcx, *ty),
|
||||
ty::Pat(ty, _) => sized_constraint_for_ty(tcx, *ty),
|
||||
|
||||
Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)),
|
||||
ty::Tuple(tys) => tys.last().and_then(|&ty| sized_constraint_for_ty(tcx, ty)),
|
||||
|
||||
// recursive case
|
||||
Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| {
|
||||
ty::Adt(adt, args) => adt.sized_constraint(tcx).and_then(|intermediate| {
|
||||
let ty = intermediate.instantiate(tcx, args);
|
||||
sized_constraint_for_ty(tcx, ty)
|
||||
}),
|
||||
|
||||
// these can be sized or unsized.
|
||||
Param(..) | Alias(..) | Error(_) => Some(ty),
|
||||
ty::Param(..) | ty::Alias(..) | ty::Error(_) => Some(ty),
|
||||
|
||||
// We cannot instantiate the binder, so just return the *original* type back,
|
||||
// but only if the inner type has a sized constraint. Thus we skip the binder,
|
||||
// but don't actually use the result from `sized_constraint_for_ty`.
|
||||
UnsafeBinder(inner_ty) => sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty),
|
||||
ty::UnsafeBinder(inner_ty) => {
|
||||
sized_constraint_for_ty(tcx, inner_ty.skip_binder()).map(|_| ty)
|
||||
}
|
||||
|
||||
Placeholder(..) | Bound(..) | Infer(..) => {
|
||||
ty::Placeholder(..) | ty::Bound(..) | ty::Infer(..) => {
|
||||
bug!("unexpected type `{ty:?}` in sized_constraint_for_ty")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue