Auto merge of #138464 - compiler-errors:less-type-ir, r=lcnr

Use `rustc_type_ir` directly less in the codebase

cc https://github.com/rust-lang/rust/issues/138449

This is a somewhat opinionated bundle of changes that will make working on https://github.com/rust-lang/rust/issues/138449 more easy, since it cuts out the bulk of the changes that would be necessitated by the lint. Namely:

1. Fold `rustc_middle::ty::fold` and `rustc_middle::ty::visit` into `rustc_middle::ty`. This is because we already reexport some parts of these modules into `rustc_middle::ty`, and there's really no benefit from namespacing away the rest of these modules's functionality given how important folding and visiting is to the type layer.
2. Rename `{Decodable,Encodable}_Generic` to `{Decodable,Encodable}_NoContext`[^why], change it to be "perfect derive" (`synstructure::AddBounds::Fields`), use it throughout `rustc_type_ir` instead of `TyEncodable`/`TyDecodable`.
3. Make `TyEncodable` and `TyDecodable` derives use `::rustc_middle::ty::codec::TyEncoder` (etc) for its generated paths, and move the `rustc_type_ir::codec` module back to `rustc_middle::ty::codec` 🎉.
4. Stop using `rustc_type_ir` in crates that aren't "fundamental" to the type system, namely middle/infer/trait-selection. This amounted mostly to changing imports from `use rustc_type_ir::...` to `use rustc_middle::ty::...`, but also this means that we can't glob import `TyKind::*` since the reexport into `rustc_middle::ty::TyKind` is a type alias. Instead, use the prefixed variants like `ty::Str` everywhere -- IMO this is a good change, since it makes it more regularized with most of the rest of the compiler.

[^why]: `_NoContext` is the name for derive macros with no additional generic bounds and which do "perfect derive" by generating bounds based on field types. See `HashStable_NoContext`.

I'm happy to cut out some of these changes into separate PRs to make landing it a bit easier, though I don't expect to have much trouble with bitrot.

r? lcnr
This commit is contained in:
bors 2025-03-15 08:36:38 +00:00
commit aa95b9648a
160 changed files with 748 additions and 695 deletions

View File

@ -3440,7 +3440,6 @@ dependencies = [
"rustc_symbol_mangling", "rustc_symbol_mangling",
"rustc_target", "rustc_target",
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir",
"serde_json", "serde_json",
"smallvec", "smallvec",
"tempfile", "tempfile",
@ -3473,7 +3472,6 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir",
"tracing", "tracing",
] ]
@ -3736,7 +3734,6 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir",
"smallvec", "smallvec",
"tracing", "tracing",
] ]
@ -3775,7 +3772,6 @@ dependencies = [
"rustc_session", "rustc_session",
"rustc_span", "rustc_span",
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir",
"smallvec", "smallvec",
"tracing", "tracing",
] ]
@ -3922,7 +3918,6 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir",
"smallvec", "smallvec",
"tracing", "tracing",
"unicode-security", "unicode-security",
@ -3998,7 +3993,6 @@ dependencies = [
"rustc_session", "rustc_session",
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"rustc_type_ir",
"tempfile", "tempfile",
"tracing", "tracing",
] ]
@ -4114,7 +4108,6 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir",
"smallvec", "smallvec",
"tracing", "tracing",
] ]
@ -4538,7 +4531,6 @@ dependencies = [
"rustc_span", "rustc_span",
"rustc_target", "rustc_target",
"rustc_trait_selection", "rustc_trait_selection",
"rustc_type_ir",
"tracing", "tracing",
] ]

View File

@ -52,7 +52,7 @@ use rustc_data_structures::stable_hasher::StableOrd;
use rustc_hashes::Hash64; use rustc_hashes::Hash64;
use rustc_index::{Idx, IndexSlice, IndexVec}; use rustc_index::{Idx, IndexSlice, IndexVec};
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use rustc_macros::{Decodable_Generic, Encodable_Generic, HashStable_Generic}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_Generic};
mod callconv; mod callconv;
mod layout; mod layout;
@ -74,7 +74,10 @@ pub use layout::{LayoutCalculator, LayoutCalculatorError};
pub trait HashStableContext {} pub trait HashStableContext {}
#[derive(Clone, Copy, PartialEq, Eq, Default)] #[derive(Clone, Copy, PartialEq, Eq, Default)]
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
)]
pub struct ReprFlags(u8); pub struct ReprFlags(u8);
bitflags! { bitflags! {
@ -106,7 +109,10 @@ impl std::fmt::Debug for ReprFlags {
} }
#[derive(Copy, Clone, Debug, Eq, PartialEq)] #[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
)]
pub enum IntegerType { pub enum IntegerType {
/// Pointer-sized integer type, i.e. `isize` and `usize`. The field shows signedness, e.g. /// Pointer-sized integer type, i.e. `isize` and `usize`. The field shows signedness, e.g.
/// `Pointer(true)` means `isize`. /// `Pointer(true)` means `isize`.
@ -127,7 +133,10 @@ impl IntegerType {
/// Represents the repr options provided by the user. /// Represents the repr options provided by the user.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Default)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
)]
pub struct ReprOptions { pub struct ReprOptions {
pub int: Option<IntegerType>, pub int: Option<IntegerType>,
pub align: Option<Align>, pub align: Option<Align>,
@ -487,7 +496,10 @@ impl FromStr for Endian {
/// Size of a type in bytes. /// Size of a type in bytes.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
)]
pub struct Size { pub struct Size {
raw: u64, raw: u64,
} }
@ -713,7 +725,10 @@ impl Step for Size {
/// Alignment of a type in bytes (always a power of two). /// Alignment of a type in bytes (always a power of two).
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
)]
pub struct Align { pub struct Align {
pow2: u8, pow2: u8,
} }
@ -872,7 +887,10 @@ impl AbiAndPrefAlign {
/// Integers, also used for enum discriminants. /// Integers, also used for enum discriminants.
#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)]
#[cfg_attr(feature = "nightly", derive(Encodable_Generic, Decodable_Generic, HashStable_Generic))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_Generic)
)]
pub enum Integer { pub enum Integer {
I8, I8,
I16, I16,

View File

@ -12,14 +12,17 @@
// tidy-alphabetical-end // tidy-alphabetical-end
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use rustc_macros::{Decodable, Encodable, HashStable_NoContext}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable_NoContext};
pub mod visit; pub mod visit;
/// The movability of a coroutine / closure literal: /// The movability of a coroutine / closure literal:
/// whether a coroutine contains self-references, causing it to be `!Unpin`. /// whether a coroutine contains self-references, causing it to be `!Unpin`.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
pub enum Movability { pub enum Movability {
/// May contain self-references, `!Unpin`. /// May contain self-references, `!Unpin`.
Static, Static,
@ -28,7 +31,10 @@ pub enum Movability {
} }
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
pub enum Mutability { pub enum Mutability {
// N.B. Order is deliberate, so that Not < Mut // N.B. Order is deliberate, so that Not < Mut
Not, Not,
@ -87,7 +93,10 @@ impl Mutability {
} }
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Debug, Copy)]
#[cfg_attr(feature = "nightly", derive(Encodable, Decodable, HashStable_NoContext))] #[cfg_attr(
feature = "nightly",
derive(Encodable_NoContext, Decodable_NoContext, HashStable_NoContext)
)]
pub enum Pinnedness { pub enum Pinnedness {
Not, Not,
Pinned, Pinned,

View File

@ -14,9 +14,8 @@ use rustc_infer::infer::{NllRegionVariableOrigin, RelateParamBound};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::hir::place::PlaceBase; use rustc_middle::hir::place::PlaceBase;
use rustc_middle::mir::{AnnotationSource, ConstraintCategory, ReturnConstraint}; use rustc_middle::mir::{AnnotationSource, ConstraintCategory, ReturnConstraint};
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitor, self, GenericArgs, Region, RegionVid, Ty, TyCtxt, TypeFoldable, TypeVisitor, fold_regions,
}; };
use rustc_span::{Ident, Span, kw}; use rustc_span::{Ident, Span, kw};
use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::error_reporting::InferCtxtErrorExt;

View File

@ -35,8 +35,7 @@ use rustc_infer::infer::{
}; };
use rustc_middle::mir::*; use rustc_middle::mir::*;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::fold::fold_regions; use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode, fold_regions};
use rustc_middle::ty::{self, ParamEnv, RegionVid, TyCtxt, TypingMode};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_mir_dataflow::impls::{ use rustc_mir_dataflow::impls::{
EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces, EverInitializedPlaces, MaybeInitializedPlaces, MaybeUninitializedPlaces,

View File

@ -18,8 +18,7 @@ use rustc_middle::mir::{
ReturnConstraint, TerminatorKind, ReturnConstraint, TerminatorKind,
}; };
use rustc_middle::traits::{ObligationCause, ObligationCauseCode}; use rustc_middle::traits::{ObligationCause, ObligationCauseCode};
use rustc_middle::ty::fold::fold_regions; use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex, fold_regions};
use rustc_middle::ty::{self, RegionVid, Ty, TyCtxt, TypeFoldable, UniverseIndex};
use rustc_mir_dataflow::points::DenseLocationMap; use rustc_mir_dataflow::points::DenseLocationMap;
use rustc_span::hygiene::DesugaringKind; use rustc_span::hygiene::DesugaringKind;
use rustc_span::{DUMMY_SP, Span}; use rustc_span::{DUMMY_SP, Span};

View File

@ -5,11 +5,9 @@ use rustc_hir::def_id::LocalDefId;
use rustc_infer::infer::outlives::env::OutlivesEnvironment; use rustc_infer::infer::outlives::env::OutlivesEnvironment;
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, TyCtxtInferExt as _}; use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, TyCtxtInferExt as _};
use rustc_macros::extension; use rustc_macros::extension;
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgKind, GenericArgs, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, self, GenericArgKind, GenericArgs, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable,
TypingMode, TypeVisitableExt, TypingMode, fold_regions,
}; };
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::regions::OutlivesEnvironmentBuildExt; use rustc_trait_selection::regions::OutlivesEnvironmentBuildExt;

View File

@ -2,8 +2,7 @@ use rustc_index::IndexSlice;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_middle::mir::visit::{MutVisitor, TyContext}; use rustc_middle::mir::visit::{MutVisitor, TyContext};
use rustc_middle::mir::{Body, ConstOperand, Location, Promoted}; use rustc_middle::mir::{Body, ConstOperand, Location, Promoted};
use rustc_middle::ty::fold::fold_regions; use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable, fold_regions};
use rustc_middle::ty::{self, GenericArgsRef, Ty, TyCtxt, TypeFoldable};
use rustc_span::Symbol; use rustc_span::Symbol;
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -7,8 +7,9 @@ use rustc_infer::infer::{self, InferCtxt, SubregionOrigin};
use rustc_infer::traits::query::type_op::DeeplyNormalize; use rustc_infer::traits::query::type_op::DeeplyNormalize;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory}; use rustc_middle::mir::{ClosureOutlivesSubject, ClosureRegionRequirements, ConstraintCategory};
use rustc_middle::ty::fold::fold_regions; use rustc_middle::ty::{
use rustc_middle::ty::{self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt}; self, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, fold_regions,
};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput}; use rustc_trait_selection::traits::query::type_op::{TypeOp, TypeOpOutput};
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -4,8 +4,7 @@ use rustc_middle::mir::visit::{TyContext, Visitor};
use rustc_middle::mir::{Body, Local, Location, SourceInfo}; use rustc_middle::mir::{Body, Local, Location, SourceInfo};
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::relate::Relate; use rustc_middle::ty::relate::Relate;
use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt, TypeVisitable};
use rustc_middle::ty::{GenericArgsRef, Region, RegionVid, Ty, TyCtxt};
use rustc_mir_dataflow::ResultsCursor; use rustc_mir_dataflow::ResultsCursor;
use rustc_mir_dataflow::impls::MaybeInitializedPlaces; use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
use rustc_mir_dataflow::move_paths::MoveData; use rustc_mir_dataflow::move_paths::MoveData;

View File

@ -24,12 +24,10 @@ use rustc_middle::mir::*;
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::ty::adjustment::PointerCoercion; use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::cast::CastTy; use rustc_middle::ty::cast::CastTy;
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt, self, Binder, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, CoroutineArgsExt,
Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt, UserArgs, Dynamic, GenericArgsRef, OpaqueHiddenType, OpaqueTypeKey, RegionVid, Ty, TyCtxt,
UserTypeAnnotationIndex, TypeVisitableExt, UserArgs, UserTypeAnnotationIndex, fold_regions,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_mir_dataflow::ResultsCursor; use rustc_mir_dataflow::ResultsCursor;

View File

@ -2,10 +2,9 @@ use std::iter;
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgKind, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeSuperVisitable, self, GenericArgKind, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeSuperVisitable,
TypeVisitable, TypeVisitableExt, TypeVisitor, TypeVisitable, TypeVisitableExt, TypeVisitor, fold_regions,
}; };
use tracing::{debug, trace}; use tracing::{debug, trace};

View File

@ -10,9 +10,8 @@ use rustc_middle::mir::ConstraintCategory;
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::traits::query::NoSolution; use rustc_middle::traits::query::NoSolution;
use rustc_middle::ty::fold::FnMutDelegate;
use rustc_middle::ty::relate::combine::{super_combine_consts, super_combine_tys}; use rustc_middle::ty::relate::combine::{super_combine_consts, super_combine_tys};
use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, FnMutDelegate, Ty, TyCtxt, TypeVisitableExt};
use rustc_span::{Span, Symbol, sym}; use rustc_span::{Span, Symbol, sym};
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -27,11 +27,10 @@ use rustc_hir::lang_items::LangItem;
use rustc_index::IndexVec; use rustc_index::IndexVec;
use rustc_infer::infer::NllRegionVariableOrigin; use rustc_infer::infer::NllRegionVariableOrigin;
use rustc_macros::extension; use rustc_macros::extension;
use rustc_middle::ty::fold::{TypeFoldable, fold_regions};
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty, self, GenericArgs, GenericArgsRef, InlineConstArgs, InlineConstArgsParts, RegionVid, Ty,
TyCtxt, TypeVisitableExt, TyCtxt, TypeFoldable, TypeVisitableExt, fold_regions,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::{ErrorGuaranteed, kw, sym}; use rustc_span::{ErrorGuaranteed, kw, sym};

View File

@ -40,7 +40,6 @@ rustc_span = { path = "../rustc_span" }
rustc_symbol_mangling = { path = "../rustc_symbol_mangling" } rustc_symbol_mangling = { path = "../rustc_symbol_mangling" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
serde_json = "1.0.59" serde_json = "1.0.59"
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tempfile = "3.2" tempfile = "3.2"

View File

@ -12,10 +12,9 @@ use rustc_errors::{
Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level, Diag, DiagArgValue, DiagCtxtHandle, Diagnostic, EmissionGuarantee, IntoDiagArg, Level,
}; };
use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic}; use rustc_macros::{Diagnostic, LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::LayoutError; use rustc_middle::ty::layout::LayoutError;
use rustc_middle::ty::{FloatTy, Ty};
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use rustc_type_ir::FloatTy;
use crate::assert_module_sources::CguReuse; use crate::assert_module_sources::CguReuse;
use crate::back::command::Command; use crate::back::command::Command;

View File

@ -43,7 +43,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
mir::Const::Ty(_, c) => match c.kind() { mir::Const::Ty(_, c) => match c.kind() {
// A constant that came from a const generic but was then used as an argument to // 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). // 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:#?}"), other => span_bug!(constant.span, "{other:#?}"),
}, },
// We should never encounter `Const::Val` unless MIR opts (like const prop) evaluate // We should never encounter `Const::Val` unless MIR opts (like const prop) evaluate

View File

@ -23,6 +23,5 @@ rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
tracing = "0.1" tracing = "0.1"
# tidy-alphabetical-end # tidy-alphabetical-end

View File

@ -9,7 +9,6 @@ use rustc_middle::ty::adjustment::PointerCoercion;
use rustc_middle::ty::layout::{IntegerExt, LayoutOf, TyAndLayout}; use rustc_middle::ty::layout::{IntegerExt, LayoutOf, TyAndLayout};
use rustc_middle::ty::{self, FloatTy, Ty}; use rustc_middle::ty::{self, FloatTy, Ty};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_type_ir::TyKind::*;
use tracing::trace; use tracing::trace;
use super::util::ensure_monomorphic_enough; use super::util::ensure_monomorphic_enough;
@ -182,9 +181,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
src: &ImmTy<'tcx, M::Provenance>, src: &ImmTy<'tcx, M::Provenance>,
cast_to: TyAndLayout<'tcx>, cast_to: TyAndLayout<'tcx>,
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> { ) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
use rustc_type_ir::TyKind::*; let ty::Float(fty) = src.layout.ty.kind() else {
let Float(fty) = src.layout.ty.kind() else {
bug!("FloatToFloat/FloatToInt cast: source type {} is not a float type", src.layout.ty) bug!("FloatToFloat/FloatToInt cast: source type {} is not a float type", src.layout.ty)
}; };
let val = match fty { 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 signed = src_layout.backend_repr.is_signed(); // Also asserts that abi is `Scalar`.
let v = match src_layout.ty.kind() { let v = match src_layout.ty.kind() {
Uint(_) | RawPtr(..) | FnPtr(..) => scalar.to_uint(src_layout.size)?, ty::Uint(_) | ty::RawPtr(..) | ty::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 ty::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(), ty::Bool => scalar.to_bool()?.into(),
Char => scalar.to_char()?.into(), ty::Char => scalar.to_char()?.into(),
_ => span_bug!(self.cur_span(), "invalid int-like cast from {}", src_layout.ty), _ => span_bug!(self.cur_span(), "invalid int-like cast from {}", src_layout.ty),
}; };
interp_ok(match *cast_ty.kind() { interp_ok(match *cast_ty.kind() {
// int -> int // int -> int
Int(_) | Uint(_) => { ty::Int(_) | ty::Uint(_) => {
let size = match *cast_ty.kind() { let size = match *cast_ty.kind() {
Int(t) => Integer::from_int_ty(self, t).size(), ty::Int(t) => Integer::from_int_ty(self, t).size(),
Uint(t) => Integer::from_uint_ty(self, t).size(), ty::Uint(t) => Integer::from_uint_ty(self, t).size(),
_ => bug!(), _ => bug!(),
}; };
let v = size.truncate(v); let v = size.truncate(v);
@ -297,7 +294,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
} }
// signed int -> float // signed int -> float
Float(fty) if signed => { ty::Float(fty) if signed => {
let v = v as i128; let v = v as i128;
match fty { match fty {
FloatTy::F16 => Scalar::from_f16(Half::from_i128(v).value), 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 // unsigned int -> float
Float(fty) => match fty { ty::Float(fty) => match fty {
FloatTy::F16 => Scalar::from_f16(Half::from_u128(v).value), FloatTy::F16 => Scalar::from_f16(Half::from_u128(v).value),
FloatTy::F32 => Scalar::from_f32(Single::from_u128(v).value), FloatTy::F32 => Scalar::from_f32(Single::from_u128(v).value),
FloatTy::F64 => Scalar::from_f64(Double::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 // 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. // 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), _ => 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<Double>
+ FloatConvert<Quad>, + FloatConvert<Quad>,
{ {
use rustc_type_ir::TyKind::*;
match *dest_ty.kind() { match *dest_ty.kind() {
// float -> uint // float -> uint
Uint(t) => { ty::Uint(t) => {
let size = Integer::from_uint_ty(self, t).size(); let size = Integer::from_uint_ty(self, t).size();
// `to_u128` is a saturating cast, which is what we need // `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). // (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) Scalar::from_uint(v, size)
} }
// float -> int // float -> int
Int(t) => { ty::Int(t) => {
let size = Integer::from_int_ty(self, t).size(); let size = Integer::from_int_ty(self, t).size();
// `to_i128` is a saturating cast, which is what we need // `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). // (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) Scalar::from_int(v, size)
} }
// float -> float // float -> float
Float(fty) => match fty { ty::Float(fty) => match fty {
FloatTy::F16 => { FloatTy::F16 => {
Scalar::from_f16(self.adjust_nan(f.convert(&mut false).value, &[f])) Scalar::from_f16(self.adjust_nan(f.convert(&mut false).value, &[f]))
} }

View File

@ -4,7 +4,7 @@ use std::fmt::Debug;
use std::mem; use std::mem;
use std::ops::{Bound, Index, IndexMut, RangeBounds}; use std::ops::{Bound, Index, IndexMut, RangeBounds};
use rustc_macros::{Decodable_Generic, Encodable_Generic}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use crate::stable_hasher::{HashStable, StableHasher, StableOrd}; use crate::stable_hasher::{HashStable, StableHasher, StableOrd};
@ -20,7 +20,7 @@ pub use index_map::SortedIndexMultiMap;
/// stores data in a more compact way. It also supports accessing contiguous /// stores data in a more compact way. It also supports accessing contiguous
/// ranges of elements as a slice, and slices of already sorted elements can be /// ranges of elements as a slice, and slices of already sorted elements can be
/// inserted efficiently. /// inserted efficiently.
#[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable_Generic, Decodable_Generic)] #[derive(Clone, PartialEq, Eq, PartialOrd, Ord, Hash, Encodable_NoContext, Decodable_NoContext)]
pub struct SortedMap<K, V> { pub struct SortedMap<K, V> {
data: Vec<(K, V)>, data: Vec<(K, V)>,
} }

View File

@ -7,12 +7,12 @@
use std::fmt; use std::fmt;
use rustc_macros::{Decodable_Generic, Encodable_Generic}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use crate::fingerprint::Fingerprint; use crate::fingerprint::Fingerprint;
use crate::stable_hasher; use crate::stable_hasher;
#[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable_Generic, Decodable_Generic, Hash)] #[derive(Copy, Clone, PartialEq, Eq, Debug, Encodable_NoContext, Decodable_NoContext, Hash)]
pub struct Svh { pub struct Svh {
hash: Fingerprint, hash: Fingerprint,
} }

View File

@ -9,7 +9,7 @@ use std::iter::{Product, Sum};
use std::ops::Index; use std::ops::Index;
use rustc_hash::{FxHashMap, FxHashSet}; use rustc_hash::{FxHashMap, FxHashSet};
use rustc_macros::{Decodable_Generic, Encodable_Generic}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use crate::fingerprint::Fingerprint; use crate::fingerprint::Fingerprint;
use crate::stable_hasher::{HashStable, StableCompare, StableHasher, ToStableHashKey}; use crate::stable_hasher::{HashStable, StableCompare, StableHasher, ToStableHashKey};
@ -224,7 +224,7 @@ trait UnordCollection {}
/// ///
/// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533) /// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533)
/// for more information. /// for more information.
#[derive(Debug, Eq, PartialEq, Clone, Encodable_Generic, Decodable_Generic)] #[derive(Debug, Eq, PartialEq, Clone, Encodable_NoContext, Decodable_NoContext)]
pub struct UnordSet<V: Eq + Hash> { pub struct UnordSet<V: Eq + Hash> {
inner: FxHashSet<V>, inner: FxHashSet<V>,
} }
@ -415,7 +415,7 @@ impl<HCX, V: Hash + Eq + HashStable<HCX>> HashStable<HCX> for UnordSet<V> {
/// ///
/// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533) /// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533)
/// for more information. /// for more information.
#[derive(Debug, Eq, PartialEq, Clone, Encodable_Generic, Decodable_Generic)] #[derive(Debug, Eq, PartialEq, Clone, Encodable_NoContext, Decodable_NoContext)]
pub struct UnordMap<K: Eq + Hash, V> { pub struct UnordMap<K: Eq + Hash, V> {
inner: FxHashMap<K, V>, inner: FxHashMap<K, V>,
} }
@ -639,7 +639,7 @@ impl<HCX, K: Hash + Eq + HashStable<HCX>, V: HashStable<HCX>> HashStable<HCX> fo
/// ///
/// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533) /// See [MCP 533](https://github.com/rust-lang/compiler-team/issues/533)
/// for more information. /// for more information.
#[derive(Default, Debug, Eq, PartialEq, Clone, Encodable_Generic, Decodable_Generic)] #[derive(Default, Debug, Eq, PartialEq, Clone, Encodable_NoContext, Decodable_NoContext)]
pub struct UnordBag<V> { pub struct UnordBag<V> {
inner: Vec<V>, inner: Vec<V>,
} }

View File

@ -28,7 +28,6 @@ rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1" tracing = "0.1"
# tidy-alphabetical-end # tidy-alphabetical-end

View File

@ -18,18 +18,17 @@ use rustc_middle::hir::nested_filter;
use rustc_middle::middle::resolve_bound_vars::ResolvedArg; use rustc_middle::middle::resolve_bound_vars::ResolvedArg;
use rustc_middle::middle::stability::EvalResult; use rustc_middle::middle::stability::EvalResult;
use rustc_middle::ty::error::TypeErrorToStringExt; use rustc_middle::ty::error::TypeErrorToStringExt;
use rustc_middle::ty::fold::{BottomUpFolder, fold_regions};
use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES}; use rustc_middle::ty::layout::{LayoutError, MAX_SIMD_LANES};
use rustc_middle::ty::util::{Discr, IntTypeExt}; use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{ use rustc_middle::ty::{
AdtDef, GenericArgKind, RegionKind, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, AdtDef, BottomUpFolder, GenericArgKind, RegionKind, TypeFoldable, TypeSuperVisitable,
TypeVisitable, TypeVisitableExt, fold_regions,
}; };
use rustc_session::lint::builtin::UNINHABITED_STATIC; use rustc_session::lint::builtin::UNINHABITED_STATIC;
use rustc_trait_selection::error_reporting::InferCtxtErrorExt; use rustc_trait_selection::error_reporting::InferCtxtErrorExt;
use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective; use rustc_trait_selection::error_reporting::traits::on_unimplemented::OnUnimplementedDirective;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;
use rustc_type_ir::fold::TypeFoldable;
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use ty::TypingMode; use ty::TypingMode;
use {rustc_attr_parsing as attr, rustc_hir as hir}; use {rustc_attr_parsing as attr, rustc_hir as hir};
@ -1715,7 +1714,7 @@ fn opaque_type_cycle_error(tcx: TyCtxt<'_>, opaque_def_id: LocalDefId) -> ErrorG
opaques: Vec<DefId>, opaques: Vec<DefId>,
closures: Vec<DefId>, closures: Vec<DefId>,
} }
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector { impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for OpaqueTypeCollector {
fn visit_ty(&mut self, t: Ty<'tcx>) { fn visit_ty(&mut self, t: Ty<'tcx>) {
match *t.kind() { match *t.kind() {
ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => { ty::Alias(ty::Opaque, ty::AliasTy { def_id: def, .. }) => {

View File

@ -12,10 +12,9 @@ use rustc_hir::{self as hir, AmbigArg, GenericParamKind, ImplItemKind, intravisi
use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt}; use rustc_infer::infer::{self, InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::util; use rustc_infer::traits::util;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::util::ExplicitSelf; use rustc_middle::ty::util::ExplicitSelf;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeFolder, self, BottomUpFolder, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeFolder,
TypeSuperFoldable, TypeVisitableExt, TypingMode, Upcast, TypeSuperFoldable, TypeVisitableExt, TypingMode, Upcast,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};

View File

@ -16,10 +16,12 @@ use rustc_lint_defs::builtin::SUPERTRAIT_ITEM_SHADOWING_DEFINITION;
use rustc_macros::LintDiagnostic; use rustc_macros::LintDiagnostic;
use rustc_middle::mir::interpret::ErrorHandled; use rustc_middle::mir::interpret::ErrorHandled;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::traits::solve::NoSolution;
use rustc_middle::ty::trait_def::TraitSpecializationKind; use rustc_middle::ty::trait_def::TraitSpecializationKind;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags,
TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast, TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
Upcast,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_session::parse::feature_err; use rustc_session::parse::feature_err;
@ -34,8 +36,6 @@ use rustc_trait_selection::traits::{
self, FulfillmentError, Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt, self, FulfillmentError, Obligation, ObligationCause, ObligationCauseCode, ObligationCtxt,
WellFormedLoc, WellFormedLoc,
}; };
use rustc_type_ir::TypeFlags;
use rustc_type_ir::solve::NoSolution;
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use {rustc_ast as ast, rustc_hir as hir}; use {rustc_ast as ast, rustc_hir as hir};
@ -1520,7 +1520,7 @@ fn check_where_clauses<'tcx>(wfcx: &WfCheckingCtxt<'_, 'tcx>, span: Span, def_id
struct CountParams { struct CountParams {
params: FxHashSet<u32>, params: FxHashSet<u32>,
} }
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for CountParams { impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for CountParams {
type Result = ControlFlow<()>; type Result = ControlFlow<()>;
fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result { fn visit_ty(&mut self, t: Ty<'tcx>) -> Self::Result {
if let ty::Param(param) = t.kind() { if let ty::Param(param) = t.kind() {

View File

@ -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 // 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) // in the compiler (in particular, all the call ABI logic) will treat them as repr(transparent)
// even if they do not carry that attribute. // even if they do not carry that attribute.
use rustc_type_ir::TyKind::*;
match (source.kind(), target.kind()) { 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(()) Ok(())
} }
(&RawPtr(_, a_mutbl), &RawPtr(_, b_mutbl)) if a_mutbl == b_mutbl => Ok(()), (&ty::RawPtr(_, a_mutbl), &ty::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::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 { if def_a != def_b {
let source_path = tcx.def_path_str(def_a.did()); let source_path = tcx.def_path_str(def_a.did());
let target_path = tcx.def_path_str(def_b.did()); let target_path = tcx.def_path_str(def_b.did());

View File

@ -10,10 +10,9 @@ use rustc_errors::struct_span_code_err;
use rustc_hir::LangItem; use rustc_hir::LangItem;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::query::Providers; 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_session::parse::feature_err;
use rustc_span::{ErrorGuaranteed, sym}; use rustc_span::{ErrorGuaranteed, sym};
use rustc_type_ir::elaborate;
use tracing::debug; use tracing::debug;
use crate::check::always_applicable; use crate::check::always_applicable;

View File

@ -33,9 +33,8 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::ObligationCause; use rustc_infer::traits::ObligationCause;
use rustc_middle::hir::nested_filter; use rustc_middle::hir::nested_filter;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::util::{Discr, IntTypeExt}; use rustc_middle::ty::util::{Discr, IntTypeExt};
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypingMode}; use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypingMode, fold_regions};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName; use rustc_trait_selection::error_reporting::traits::suggestions::NextTypeParamName;

View File

@ -1,14 +1,13 @@
use rustc_data_structures::fx::{FxIndexMap, FxIndexSet}; use rustc_data_structures::fx::{FxIndexMap, FxIndexSet};
use rustc_hir as hir; use rustc_hir as hir;
use rustc_infer::traits::util; use rustc_infer::traits::util;
use rustc_middle::ty::fold::shift_vars;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, self, GenericArgs, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
Upcast, shift_vars,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::{DefId, LocalDefId}; use rustc_span::def_id::{DefId, LocalDefId};
use rustc_type_ir::Upcast;
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use super::ItemCtxt; use super::ItemCtxt;

View File

@ -5,10 +5,9 @@ use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_hir::intravisit::VisitorExt; use rustc_hir::intravisit::VisitorExt;
use rustc_hir::{self as hir, AmbigArg, HirId}; use rustc_hir::{self as hir, AmbigArg, HirId};
use rustc_middle::query::plumbing::CyclePlaceholder; use rustc_middle::query::plumbing::CyclePlaceholder;
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::print::with_forced_trimmed_paths; use rustc_middle::ty::print::with_forced_trimmed_paths;
use rustc_middle::ty::util::IntTypeExt; use rustc_middle::ty::util::IntTypeExt;
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt}; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt, fold_regions};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::{DUMMY_SP, Ident, Span}; use rustc_span::{DUMMY_SP, Ident, Span};

View File

@ -1,9 +1,7 @@
use rustc_data_structures::fx::FxHashSet; use rustc_data_structures::fx::FxHashSet;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitor}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperVisitable, TypeVisitor};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use rustc_type_ir::fold::TypeFoldable;
use tracing::debug; use tracing::debug;
#[derive(Clone, PartialEq, Eq, Hash, Debug)] #[derive(Clone, PartialEq, Eq, Hash, Debug)]

View File

@ -7,10 +7,10 @@ use std::assert_matches::debug_assert_matches;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def::DefKind; use rustc_hir::def::DefKind;
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{
use rustc_middle::ty::{self, Ty, TyCtxt}; self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
};
use rustc_span::{ErrorGuaranteed, Span}; use rustc_span::{ErrorGuaranteed, Span};
use rustc_type_ir::visit::TypeVisitableExt;
type RemapTable = FxHashMap<u32, u32>; type RemapTable = FxHashMap<u32, u32>;

View File

@ -8,10 +8,12 @@ use rustc_hir::HirId;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_hir::def_id::{DefId, LocalDefId};
use rustc_middle::bug; 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_span::{ErrorGuaranteed, Ident, Span, Symbol, kw, sym};
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
use rustc_type_ir::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor};
use smallvec::SmallVec; use smallvec::SmallVec;
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -4,15 +4,14 @@ use rustc_errors::struct_span_code_err;
use rustc_hir as hir; use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res}; use rustc_hir::def::{DefKind, Res};
use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS; use rustc_lint_defs::builtin::UNUSED_ASSOCIATED_TYPE_BOUNDS;
use rustc_middle::ty::fold::BottomUpFolder; use rustc_middle::ty::elaborate::ClauseWithSupertraitSpan;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, DynKind, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable, self, BottomUpFolder, DynKind, ExistentialPredicateStableCmpExt as _, Ty, TyCtxt, TypeFoldable,
TypeVisitableExt, Upcast, TypeVisitableExt, Upcast,
}; };
use rustc_span::{ErrorGuaranteed, Span}; use rustc_span::{ErrorGuaranteed, Span};
use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility; use rustc_trait_selection::error_reporting::traits::report_dyn_incompatibility;
use rustc_trait_selection::traits::{self, hir_ty_lowering_dyn_compatibility_violations}; use rustc_trait_selection::traits::{self, hir_ty_lowering_dyn_compatibility_violations};
use rustc_type_ir::elaborate::ClauseWithSupertraitSpan;
use smallvec::{SmallVec, smallvec}; use smallvec::{SmallVec, smallvec};
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -36,11 +36,10 @@ use rustc_infer::infer::{InferCtxt, TyCtxtInferExt};
use rustc_infer::traits::ObligationCause; use rustc_infer::traits::ObligationCause;
use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::middle::stability::AllowUnstable;
use rustc_middle::mir::interpret::LitToConstInput; use rustc_middle::mir::interpret::LitToConstInput;
use rustc_middle::ty::fold::fold_regions;
use rustc_middle::ty::print::PrintPolyTraitRefExt as _; use rustc_middle::ty::print::PrintPolyTraitRefExt as _;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, ParamEnv, Ty, TyCtxt, self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, ParamEnv, Ty, TyCtxt,
TypeVisitableExt, TypingMode, TypeVisitableExt, TypingMode, Upcast, fold_regions,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS; use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
@ -50,7 +49,6 @@ use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::wf::object_region_bounds; use rustc_trait_selection::traits::wf::object_region_bounds;
use rustc_trait_selection::traits::{self, ObligationCtxt}; use rustc_trait_selection::traits::{self, ObligationCtxt};
use rustc_type_ir::Upcast;
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use self::errors::assoc_kind_str; use self::errors::assoc_kind_str;

View File

@ -4,8 +4,7 @@ use rustc_infer::infer::TyCtxtInferExt;
use rustc_infer::traits::{ObligationCause, WellFormedLoc}; use rustc_infer::traits::{ObligationCause, WellFormedLoc};
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::query::Providers; use rustc_middle::query::Providers;
use rustc_middle::ty::fold::fold_regions; use rustc_middle::ty::{self, TyCtxt, TypingMode, fold_regions};
use rustc_middle::ty::{self, TyCtxt, TypingMode};
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_trait_selection::traits::{self, ObligationCtxt}; use rustc_trait_selection::traits::{self, ObligationCtxt};
use tracing::debug; use tracing::debug;

View File

@ -1,8 +1,8 @@
use rustc_data_structures::fx::FxIndexMap; 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::ty::{self, GenericArg, GenericArgKind, Region, Ty, TyCtxt};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::Span; use rustc_span::Span;
use rustc_type_ir::outlives::{Component, push_outlives_components};
use smallvec::smallvec; use smallvec::smallvec;
/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred /// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred

View File

@ -23,7 +23,6 @@ rustc_middle = { path = "../rustc_middle" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1" tracing = "0.1"
# tidy-alphabetical-end # tidy-alphabetical-end

View File

@ -40,13 +40,12 @@ use rustc_middle::mir::Mutability;
use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::cast::{CastKind, CastTy}; use rustc_middle::ty::cast::{CastKind, CastTy};
use rustc_middle::ty::error::TypeError; 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_middle::{bug, span_bug};
use rustc_session::lint; use rustc_session::lint;
use rustc_span::def_id::LOCAL_CRATE; use rustc_span::def_id::LOCAL_CRATE;
use rustc_span::{DUMMY_SP, Span, sym}; use rustc_span::{DUMMY_SP, Span, sym};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use rustc_type_ir::elaborate;
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use super::FnCtxt; use super::FnCtxt;

View File

@ -12,13 +12,14 @@ use rustc_infer::infer::{BoundRegionConversionTime, DefineOpaqueTypes, InferOk,
use rustc_infer::traits::{ObligationCauseCode, PredicateObligations}; use rustc_infer::traits::{ObligationCauseCode, PredicateObligations};
use rustc_macros::{TypeFoldable, TypeVisitable}; use rustc_macros::{TypeFoldable, TypeVisitable};
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt}; use rustc_middle::ty::{
use rustc_middle::ty::{self, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitor}; self, ClosureKind, GenericArgs, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable,
TypeVisitableExt, TypeVisitor,
};
use rustc_span::def_id::LocalDefId; use rustc_span::def_id::LocalDefId;
use rustc_span::{DUMMY_SP, Span}; use rustc_span::{DUMMY_SP, Span};
use rustc_trait_selection::error_reporting::traits::ArgKind; use rustc_trait_selection::error_reporting::traits::ArgKind;
use rustc_trait_selection::traits; use rustc_trait_selection::traits;
use rustc_type_ir::ClosureKind;
use tracing::{debug, instrument, trace}; use tracing::{debug, instrument, trace};
use super::{CoroutineTypes, Expectation, FnCtxt, check_fn}; use super::{CoroutineTypes, Expectation, FnCtxt, check_fn};

View File

@ -55,8 +55,7 @@ use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion, Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
}; };
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, AliasTy, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{self, AliasTy, GenericArgsRef, Ty, TyCtxt};
use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Span}; use rustc_span::{BytePos, DUMMY_SP, DesugaringKind, Span};
use rustc_trait_selection::infer::InferCtxtExt as _; use rustc_trait_selection::infer::InferCtxtExt as _;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;

View File

@ -6,9 +6,8 @@ use rustc_infer::infer::DefineOpaqueTypes;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::print::with_no_trimmed_paths; use rustc_middle::ty::print::with_no_trimmed_paths;
use rustc_middle::ty::{self, AssocItem, Ty, TypeFoldable, TypeVisitableExt}; use rustc_middle::ty::{self, AssocItem, BottomUpFolder, Ty, TypeFoldable, TypeVisitableExt};
use rustc_span::{DUMMY_SP, Ident, Span, sym}; use rustc_span::{DUMMY_SP, Ident, Span, sym};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::ObligationCause; use rustc_trait_selection::traits::ObligationCause;

View File

@ -21,11 +21,9 @@ use rustc_infer::infer::canonical::{Canonical, OriginalQueryValues, QueryRespons
use rustc_infer::infer::{DefineOpaqueTypes, InferResult}; use rustc_infer::infer::{DefineOpaqueTypes, InferResult};
use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM; use rustc_lint::builtin::SELF_CONSTRUCTOR_FROM_OUTER_ITEM;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, AutoBorrow, AutoBorrowMutability};
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitableExt};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AdtKind, CanonicalUserType, GenericArgKind, GenericArgsRef, GenericParamDefKind, self, AdtKind, CanonicalUserType, GenericArgKind, GenericArgsRef, GenericParamDefKind,
IsIdentity, Ty, TyCtxt, UserArgs, UserSelfTy, IsIdentity, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitableExt, UserArgs, UserSelfTy,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_session::lint; use rustc_session::lint;

View File

@ -15,8 +15,7 @@ use rustc_index::IndexVec;
use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TypeTrace}; use rustc_infer::infer::{DefineOpaqueTypes, InferOk, TypeTrace};
use rustc_middle::ty::adjustment::AllowTwoPhase; use rustc_middle::ty::adjustment::AllowTwoPhase;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt, TypeVisitableExt};
use rustc_middle::ty::{self, IsSuggestable, Ty, TyCtxt};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_session::Session; use rustc_session::Session;
use rustc_span::{DUMMY_SP, Ident, Span, kw, sym}; use rustc_span::{DUMMY_SP, Ident, Span, kw, sym};

View File

@ -1,13 +1,12 @@
//! A utility module to inspect currently ambiguous obligations in the current context. //! A utility module to inspect currently ambiguous obligations in the current context.
use rustc_infer::traits::{self, ObligationCause, PredicateObligations}; 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_middle::ty::{self, Ty, TypeVisitableExt};
use rustc_span::Span; use rustc_span::Span;
use rustc_trait_selection::solve::inspect::{ use rustc_trait_selection::solve::inspect::{
InspectConfig, InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor, InspectConfig, InspectGoal, ProofTreeInferCtxtExt, ProofTreeVisitor,
}; };
use rustc_type_ir::solve::GoalSource;
use tracing::{debug, instrument, trace}; use tracing::{debug, instrument, trace};
use crate::FnCtxt; use crate::FnCtxt;

View File

@ -15,9 +15,9 @@ use rustc_middle::traits::ObligationCauseCode;
use rustc_middle::ty::adjustment::{ use rustc_middle::ty::adjustment::{
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion, Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability, PointerCoercion,
}; };
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt, UserArgs, self, GenericArgs, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeFoldable,
TypeVisitableExt, UserArgs,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::{DUMMY_SP, Span}; use rustc_span::{DUMMY_SP, Span};

View File

@ -14,6 +14,7 @@ use rustc_infer::infer::{self, DefineOpaqueTypes, InferOk, TyCtxtInferExt};
use rustc_infer::traits::ObligationCauseCode; use rustc_infer::traits::ObligationCauseCode;
use rustc_middle::middle::stability; use rustc_middle::middle::stability;
use rustc_middle::query::Providers; 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::fast_reject::{TreatParams, simplify_type};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AssocItem, AssocItemContainer, GenericArgs, GenericArgsRef, GenericParamDefKind, self, AssocItem, AssocItemContainer, GenericArgs, GenericArgsRef, GenericParamDefKind,
@ -34,7 +35,6 @@ use rustc_trait_selection::traits::query::method_autoderef::{
CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult, CandidateStep, MethodAutoderefBadTy, MethodAutoderefStepsResult,
}; };
use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt}; use rustc_trait_selection::traits::{self, ObligationCause, ObligationCtxt};
use rustc_type_ir::elaborate::supertrait_def_ids;
use smallvec::{SmallVec, smallvec}; use smallvec::{SmallVec, smallvec};
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -15,7 +15,6 @@ use rustc_span::source_map::Spanned;
use rustc_span::{Ident, Span, sym}; use rustc_span::{Ident, Span, sym};
use rustc_trait_selection::infer::InferCtxtExt; use rustc_trait_selection::infer::InferCtxtExt;
use rustc_trait_selection::traits::{FulfillmentError, Obligation, ObligationCtxt}; use rustc_trait_selection::traits::{FulfillmentError, Obligation, ObligationCtxt};
use rustc_type_ir::TyKind::*;
use tracing::debug; use tracing::debug;
use {rustc_ast as ast, rustc_hir as hir}; 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); suggest_deref_binop(&mut err, lhs_deref_ty);
} else if is_assign == IsAssign::No } 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) { if self.type_is_copy_modulo_regions(self.param_env, *lhs_deref_ty) {
suggest_deref_binop(&mut err, *lhs_deref_ty); suggest_deref_binop(&mut err, *lhs_deref_ty);
@ -536,7 +535,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
None, 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 = mutbl.invert();
let rhs_inv_mutbl_ty = let rhs_inv_mutbl_ty =
Ty::new_ref(self.tcx, *region, *rhs_deref_ty, rhs_inv_mutbl); 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); |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()) { match (lhs_ty.kind(), rhs_ty.kind()) {
(&Ref(_, l_ty, _), &Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str (&ty::Ref(_, l_ty, _), &ty::Ref(_, r_ty, _)) // &str or &String + &str, &String or &&str
if (*l_ty.kind() == Str || is_std_string(l_ty)) if (*l_ty.kind() == ty::Str || is_std_string(l_ty))
&& (*r_ty.kind() == Str && (*r_ty.kind() == ty::Str
|| is_std_string(r_ty) || is_std_string(r_ty)
|| matches!( || 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` 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 true
} }
(&Ref(_, l_ty, _), &Adt(..)) // Handle `&str` & `&String` + `String` (&ty::Ref(_, l_ty, _), &ty::Adt(..)) // Handle `&str` & `&String` + `String`
if (*l_ty.kind() == Str || is_std_string(l_ty)) && is_std_string(rhs_ty) => if (*l_ty.kind() == ty::Str || is_std_string(l_ty)) && is_std_string(rhs_ty) =>
{ {
err.span_label( err.span_label(
op.span, op.span,
@ -847,7 +846,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp)); err.subdiagnostic(ExprParenthesesNeeded::surrounding(*sp));
} else { } else {
match actual.kind() { match actual.kind() {
Uint(_) if op == hir::UnOp::Neg => { ty::Uint(_) if op == hir::UnOp::Neg => {
err.note("unsigned values cannot be negated"); err.note("unsigned values cannot be negated");
if let hir::ExprKind::Unary( if let hir::ExprKind::Unary(
@ -881,8 +880,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
); );
} }
} }
Str | Never | Char | Tuple(_) | Array(_, _) => {} ty::Str | ty::Never | ty::Char | ty::Tuple(_) | ty::Array(_, _) => {}
Ref(_, lty, _) if *lty.kind() == Str => {} ty::Ref(_, lty, _) if *lty.kind() == ty::Str => {}
_ => { _ => {
self.note_unmet_impls_on_type(&mut err, errors, true); self.note_unmet_impls_on_type(&mut err, errors, true);
} }

View File

@ -7,8 +7,7 @@ use rustc_hir::def_id::LocalDefId;
use rustc_hir::{HirId, HirIdMap}; use rustc_hir::{HirId, HirIdMap};
use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt}; use rustc_infer::infer::{InferCtxt, InferOk, TyCtxtInferExt};
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::ty::visit::TypeVisitableExt; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitableExt, TypingMode};
use rustc_middle::ty::{self, Ty, TyCtxt, TypingMode};
use rustc_span::Span; use rustc_span::Span;
use rustc_span::def_id::LocalDefIdMap; use rustc_span::def_id::LocalDefIdMap;
use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt; use rustc_trait_selection::traits::query::evaluate_obligation::InferCtxtExt;

View File

@ -11,9 +11,9 @@ use rustc_hir::{self as hir, AmbigArg, HirId};
use rustc_middle::span_bug; use rustc_middle::span_bug;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion}; use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCoercion};
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, fold_regions}; use rustc_middle::ty::{
use rustc_middle::ty::visit::TypeVisitableExt; self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt, fold_regions,
use rustc_middle::ty::{self, Ty, TyCtxt, TypeSuperFoldable}; };
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};
use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded; use rustc_trait_selection::error_reporting::infer::need_type_info::TypeAnnotationNeeded;
use rustc_trait_selection::solve; use rustc_trait_selection::solve;

View File

@ -7,7 +7,7 @@ use std::{fmt, iter, slice};
use Chunk::*; use Chunk::*;
#[cfg(feature = "nightly")] #[cfg(feature = "nightly")]
use rustc_macros::{Decodable_Generic, Encodable_Generic}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext};
use smallvec::{SmallVec, smallvec}; use smallvec::{SmallVec, smallvec};
use crate::{Idx, IndexVec}; use crate::{Idx, IndexVec};
@ -114,7 +114,7 @@ macro_rules! bit_relations_inherent_impls {
/// to or greater than the domain size. All operations that involve two bitsets /// to or greater than the domain size. All operations that involve two bitsets
/// will panic if the bitsets have differing domain sizes. /// will panic if the bitsets have differing domain sizes.
/// ///
#[cfg_attr(feature = "nightly", derive(Decodable_Generic, Encodable_Generic))] #[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext))]
#[derive(Eq, PartialEq, Hash)] #[derive(Eq, PartialEq, Hash)]
pub struct DenseBitSet<T> { pub struct DenseBitSet<T> {
domain_size: usize, domain_size: usize,
@ -1392,7 +1392,7 @@ impl<T: Idx> From<DenseBitSet<T>> for GrowableBitSet<T> {
/// ///
/// All operations that involve a row and/or column index will panic if the /// All operations that involve a row and/or column index will panic if the
/// index exceeds the relevant bound. /// index exceeds the relevant bound.
#[cfg_attr(feature = "nightly", derive(Decodable_Generic, Encodable_Generic))] #[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext))]
#[derive(Clone, Eq, PartialEq, Hash)] #[derive(Clone, Eq, PartialEq, Hash)]
pub struct BitMatrix<R: Idx, C: Idx> { pub struct BitMatrix<R: Idx, C: Idx> {
num_rows: usize, num_rows: usize,
@ -1816,7 +1816,7 @@ impl std::fmt::Debug for FiniteBitSet<u32> {
/// A fixed-sized bitset type represented by an integer type. Indices outwith than the range /// A fixed-sized bitset type represented by an integer type. Indices outwith than the range
/// representable by `T` are considered set. /// representable by `T` are considered set.
#[cfg_attr(feature = "nightly", derive(Decodable_Generic, Encodable_Generic))] #[cfg_attr(feature = "nightly", derive(Decodable_NoContext, Encodable_NoContext))]
#[derive(Copy, Clone, Eq, PartialEq)] #[derive(Copy, Clone, Eq, PartialEq)]
pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T); pub struct FiniteBitSet<T: FiniteBitSetTy>(pub T);

View File

@ -8,9 +8,9 @@
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_index::Idx; use rustc_index::Idx;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, BoundVar, GenericArg, InferConst, List, Ty, TyCtxt, TypeFlags, TypeVisitableExt, self, BoundVar, GenericArg, InferConst, List, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeFolder,
TypeSuperFoldable, TypeVisitableExt,
}; };
use smallvec::SmallVec; use smallvec::SmallVec;
use tracing::debug; use tracing::debug;

View File

@ -8,8 +8,7 @@
use rustc_macros::extension; use rustc_macros::extension;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::fold::{FnMutDelegate, TypeFoldable}; use rustc_middle::ty::{self, FnMutDelegate, GenericArgKind, TyCtxt, TypeFoldable};
use rustc_middle::ty::{self, GenericArgKind, TyCtxt};
use crate::infer::canonical::{Canonical, CanonicalVarValues}; use crate::infer::canonical::{Canonical, CanonicalVarValues};

View File

@ -24,8 +24,7 @@
pub use instantiate::CanonicalExt; pub use instantiate::CanonicalExt;
use rustc_index::IndexVec; use rustc_index::IndexVec;
pub use rustc_middle::infer::canonical::*; pub use rustc_middle::infer::canonical::*;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, GenericArg, List, Ty, TyCtxt, TypeFoldable};
use rustc_middle::ty::{self, GenericArg, List, Ty, TyCtxt};
use rustc_span::Span; use rustc_span::Span;
use crate::infer::{InferCtxt, RegionVariableOrigin}; use crate::infer::{InferCtxt, RegionVariableOrigin};

View File

@ -13,8 +13,7 @@ use std::iter;
use rustc_index::{Idx, IndexVec}; use rustc_index::{Idx, IndexVec};
use rustc_middle::arena::ArenaAllocatable; use rustc_middle::arena::ArenaAllocatable;
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::{self, BoundVar, GenericArg, GenericArgKind, Ty, TyCtxt, TypeFoldable};
use rustc_middle::ty::{self, BoundVar, GenericArg, GenericArgKind, Ty, TyCtxt};
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -1,10 +1,9 @@
///! Definition of `InferCtxtLike` from the librarified type layer. ///! Definition of `InferCtxtLike` from the librarified type layer.
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::ty::fold::TypeFoldable;
use rustc_middle::ty::relate::RelateResult; use rustc_middle::ty::relate::RelateResult;
use rustc_middle::ty::relate::combine::PredicateEmittingRelation; use rustc_middle::ty::relate::combine::PredicateEmittingRelation;
use rustc_middle::ty::{self, Ty, TyCtxt}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span}; use rustc_span::{DUMMY_SP, ErrorGuaranteed, Span};
use super::{BoundRegionConversionTime, InferCtxt, RegionVariableOrigin, SubregionOrigin}; use super::{BoundRegionConversionTime, InferCtxt, RegionVariableOrigin, SubregionOrigin};

View File

@ -35,8 +35,9 @@ use std::collections::hash_map::Entry;
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::fold::TypeFolder; use rustc_middle::ty::{
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable, TypeSuperFoldable, TypeVisitableExt}; self, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
};
use super::InferCtxt; use super::InferCtxt;

View File

@ -9,10 +9,9 @@ use rustc_data_structures::graph::implementation::{
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_data_structures::unord::UnordSet; use rustc_data_structures::unord::UnordSet;
use rustc_index::{IndexSlice, IndexVec}; use rustc_index::{IndexSlice, IndexVec};
use rustc_middle::ty::fold::{TypeFoldable, fold_regions};
use rustc_middle::ty::{ use rustc_middle::ty::{
self, ReBound, ReEarlyParam, ReErased, ReError, ReLateParam, RePlaceholder, ReStatic, ReVar, self, ReBound, ReEarlyParam, ReErased, ReError, ReLateParam, RePlaceholder, ReStatic, ReVar,
Region, RegionVid, Ty, TyCtxt, Region, RegionVid, Ty, TyCtxt, TypeFoldable, fold_regions,
}; };
use rustc_middle::{bug, span_bug}; use rustc_middle::{bug, span_bug};
use rustc_span::Span; use rustc_span::Span;

View File

@ -28,14 +28,11 @@ use rustc_middle::infer::canonical::{CanonicalQueryInput, CanonicalVarValues};
use rustc_middle::mir::ConstraintCategory; use rustc_middle::mir::ConstraintCategory;
use rustc_middle::traits::select; use rustc_middle::traits::select;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::{
BoundVarReplacerDelegate, TypeFoldable, TypeFolder, TypeSuperFoldable, fold_regions,
};
use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, ConstVid, FloatVid, GenericArg, GenericArgKind, GenericArgs, GenericArgsRef, self, BoundVarReplacerDelegate, ConstVid, FloatVid, GenericArg, GenericArgKind, GenericArgs,
GenericParamDefKind, InferConst, IntVid, PseudoCanonicalInput, Ty, TyCtxt, TyVid, GenericArgsRef, GenericParamDefKind, InferConst, IntVid, PseudoCanonicalInput, Ty, TyCtxt,
TypeVisitable, TypingEnv, TypingMode, TyVid, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitable, TypeVisitableExt, TypingEnv,
TypingMode, fold_regions,
}; };
use rustc_span::{Span, Symbol}; use rustc_span::{Span, Symbol};
use snapshot::undo_log::InferCtxtUndoLogs; use snapshot::undo_log::InferCtxtUndoLogs;

View File

@ -5,9 +5,9 @@ use rustc_middle::bug;
use rustc_middle::traits::ObligationCause; use rustc_middle::traits::ObligationCause;
use rustc_middle::traits::solve::Goal; use rustc_middle::traits::solve::Goal;
use rustc_middle::ty::error::{ExpectedFound, TypeError}; use rustc_middle::ty::error::{ExpectedFound, TypeError};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable, TypeVisitableExt, self, BottomUpFolder, OpaqueHiddenType, OpaqueTypeKey, Ty, TyCtxt, TypeFoldable,
TypeVisitableExt,
}; };
use rustc_span::Span; use rustc_span::Span;
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -5,10 +5,9 @@ use rustc_data_structures::stack::ensure_sufficient_stack;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::error::TypeError; use rustc_middle::ty::error::TypeError;
use rustc_middle::ty::visit::MaxUniverse;
use rustc_middle::ty::{ use rustc_middle::ty::{
self, AliasRelationDirection, InferConst, Term, Ty, TyCtxt, TypeVisitable, TypeVisitableExt, self, AliasRelationDirection, InferConst, MaxUniverse, Term, Ty, TyCtxt, TypeVisitable,
TypingMode, TypeVisitableExt, TypingMode,
}; };
use rustc_span::Span; use rustc_span::Span;
use tracing::{debug, instrument, warn}; use tracing::{debug, instrument, warn};

View File

@ -1,9 +1,7 @@
//! Helper routines for higher-ranked things. See the `doc` module at //! Helper routines for higher-ranked things. See the `doc` module at
//! the end of the file for details. //! the end of the file for details.
use rustc_middle::ty::fold::FnMutDelegate; use rustc_middle::ty::{self, FnMutDelegate, Ty, TyCtxt, TypeFoldable, TypeVisitableExt};
use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use super::RelateResult; use super::RelateResult;

View File

@ -1,7 +1,8 @@
use rustc_middle::bug; use rustc_middle::bug;
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{
use rustc_middle::ty::visit::TypeVisitableExt; self, Const, FallibleTypeFolder, InferConst, Ty, TyCtxt, TypeFoldable, TypeFolder,
use rustc_middle::ty::{self, Const, InferConst, Ty, TyCtxt, TypeFoldable}; TypeSuperFoldable, TypeVisitableExt,
};
use rustc_type_ir::data_structures::DelayedMap; use rustc_type_ir::data_structures::DelayedMap;
use super::{FixupError, FixupResult, InferCtxt}; use super::{FixupError, FixupResult, InferCtxt};

View File

@ -1,9 +1,11 @@
use std::ops::Range; use std::ops::Range;
use rustc_data_structures::{snapshot_vec as sv, unify as ut}; use rustc_data_structures::{snapshot_vec as sv, unify as ut};
use rustc_middle::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use rustc_middle::ty::{
use rustc_middle::ty::{self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid}; self, ConstVid, FloatVid, IntVid, RegionVid, Ty, TyCtxt, TyVid, TypeFoldable, TypeFolder,
use rustc_type_ir::visit::TypeVisitableExt; TypeSuperFoldable,
};
use rustc_type_ir::TypeVisitableExt;
use tracing::instrument; use tracing::instrument;
use ut::UnifyKey; use ut::UnifyKey;

View File

@ -1,8 +1,8 @@
use std::fmt; use std::fmt;
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable}; use rustc_middle::ty::{
use rustc_middle::ty::visit::{TypeVisitable, TypeVisitor, try_visit}; self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitor, try_visit,
use rustc_middle::ty::{self, TyCtxt}; };
use crate::traits; use crate::traits;
use crate::traits::project::Normalized; use crate::traits::project::Normalized;

View File

@ -23,7 +23,6 @@ rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_trait_selection = { path = "../rustc_trait_selection" } rustc_trait_selection = { path = "../rustc_trait_selection" }
rustc_type_ir = { path = "../rustc_type_ir" }
smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } smallvec = { version = "1.8.1", features = ["union", "may_dangle"] }
tracing = "0.1" tracing = "0.1"
unicode-security = "0.1.0" unicode-security = "0.1.0"

View File

@ -2582,34 +2582,35 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
) -> Option<InitError> { ) -> Option<InitError> {
let ty = cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty).unwrap_or(ty); let ty = cx.tcx.try_normalize_erasing_regions(cx.typing_env(), ty).unwrap_or(ty);
use rustc_type_ir::TyKind::*;
match ty.kind() { match ty.kind() {
// Primitive types that don't like 0 as a value. // Primitive types that don't like 0 as a value.
Ref(..) => Some("references must be non-null".into()), ty::Ref(..) => Some("references must be non-null".into()),
Adt(..) if ty.is_box() => Some("`Box` must be non-null".into()), ty::Adt(..) if ty.is_box() => Some("`Box` must be non-null".into()),
FnPtr(..) => Some("function pointers must be non-null".into()), ty::FnPtr(..) => Some("function pointers must be non-null".into()),
Never => Some("the `!` type has no valid value".into()), ty::Never => Some("the `!` type has no valid value".into()),
RawPtr(ty, _) if matches!(ty.kind(), Dynamic(..)) => ty::RawPtr(ty, _) if matches!(ty.kind(), ty::Dynamic(..)) =>
// raw ptr to dyn Trait // raw ptr to dyn Trait
{ {
Some("the vtable of a wide raw pointer must be non-null".into()) Some("the vtable of a wide raw pointer must be non-null".into())
} }
// Primitive types with other constraints. // 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()) 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()) 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()) Some("integers must be initialized".into())
} }
Float(_) if init == InitKind::Uninit => Some("floats must be initialized".into()), ty::Float(_) if init == InitKind::Uninit => {
RawPtr(_, _) if init == InitKind::Uninit => { Some("floats must be initialized".into())
}
ty::RawPtr(_, _) if init == InitKind::Uninit => {
Some("raw pointers must be initialized".into()) Some("raw pointers must be initialized".into())
} }
// Recurse and checks for some compound types. (but not unions) // 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. // Handle structs.
if adt_def.is_struct() { if adt_def.is_struct() {
return variant_find_init_error( return variant_find_init_error(
@ -2675,11 +2676,11 @@ impl<'tcx> LateLintPass<'tcx> for InvalidValue {
// We couldn't find anything wrong here. // We couldn't find anything wrong here.
None None
} }
Tuple(..) => { ty::Tuple(..) => {
// Proceed recursively, check all fields. // Proceed recursively, check all fields.
ty.tuple_fields().iter().find_map(|field| ty_find_init_error(cx, field, init)) 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) { if matches!(len.try_to_target_usize(cx.tcx), Some(v) if v > 0) {
// Array length known at array non-empty -- recurse. // Array length known at array non-empty -- recurse.
ty_find_init_error(cx, *ty, init) ty_find_init_error(cx, *ty, init)

View File

@ -1,6 +1,5 @@
use rustc_hir as hir; use rustc_hir as hir;
use rustc_middle::ty::Ty; use rustc_middle::ty::{Ty, TypeVisitableExt};
use rustc_middle::ty::visit::TypeVisitableExt;
use rustc_session::{declare_lint, declare_lint_pass}; use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::{Span, sym}; use rustc_span::{Span, sym};

View File

@ -270,14 +270,12 @@ fn structurally_same_type_impl<'tcx>(
true true
} else { } else {
// Do a full, depth-first comparison between the two. // Do a full, depth-first comparison between the two.
use rustc_type_ir::TyKind::*;
let is_primitive_or_pointer = 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(|| { ensure_sufficient_stack(|| {
match (a.kind(), b.kind()) { 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. // Only `repr(C)` types can be compared structurally.
if !(a_def.repr().c() && b_def.repr().c()) { if !(a_def.repr().c() && b_def.repr().c()) {
return false; 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. // For arrays, we also check the length.
a_len == b_len a_len == b_len
&& structurally_same_type_impl( && structurally_same_type_impl(
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind, 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) 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 a_mutbl == b_mutbl
&& structurally_same_type_impl( && structurally_same_type_impl(
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind, 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. // For structural sameness, we don't need the region to be same.
a_mut == b_mut a_mut == b_mut
&& structurally_same_type_impl( && structurally_same_type_impl(
seen_types, tcx, typing_env, *a_ty, *b_ty, ckind, 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 a_poly_sig = a.fn_sig(tcx);
let b_poly_sig = b.fn_sig(tcx); let b_poly_sig = b.fn_sig(tcx);
@ -354,35 +352,38 @@ fn structurally_same_type_impl<'tcx>(
ckind, ckind,
) )
} }
(Tuple(..), Tuple(..)) => { (ty::Tuple(..), ty::Tuple(..)) => {
// Tuples are not `repr(C)` so these cannot be compared structurally. // Tuples are not `repr(C)` so these cannot be compared structurally.
false false
} }
// For these, it's not quite as easy to define structural-sameness quite so easily. // 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 // For the purposes of this lint, take the conservative approach and mark them as
// not structurally same. // not structurally same.
(Dynamic(..), Dynamic(..)) (ty::Dynamic(..), ty::Dynamic(..))
| (Error(..), Error(..)) | (ty::Error(..), ty::Error(..))
| (Closure(..), Closure(..)) | (ty::Closure(..), ty::Closure(..))
| (Coroutine(..), Coroutine(..)) | (ty::Coroutine(..), ty::Coroutine(..))
| (CoroutineWitness(..), CoroutineWitness(..)) | (ty::CoroutineWitness(..), ty::CoroutineWitness(..))
| (Alias(ty::Projection, ..), Alias(ty::Projection, ..)) | (ty::Alias(ty::Projection, ..), ty::Alias(ty::Projection, ..))
| (Alias(ty::Inherent, ..), Alias(ty::Inherent, ..)) | (ty::Alias(ty::Inherent, ..), ty::Alias(ty::Inherent, ..))
| (Alias(ty::Opaque, ..), Alias(ty::Opaque, ..)) => false, | (ty::Alias(ty::Opaque, ..), ty::Alias(ty::Opaque, ..)) => false,
// These definitely should have been caught above. // 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 // An Adt and a primitive or pointer type. This can be FFI-safe if non-null
// enum layout optimisation is being applied. // 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) { if let Some(a_inner) = types::repr_nullable_ptr(tcx, typing_env, a, ckind) {
a_inner == b a_inner == b
} else { } else {
false 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) { if let Some(b_inner) = types::repr_nullable_ptr(tcx, typing_env, b, ckind) {
b_inner == a b_inner == a
} else { } else {

View File

@ -506,9 +506,9 @@ impl<'tcx> TypeRelation<TyCtxt<'tcx>> for FunctionalVariances<'tcx> {
self.tcx self.tcx
} }
fn relate_with_variance<T: ty::relate::Relate<TyCtxt<'tcx>>>( fn relate_with_variance<T: Relate<TyCtxt<'tcx>>>(
&mut self, &mut self,
variance: rustc_type_ir::Variance, variance: ty::Variance,
_: ty::VarianceDiagInfo<TyCtxt<'tcx>>, _: ty::VarianceDiagInfo<TyCtxt<'tcx>>,
a: T, a: T,
b: T, b: T,

View File

@ -1,9 +1,8 @@
use rustc_hir::{self as hir, AmbigArg}; use rustc_hir::{self as hir, AmbigArg};
use rustc_infer::infer::TyCtxtInferExt; use rustc_infer::infer::TyCtxtInferExt;
use rustc_macros::{LintDiagnostic, Subdiagnostic}; use rustc_macros::{LintDiagnostic, Subdiagnostic};
use rustc_middle::ty::fold::BottomUpFolder;
use rustc_middle::ty::print::{PrintTraitPredicateExt as _, TraitPredPrintModifiersAndPath}; use rustc_middle::ty::print::{PrintTraitPredicateExt as _, TraitPredPrintModifiersAndPath};
use rustc_middle::ty::{self, Ty, TypeFoldable}; use rustc_middle::ty::{self, BottomUpFolder, Ty, TypeFoldable};
use rustc_session::{declare_lint, declare_lint_pass}; use rustc_session::{declare_lint, declare_lint_pass};
use rustc_span::{Span, kw}; use rustc_span::{Span, kw};
use rustc_trait_selection::traits::{self, ObligationCtxt}; use rustc_trait_selection::traits::{self, ObligationCtxt};

View File

@ -1422,7 +1422,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool { fn check_for_opaque_ty(&mut self, sp: Span, ty: Ty<'tcx>) -> bool {
struct ProhibitOpaqueTypes; struct ProhibitOpaqueTypes;
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for ProhibitOpaqueTypes { impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for ProhibitOpaqueTypes {
type Result = ControlFlow<Ty<'tcx>>; type Result = ControlFlow<Ty<'tcx>>;
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
@ -1564,7 +1564,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
} }
} }
impl<'tcx> ty::visit::TypeVisitor<TyCtxt<'tcx>> for FnPtrFinder<'tcx> { impl<'tcx> ty::TypeVisitor<TyCtxt<'tcx>> for FnPtrFinder<'tcx> {
type Result = (); type Result = ();
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result { fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {

View File

@ -74,8 +74,8 @@ decl_derive!(
hash_stable::hash_stable_no_context_derive hash_stable::hash_stable_no_context_derive
); );
decl_derive!([Decodable_Generic] => serialize::decodable_generic_derive); decl_derive!([Decodable_NoContext] => serialize::decodable_nocontext_derive);
decl_derive!([Encodable_Generic] => serialize::encodable_generic_derive); decl_derive!([Encodable_NoContext] => serialize::encodable_nocontext_derive);
decl_derive!([Decodable] => serialize::decodable_derive); decl_derive!([Decodable] => serialize::decodable_derive);
decl_derive!([Encodable] => serialize::encodable_derive); decl_derive!([Encodable] => serialize::encodable_derive);
decl_derive!([TyDecodable] => serialize::type_decodable_derive); decl_derive!([TyDecodable] => serialize::type_decodable_derive);

View File

@ -6,16 +6,11 @@ use syn::spanned::Spanned;
pub(super) fn type_decodable_derive( pub(super) fn type_decodable_derive(
mut s: synstructure::Structure<'_>, mut s: synstructure::Structure<'_>,
) -> proc_macro2::TokenStream { ) -> proc_macro2::TokenStream {
if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
s.add_impl_generic(parse_quote! { 'tcx });
}
let decoder_ty = quote! { __D }; let decoder_ty = quote! { __D };
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") { s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_middle::ty::codec::TyDecoder<'tcx> });
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
quote! { <I = I> }
} else {
quote! {}
};
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_type_ir::codec::TyDecoder #bound });
s.add_bounds(synstructure::AddBounds::Fields); s.add_bounds(synstructure::AddBounds::Fields);
s.underscore_const(true); s.underscore_const(true);
@ -45,12 +40,12 @@ pub(super) fn decodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro
decodable_body(s, decoder_ty) decodable_body(s, decoder_ty)
} }
pub(super) fn decodable_generic_derive( pub(super) fn decodable_nocontext_derive(
mut s: synstructure::Structure<'_>, mut s: synstructure::Structure<'_>,
) -> proc_macro2::TokenStream { ) -> proc_macro2::TokenStream {
let decoder_ty = quote! { __D }; let decoder_ty = quote! { __D };
s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_serialize::Decoder }); s.add_impl_generic(parse_quote! { #decoder_ty: ::rustc_serialize::Decoder });
s.add_bounds(synstructure::AddBounds::Generics); s.add_bounds(synstructure::AddBounds::Fields);
s.underscore_const(true); s.underscore_const(true);
decodable_body(s, decoder_ty) decodable_body(s, decoder_ty)
@ -132,16 +127,11 @@ fn decode_field(field: &syn::Field) -> proc_macro2::TokenStream {
pub(super) fn type_encodable_derive( pub(super) fn type_encodable_derive(
mut s: synstructure::Structure<'_>, mut s: synstructure::Structure<'_>,
) -> proc_macro2::TokenStream { ) -> proc_macro2::TokenStream {
let bound = if s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
quote! { <I = ::rustc_middle::ty::TyCtxt<'tcx>> }
} else if s.ast().generics.type_params().any(|ty| ty.ident == "I") {
quote! { <I = I> }
} else {
quote! {}
};
let encoder_ty = quote! { __E }; let encoder_ty = quote! { __E };
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_type_ir::codec::TyEncoder #bound }); if !s.ast().generics.lifetimes().any(|lt| lt.lifetime.ident == "tcx") {
s.add_impl_generic(parse_quote! { 'tcx });
}
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_middle::ty::codec::TyEncoder<'tcx> });
s.add_bounds(synstructure::AddBounds::Fields); s.add_bounds(synstructure::AddBounds::Fields);
s.underscore_const(true); s.underscore_const(true);
@ -171,12 +161,12 @@ pub(super) fn encodable_derive(mut s: synstructure::Structure<'_>) -> proc_macro
encodable_body(s, encoder_ty, false) encodable_body(s, encoder_ty, false)
} }
pub(super) fn encodable_generic_derive( pub(super) fn encodable_nocontext_derive(
mut s: synstructure::Structure<'_>, mut s: synstructure::Structure<'_>,
) -> proc_macro2::TokenStream { ) -> proc_macro2::TokenStream {
let encoder_ty = quote! { __E }; let encoder_ty = quote! { __E };
s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder }); s.add_impl_generic(parse_quote! { #encoder_ty: ::rustc_serialize::Encoder });
s.add_bounds(synstructure::AddBounds::Generics); s.add_bounds(synstructure::AddBounds::Fields);
s.underscore_const(true); s.underscore_const(true);
encodable_body(s, encoder_ty, false) encodable_body(s, encoder_ty, false)

View File

@ -38,16 +38,16 @@ pub(super) fn type_foldable_derive(mut s: synstructure::Structure<'_>) -> proc_m
bind.to_token_stream() bind.to_token_stream()
} else { } else {
quote! { quote! {
::rustc_middle::ty::fold::TypeFoldable::try_fold_with(#bind, __folder)? ::rustc_middle::ty::TypeFoldable::try_fold_with(#bind, __folder)?
} }
} }
}) })
}); });
s.bound_impl( s.bound_impl(
quote!(::rustc_middle::ty::fold::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>), quote!(::rustc_middle::ty::TypeFoldable<::rustc_middle::ty::TyCtxt<'tcx>>),
quote! { quote! {
fn try_fold_with<__F: ::rustc_middle::ty::fold::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>( fn try_fold_with<__F: ::rustc_middle::ty::FallibleTypeFolder<::rustc_middle::ty::TyCtxt<'tcx>>>(
self, self,
__folder: &mut __F __folder: &mut __F
) -> Result<Self, __F::Error> { ) -> Result<Self, __F::Error> {

View File

@ -36,12 +36,12 @@ pub(super) fn type_visitable_derive(
s.add_bounds(synstructure::AddBounds::Generics); s.add_bounds(synstructure::AddBounds::Generics);
let body_visit = s.each(|bind| { let body_visit = s.each(|bind| {
quote! { quote! {
match ::rustc_middle::ty::visit::VisitorResult::branch( match ::rustc_middle::ty::VisitorResult::branch(
::rustc_middle::ty::visit::TypeVisitable::visit_with(#bind, __visitor) ::rustc_middle::ty::TypeVisitable::visit_with(#bind, __visitor)
) { ) {
::core::ops::ControlFlow::Continue(()) => {}, ::core::ops::ControlFlow::Continue(()) => {},
::core::ops::ControlFlow::Break(r) => { ::core::ops::ControlFlow::Break(r) => {
return ::rustc_middle::ty::visit::VisitorResult::from_residual(r); return ::rustc_middle::ty::VisitorResult::from_residual(r);
}, },
} }
} }
@ -49,14 +49,14 @@ pub(super) fn type_visitable_derive(
s.bind_with(|_| synstructure::BindStyle::Move); s.bind_with(|_| synstructure::BindStyle::Move);
s.bound_impl( s.bound_impl(
quote!(::rustc_middle::ty::visit::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>), quote!(::rustc_middle::ty::TypeVisitable<::rustc_middle::ty::TyCtxt<'tcx>>),
quote! { quote! {
fn visit_with<__V: ::rustc_middle::ty::visit::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>( fn visit_with<__V: ::rustc_middle::ty::TypeVisitor<::rustc_middle::ty::TyCtxt<'tcx>>>(
&self, &self,
__visitor: &mut __V __visitor: &mut __V
) -> __V::Result { ) -> __V::Result {
match *self { #body_visit } match *self { #body_visit }
<__V::Result as ::rustc_middle::ty::visit::VisitorResult>::output() <__V::Result as ::rustc_middle::ty::VisitorResult>::output()
} }
}, },
) )

View File

@ -27,7 +27,6 @@ rustc_serialize = { path = "../rustc_serialize" }
rustc_session = { path = "../rustc_session" } rustc_session = { path = "../rustc_session" }
rustc_span = { path = "../rustc_span" } rustc_span = { path = "../rustc_span" }
rustc_target = { path = "../rustc_target" } rustc_target = { path = "../rustc_target" }
rustc_type_ir = { path = "../rustc_type_ir" }
tempfile = "3.2" tempfile = "3.2"
tracing = "0.1" tracing = "0.1"
# tidy-alphabetical-end # tidy-alphabetical-end

View File

@ -386,13 +386,11 @@ impl<'a, 'tcx> DecodeContext<'a, 'tcx> {
} }
} }
impl<'a, 'tcx> TyDecoder for DecodeContext<'a, 'tcx> { impl<'a, 'tcx> TyDecoder<'tcx> for DecodeContext<'a, 'tcx> {
const CLEAR_CROSS_CRATE: bool = true; const CLEAR_CROSS_CRATE: bool = true;
type I = TyCtxt<'tcx>;
#[inline] #[inline]
fn interner(&self) -> Self::I { fn interner(&self) -> TyCtxt<'tcx> {
self.tcx() self.tcx()
} }

View File

@ -378,11 +378,9 @@ impl<'a, 'tcx> Encodable<EncodeContext<'a, 'tcx>> for [u8] {
} }
} }
impl<'a, 'tcx> TyEncoder for EncodeContext<'a, 'tcx> { impl<'a, 'tcx> TyEncoder<'tcx> for EncodeContext<'a, 'tcx> {
const CLEAR_CROSS_CRATE: bool = true; const CLEAR_CROSS_CRATE: bool = true;
type I = TyCtxt<'tcx>;
fn position(&self) -> usize { fn position(&self) -> usize {
self.opaque.position() self.opaque.position()
} }

View File

@ -59,8 +59,8 @@ macro_rules! TrivialLiftImpls {
macro_rules! TrivialTypeTraversalImpls { macro_rules! TrivialTypeTraversalImpls {
($($ty:ty),+ $(,)?) => { ($($ty:ty),+ $(,)?) => {
$( $(
impl<'tcx> $crate::ty::fold::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty { impl<'tcx> $crate::ty::TypeFoldable<$crate::ty::TyCtxt<'tcx>> for $ty {
fn try_fold_with<F: $crate::ty::fold::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>( fn try_fold_with<F: $crate::ty::FallibleTypeFolder<$crate::ty::TyCtxt<'tcx>>>(
self, self,
_: &mut F, _: &mut F,
) -> ::std::result::Result<Self, F::Error> { ) -> ::std::result::Result<Self, F::Error> {
@ -68,7 +68,7 @@ macro_rules! TrivialTypeTraversalImpls {
} }
#[inline] #[inline]
fn fold_with<F: $crate::ty::fold::TypeFolder<$crate::ty::TyCtxt<'tcx>>>( fn fold_with<F: $crate::ty::TypeFolder<$crate::ty::TyCtxt<'tcx>>>(
self, self,
_: &mut F, _: &mut F,
) -> Self { ) -> Self {
@ -76,14 +76,14 @@ macro_rules! TrivialTypeTraversalImpls {
} }
} }
impl<'tcx> $crate::ty::visit::TypeVisitable<$crate::ty::TyCtxt<'tcx>> for $ty { impl<'tcx> $crate::ty::TypeVisitable<$crate::ty::TyCtxt<'tcx>> for $ty {
#[inline] #[inline]
fn visit_with<F: $crate::ty::visit::TypeVisitor<$crate::ty::TyCtxt<'tcx>>>( fn visit_with<F: $crate::ty::TypeVisitor<$crate::ty::TyCtxt<'tcx>>>(
&self, &self,
_: &mut F) _: &mut F)
-> F::Result -> F::Result
{ {
<F::Result as ::rustc_middle::ty::visit::VisitorResult>::output() <F::Result as ::rustc_middle::ty::VisitorResult>::output()
} }
} }
)+ )+

View File

@ -6,7 +6,7 @@ use rustc_macros::{HashStable, Lift, TyDecodable, TyEncodable, TypeFoldable, Typ
use rustc_session::RemapFileNameExt; use rustc_session::RemapFileNameExt;
use rustc_session::config::RemapPathScopeComponents; use rustc_session::config::RemapPathScopeComponents;
use rustc_span::{DUMMY_SP, Span, Symbol}; use rustc_span::{DUMMY_SP, Span, Symbol};
use rustc_type_ir::visit::TypeVisitableExt; use rustc_type_ir::TypeVisitableExt;
use super::interpret::ReportedErrorInfo; use super::interpret::ReportedErrorInfo;
use crate::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, Scalar, alloc_range}; use crate::mir::interpret::{AllocId, ConstAllocation, ErrorHandled, Scalar, alloc_range};

View File

@ -16,8 +16,7 @@ use rustc_abi::{Align, HasDataLayout, Size};
use rustc_ast::Mutability; use rustc_ast::Mutability;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_macros::HashStable; use rustc_macros::HashStable;
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_type_ir::{TyDecoder, TyEncoder};
use super::{ use super::{
AllocId, BadBytesAccess, CtfeProvenance, InterpErrorKind, InterpResult, Pointer, AllocId, BadBytesAccess, CtfeProvenance, InterpErrorKind, InterpResult, Pointer,
@ -112,7 +111,7 @@ struct AllocFlags {
all_zero: bool, all_zero: bool,
} }
impl<E: TyEncoder> Encodable<E> for AllocFlags { impl<E: Encoder> Encodable<E> for AllocFlags {
fn encode(&self, encoder: &mut E) { fn encode(&self, encoder: &mut E) {
// Make sure Align::MAX can be stored with the high 2 bits unset. // Make sure Align::MAX can be stored with the high 2 bits unset.
const { const {
@ -131,7 +130,7 @@ impl<E: TyEncoder> Encodable<E> for AllocFlags {
} }
} }
impl<D: TyDecoder> Decodable<D> for AllocFlags { impl<D: Decoder> Decodable<D> for AllocFlags {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
let flags: u8 = Decodable::decode(decoder); let flags: u8 = Decodable::decode(decoder);
let align = flags & 0b0011_1111; let align = flags & 0b0011_1111;
@ -173,7 +172,7 @@ fn all_zero(buf: &[u8]) -> bool {
} }
/// Custom encoder for [`Allocation`] to more efficiently represent the case where all bytes are 0. /// Custom encoder for [`Allocation`] to more efficiently represent the case where all bytes are 0.
impl<Prov: Provenance, Extra, Bytes, E: TyEncoder> Encodable<E> for Allocation<Prov, Extra, Bytes> impl<Prov: Provenance, Extra, Bytes, E: Encoder> Encodable<E> for Allocation<Prov, Extra, Bytes>
where where
Bytes: AllocBytes, Bytes: AllocBytes,
ProvenanceMap<Prov>: Encodable<E>, ProvenanceMap<Prov>: Encodable<E>,
@ -193,7 +192,7 @@ where
} }
} }
impl<Prov: Provenance, Extra, Bytes, D: TyDecoder> Decodable<D> for Allocation<Prov, Extra, Bytes> impl<Prov: Provenance, Extra, Bytes, D: Decoder> Decodable<D> for Allocation<Prov, Extra, Bytes>
where where
Bytes: AllocBytes, Bytes: AllocBytes,
ProvenanceMap<Prov>: Decodable<D>, ProvenanceMap<Prov>: Decodable<D>,

View File

@ -5,9 +5,8 @@ use std::ops::Range;
use std::{hash, iter}; use std::{hash, iter};
use rustc_abi::Size; use rustc_abi::Size;
use rustc_macros::{HashStable, TyDecodable, TyEncodable}; use rustc_macros::{Decodable_NoContext, Encodable_NoContext, HashStable};
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
use rustc_type_ir::{TyDecoder, TyEncoder};
use super::AllocRange; use super::AllocRange;
@ -19,13 +18,13 @@ type Block = u64;
/// possible. Currently, if all the blocks have the same value, then the mask represents either a /// possible. Currently, if all the blocks have the same value, then the mask represents either a
/// fully initialized or fully uninitialized const allocation, so we can only store that single /// fully initialized or fully uninitialized const allocation, so we can only store that single
/// value. /// value.
#[derive(Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Clone, Debug, Eq, PartialEq, Encodable_NoContext, Decodable_NoContext, Hash, HashStable)]
pub struct InitMask { pub struct InitMask {
blocks: InitMaskBlocks, blocks: InitMaskBlocks,
len: Size, len: Size,
} }
#[derive(Clone, Debug, Eq, PartialEq, TyEncodable, TyDecodable, Hash, HashStable)] #[derive(Clone, Debug, Eq, PartialEq, Encodable_NoContext, Decodable_NoContext, Hash, HashStable)]
enum InitMaskBlocks { enum InitMaskBlocks {
Lazy { Lazy {
/// Whether the lazy init mask is fully initialized or uninitialized. /// Whether the lazy init mask is fully initialized or uninitialized.
@ -194,7 +193,7 @@ struct InitMaskMaterialized {
// and also produces more output when the high bits of each `u64` are occupied. // and also produces more output when the high bits of each `u64` are occupied.
// Note: There is probably a remaining optimization for masks that do not use an entire // Note: There is probably a remaining optimization for masks that do not use an entire
// `Block`. // `Block`.
impl<E: TyEncoder> Encodable<E> for InitMaskMaterialized { impl<E: Encoder> Encodable<E> for InitMaskMaterialized {
fn encode(&self, encoder: &mut E) { fn encode(&self, encoder: &mut E) {
encoder.emit_usize(self.blocks.len()); encoder.emit_usize(self.blocks.len());
for block in &self.blocks { for block in &self.blocks {
@ -204,7 +203,7 @@ impl<E: TyEncoder> Encodable<E> for InitMaskMaterialized {
} }
// This implementation is deliberately not derived, see the matching `Encodable` impl. // This implementation is deliberately not derived, see the matching `Encodable` impl.
impl<D: TyDecoder> Decodable<D> for InitMaskMaterialized { impl<D: Decoder> Decodable<D> for InitMaskMaterialized {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
let num_blocks = decoder.read_usize(); let num_blocks = decoder.read_usize();
let mut blocks = Vec::with_capacity(num_blocks); let mut blocks = Vec::with_capacity(num_blocks);

View File

@ -105,7 +105,7 @@ enum AllocDiscriminant {
Static, Static,
} }
pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>>( pub fn specialized_encode_alloc_id<'tcx, E: TyEncoder<'tcx>>(
encoder: &mut E, encoder: &mut E,
tcx: TyCtxt<'tcx>, tcx: TyCtxt<'tcx>,
alloc_id: AllocId, alloc_id: AllocId,
@ -175,7 +175,7 @@ impl<'s> AllocDecodingSession<'s> {
/// Decodes an `AllocId` in a thread-safe way. /// Decodes an `AllocId` in a thread-safe way.
pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId pub fn decode_alloc_id<'tcx, D>(&self, decoder: &mut D) -> AllocId
where where
D: TyDecoder<I = TyCtxt<'tcx>>, D: TyDecoder<'tcx>,
{ {
// Read the index of the allocation. // Read the index of the allocation.
let idx = usize::try_from(decoder.read_u32()).unwrap(); let idx = usize::try_from(decoder.read_u32()).unwrap();

View File

@ -10,8 +10,7 @@ use super::{
}; };
use crate::mir; use crate::mir;
use crate::query::TyCtxtEnsureOk; use crate::query::TyCtxtEnsureOk;
use crate::ty::visit::TypeVisitableExt; use crate::ty::{self, GenericArgs, TyCtxt, TypeVisitableExt};
use crate::ty::{self, GenericArgs, TyCtxt};
impl<'tcx> TyCtxt<'tcx> { impl<'tcx> TyCtxt<'tcx> {
/// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts /// Evaluates a constant without providing any generic parameters. This is useful to evaluate consts

View File

@ -32,10 +32,9 @@ pub use self::query::*;
use crate::mir::interpret::{AllocRange, Scalar}; use crate::mir::interpret::{AllocRange, Scalar};
use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths}; use crate::ty::print::{FmtPrinter, Printer, pretty_print_const, with_no_trimmed_paths};
use crate::ty::visit::TypeVisitableExt;
use crate::ty::{ use crate::ty::{
self, AdtDef, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt, TypingEnv, self, AdtDef, GenericArg, GenericArgsRef, Instance, InstanceKind, List, Ty, TyCtxt,
UserTypeAnnotationIndex, TypeVisitableExt, TypingEnv, UserTypeAnnotationIndex,
}; };
mod basic_blocks; mod basic_blocks;
@ -791,7 +790,7 @@ impl<T> ClearCrossCrate<T> {
const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0; const TAG_CLEAR_CROSS_CRATE_CLEAR: u8 = 0;
const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1; const TAG_CLEAR_CROSS_CRATE_SET: u8 = 1;
impl<E: TyEncoder, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> { impl<'tcx, E: TyEncoder<'tcx>, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
#[inline] #[inline]
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
if E::CLEAR_CROSS_CRATE { if E::CLEAR_CROSS_CRATE {
@ -807,7 +806,7 @@ impl<E: TyEncoder, T: Encodable<E>> Encodable<E> for ClearCrossCrate<T> {
} }
} }
} }
impl<D: TyDecoder, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> { impl<'tcx, D: TyDecoder<'tcx>, T: Decodable<D>> Decodable<D> for ClearCrossCrate<T> {
#[inline] #[inline]
fn decode(d: &mut D) -> ClearCrossCrate<T> { fn decode(d: &mut D) -> ClearCrossCrate<T> {
if D::CLEAR_CROSS_CRATE { if D::CLEAR_CROSS_CRATE {

View File

@ -13,8 +13,7 @@ use rustc_span::{Span, Symbol};
use smallvec::SmallVec; use smallvec::SmallVec;
use super::{ConstValue, SourceInfo}; use super::{ConstValue, SourceInfo};
use crate::ty::fold::fold_regions; use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty, TyCtxt, fold_regions};
use crate::ty::{self, CoroutineArgsExt, OpaqueHiddenType, Ty, TyCtxt};
rustc_index::newtype_index! { rustc_index::newtype_index! {
#[derive(HashStable)] #[derive(HashStable)]

View File

@ -518,8 +518,7 @@ where
value value
} }
impl<'a, 'tcx> TyDecoder for CacheDecoder<'a, 'tcx> { impl<'a, 'tcx> TyDecoder<'tcx> for CacheDecoder<'a, 'tcx> {
type I = TyCtxt<'tcx>;
const CLEAR_CROSS_CRATE: bool = false; const CLEAR_CROSS_CRATE: bool = false;
#[inline] #[inline]
@ -943,8 +942,7 @@ impl<'a, 'tcx> SpanEncoder for CacheEncoder<'a, 'tcx> {
} }
} }
impl<'a, 'tcx> TyEncoder for CacheEncoder<'a, 'tcx> { impl<'a, 'tcx> TyEncoder<'tcx> for CacheEncoder<'a, 'tcx> {
type I = TyCtxt<'tcx>;
const CLEAR_CROSS_CRATE: bool = false; const CLEAR_CROSS_CRATE: bool = false;
#[inline] #[inline]

View File

@ -3,9 +3,9 @@ use rustc_macros::HashStable;
use rustc_type_ir as ir; use rustc_type_ir as ir;
pub use rustc_type_ir::solve::*; pub use rustc_type_ir::solve::*;
use crate::ty::visit::try_visit;
use crate::ty::{ use crate::ty::{
self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor, self, FallibleTypeFolder, TyCtxt, TypeFoldable, TypeFolder, TypeVisitable, TypeVisitor,
try_visit,
}; };
pub type Goal<'tcx, P> = ir::solve::Goal<TyCtxt<'tcx>, P>; pub type Goal<'tcx, P> = ir::solve::Goal<TyCtxt<'tcx>, P>;

View File

@ -6,8 +6,7 @@ use rustc_span::sym;
use crate::error::StrictCoherenceNeedsNegativeCoherence; use crate::error::StrictCoherenceNeedsNegativeCoherence;
use crate::ty::fast_reject::SimplifiedType; use crate::ty::fast_reject::SimplifiedType;
use crate::ty::visit::TypeVisitableExt; use crate::ty::{self, TyCtxt, TypeVisitableExt};
use crate::ty::{self, TyCtxt};
/// A per-trait graph of impls in specialization order. At the moment, this /// A per-trait graph of impls in specialization order. At the moment, this
/// graph forms a tree rooted with the trait itself, with all other nodes /// graph forms a tree rooted with the trait itself, with all other nodes

View File

@ -14,9 +14,8 @@ use rustc_abi::{FieldIdx, VariantIdx};
use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::fx::FxHashMap;
use rustc_hir::def_id::LocalDefId; use rustc_hir::def_id::LocalDefId;
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
use rustc_span::Span;
use rustc_span::source_map::Spanned; use rustc_span::source_map::Spanned;
pub use rustc_type_ir::{TyDecoder, TyEncoder}; use rustc_span::{Span, SpanDecoder, SpanEncoder};
use crate::arena::ArenaAllocatable; use crate::arena::ArenaAllocatable;
use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos}; use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos};
@ -31,13 +30,45 @@ use crate::ty::{self, AdtDef, GenericArgsRef, Ty, TyCtxt};
/// This offset is also chosen so that the first byte is never < 0x80. /// This offset is also chosen so that the first byte is never < 0x80.
pub const SHORTHAND_OFFSET: usize = 0x80; pub const SHORTHAND_OFFSET: usize = 0x80;
pub trait EncodableWithShorthand<E: TyEncoder>: Copy + Eq + Hash { pub trait TyEncoder<'tcx>: SpanEncoder {
const CLEAR_CROSS_CRATE: bool;
fn position(&self) -> usize;
fn type_shorthands(&mut self) -> &mut FxHashMap<Ty<'tcx>, usize>;
fn predicate_shorthands(&mut self) -> &mut FxHashMap<ty::PredicateKind<'tcx>, usize>;
fn encode_alloc_id(&mut self, alloc_id: &AllocId);
}
pub trait TyDecoder<'tcx>: SpanDecoder {
const CLEAR_CROSS_CRATE: bool;
fn interner(&self) -> TyCtxt<'tcx>;
fn cached_ty_for_shorthand<F>(&mut self, shorthand: usize, or_insert_with: F) -> Ty<'tcx>
where
F: FnOnce(&mut Self) -> Ty<'tcx>;
fn with_position<F, R>(&mut self, pos: usize, f: F) -> R
where
F: FnOnce(&mut Self) -> R;
fn positioned_at_shorthand(&self) -> bool {
(self.peek_byte() & (SHORTHAND_OFFSET as u8)) != 0
}
fn decode_alloc_id(&mut self) -> AllocId;
}
pub trait EncodableWithShorthand<'tcx, E: TyEncoder<'tcx>>: Copy + Eq + Hash {
type Variant: Encodable<E>; type Variant: Encodable<E>;
fn variant(&self) -> &Self::Variant; fn variant(&self) -> &Self::Variant;
} }
#[allow(rustc::usage_of_ty_tykind)] #[allow(rustc::usage_of_ty_tykind)]
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> EncodableWithShorthand<E> for Ty<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for Ty<'tcx> {
type Variant = ty::TyKind<'tcx>; type Variant = ty::TyKind<'tcx>;
#[inline] #[inline]
@ -46,7 +77,7 @@ impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> EncodableWithShorthand<E> for Ty<'tcx
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> EncodableWithShorthand<E> for ty::PredicateKind<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> EncodableWithShorthand<'tcx, E> for ty::PredicateKind<'tcx> {
type Variant = ty::PredicateKind<'tcx>; type Variant = ty::PredicateKind<'tcx>;
#[inline] #[inline]
@ -65,16 +96,16 @@ impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> EncodableWithShorthand<E> for ty::Pre
/// ///
/// `Decodable` can still be implemented in cases where `Decodable` is required /// `Decodable` can still be implemented in cases where `Decodable` is required
/// by a trait bound. /// by a trait bound.
pub trait RefDecodable<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> { pub trait RefDecodable<'tcx, D: TyDecoder<'tcx>> {
fn decode(d: &mut D) -> &'tcx Self; fn decode(d: &mut D) -> &'tcx Self;
} }
/// Encode the given value or a previously cached shorthand. /// Encode the given value or a previously cached shorthand.
pub fn encode_with_shorthand<'tcx, E, T, M>(encoder: &mut E, value: &T, cache: M) pub fn encode_with_shorthand<'tcx, E, T, M>(encoder: &mut E, value: &T, cache: M)
where where
E: TyEncoder<I = TyCtxt<'tcx>>, E: TyEncoder<'tcx>,
M: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<T, usize>, M: for<'b> Fn(&'b mut E) -> &'b mut FxHashMap<T, usize>,
T: EncodableWithShorthand<E>, T: EncodableWithShorthand<'tcx, E>,
// The discriminant and shorthand must have the same size. // The discriminant and shorthand must have the same size.
T::Variant: DiscriminantKind<Discriminant = isize>, T::Variant: DiscriminantKind<Discriminant = isize>,
{ {
@ -108,13 +139,13 @@ where
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for Ty<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Ty<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
encode_with_shorthand(e, self, TyEncoder::type_shorthands); encode_with_shorthand(e, self, TyEncoder::type_shorthands);
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Predicate<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Predicate<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
let kind = self.kind(); let kind = self.kind();
kind.bound_vars().encode(e); kind.bound_vars().encode(e);
@ -122,76 +153,72 @@ impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Predicate<'tcx>
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Clause<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Clause<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.as_predicate().encode(e); self.as_predicate().encode(e);
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Region<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Region<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.kind().encode(e); self.kind().encode(e);
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Const<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Const<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.0.0.encode(e); self.0.0.encode(e);
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::Pattern<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::Pattern<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.0.0.encode(e); self.0.0.encode(e);
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::ValTree<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::ValTree<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.0.0.encode(e); self.0.0.encode(e);
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ConstAllocation<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ConstAllocation<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.inner().encode(e) self.inner().encode(e)
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for AdtDef<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for AdtDef<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.0.0.encode(e) self.0.0.encode(e)
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for AllocId { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for AllocId {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
e.encode_alloc_id(self) e.encode_alloc_id(self)
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for CtfeProvenance { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for CtfeProvenance {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.into_parts().encode(e); self.into_parts().encode(e);
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for ty::ParamEnv<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for ty::ParamEnv<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.caller_bounds().encode(e); self.caller_bounds().encode(e);
} }
} }
#[inline] #[inline]
fn decode_arena_allocable< fn decode_arena_allocable<'tcx, D: TyDecoder<'tcx>, T: ArenaAllocatable<'tcx> + Decodable<D>>(
'tcx,
D: TyDecoder<I = TyCtxt<'tcx>>,
T: ArenaAllocatable<'tcx> + Decodable<D>,
>(
decoder: &mut D, decoder: &mut D,
) -> &'tcx T ) -> &'tcx T
where where
D: TyDecoder, D: TyDecoder<'tcx>,
{ {
decoder.interner().arena.alloc(Decodable::decode(decoder)) decoder.interner().arena.alloc(Decodable::decode(decoder))
} }
@ -199,18 +226,18 @@ where
#[inline] #[inline]
fn decode_arena_allocable_slice< fn decode_arena_allocable_slice<
'tcx, 'tcx,
D: TyDecoder<I = TyCtxt<'tcx>>, D: TyDecoder<'tcx>,
T: ArenaAllocatable<'tcx> + Decodable<D>, T: ArenaAllocatable<'tcx> + Decodable<D>,
>( >(
decoder: &mut D, decoder: &mut D,
) -> &'tcx [T] ) -> &'tcx [T]
where where
D: TyDecoder, D: TyDecoder<'tcx>,
{ {
decoder.interner().arena.alloc_from_iter(<Vec<T> as Decodable<D>>::decode(decoder)) decoder.interner().arena.alloc_from_iter(<Vec<T> as Decodable<D>>::decode(decoder))
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Ty<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Ty<'tcx> {
#[allow(rustc::usage_of_ty_tykind)] #[allow(rustc::usage_of_ty_tykind)]
fn decode(decoder: &mut D) -> Ty<'tcx> { fn decode(decoder: &mut D) -> Ty<'tcx> {
// Handle shorthands first, if we have a usize > 0x80. // Handle shorthands first, if we have a usize > 0x80.
@ -229,7 +256,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Ty<'tcx> {
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Predicate<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Predicate<'tcx> {
fn decode(decoder: &mut D) -> ty::Predicate<'tcx> { fn decode(decoder: &mut D) -> ty::Predicate<'tcx> {
let bound_vars = Decodable::decode(decoder); let bound_vars = Decodable::decode(decoder);
// Handle shorthands first, if we have a usize > 0x80. // Handle shorthands first, if we have a usize > 0x80.
@ -249,14 +276,14 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Predicate<'tcx>
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Clause<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Clause<'tcx> {
fn decode(decoder: &mut D) -> ty::Clause<'tcx> { fn decode(decoder: &mut D) -> ty::Clause<'tcx> {
let pred: ty::Predicate<'tcx> = Decodable::decode(decoder); let pred: ty::Predicate<'tcx> = Decodable::decode(decoder);
pred.expect_clause() pred.expect_clause()
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for GenericArgsRef<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for GenericArgsRef<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
let tcx = decoder.interner(); let tcx = decoder.interner();
@ -266,7 +293,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for GenericArgsRef<'tcx>
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for mir::Place<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for mir::Place<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
let local: mir::Local = Decodable::decode(decoder); let local: mir::Local = Decodable::decode(decoder);
let len = decoder.read_usize(); let len = decoder.read_usize();
@ -277,13 +304,13 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for mir::Place<'tcx> {
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Region<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Region<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
ty::Region::new_from_kind(decoder.interner(), Decodable::decode(decoder)) ty::Region::new_from_kind(decoder.interner(), Decodable::decode(decoder))
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for CanonicalVarInfos<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for CanonicalVarInfos<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
decoder.interner().mk_canonical_var_infos_from_iter( decoder.interner().mk_canonical_var_infos_from_iter(
@ -292,26 +319,26 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for CanonicalVarInfos<'t
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for AllocId { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for AllocId {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
decoder.decode_alloc_id() decoder.decode_alloc_id()
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for CtfeProvenance { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for CtfeProvenance {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
let parts = Decodable::decode(decoder); let parts = Decodable::decode(decoder);
CtfeProvenance::from_parts(parts) CtfeProvenance::from_parts(parts)
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::SymbolName<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::SymbolName<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
ty::SymbolName::new(decoder.interner(), decoder.read_str()) ty::SymbolName::new(decoder.interner(), decoder.read_str())
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::ParamEnv<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::ParamEnv<'tcx> {
fn decode(d: &mut D) -> Self { fn decode(d: &mut D) -> Self {
let caller_bounds = Decodable::decode(d); let caller_bounds = Decodable::decode(d);
ty::ParamEnv::new(caller_bounds) ty::ParamEnv::new(caller_bounds)
@ -320,7 +347,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::ParamEnv<'tcx> {
macro_rules! impl_decodable_via_ref { macro_rules! impl_decodable_via_ref {
($($t:ty,)+) => { ($($t:ty,)+) => {
$(impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for $t { $(impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for $t {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
RefDecodable::decode(decoder) RefDecodable::decode(decoder)
} }
@ -328,7 +355,7 @@ macro_rules! impl_decodable_via_ref {
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<Ty<'tcx>> { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<Ty<'tcx>> {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
decoder decoder
@ -337,7 +364,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<Ty
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D>
for ty::List<ty::PolyExistentialPredicate<'tcx>> for ty::List<ty::PolyExistentialPredicate<'tcx>>
{ {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
@ -348,38 +375,38 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Const<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Const<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
let kind: ty::ConstKind<'tcx> = Decodable::decode(decoder); let kind: ty::ConstKind<'tcx> = Decodable::decode(decoder);
decoder.interner().mk_ct_from_kind(kind) decoder.interner().mk_ct_from_kind(kind)
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::Pattern<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::Pattern<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
decoder.interner().mk_pat(Decodable::decode(decoder)) decoder.interner().mk_pat(Decodable::decode(decoder))
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ty::ValTree<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ty::ValTree<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
decoder.interner().intern_valtree(Decodable::decode(decoder)) decoder.interner().intern_valtree(Decodable::decode(decoder))
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for ConstAllocation<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for ConstAllocation<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
decoder.interner().mk_const_alloc(Decodable::decode(decoder)) decoder.interner().mk_const_alloc(Decodable::decode(decoder))
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for AdtDef<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for AdtDef<'tcx> {
fn decode(decoder: &mut D) -> Self { fn decode(decoder: &mut D) -> Self {
decoder.interner().mk_adt_def_from_data(Decodable::decode(decoder)) decoder.interner().mk_adt_def_from_data(Decodable::decode(decoder))
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [(ty::Clause<'tcx>, Span)] { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [(ty::Clause<'tcx>, Span)] {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
decoder decoder
.interner() .interner()
@ -388,9 +415,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [(ty::Claus
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [(ty::PolyTraitRef<'tcx>, Span)] {
for [(ty::PolyTraitRef<'tcx>, Span)]
{
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
decoder decoder
.interner() .interner()
@ -399,7 +424,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [Spanned<MonoItem<'tcx>>] { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [Spanned<MonoItem<'tcx>>] {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
decoder decoder
.interner() .interner()
@ -408,9 +433,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [Spanned<Mo
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<ty::BoundVariableKind> {
for ty::List<ty::BoundVariableKind>
{
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
decoder.interner().mk_bound_variable_kinds_from_iter( decoder.interner().mk_bound_variable_kinds_from_iter(
@ -419,7 +442,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty::Const<'tcx>> { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<ty::Const<'tcx>> {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
decoder.interner().mk_const_list_from_iter( decoder.interner().mk_const_list_from_iter(
@ -428,7 +451,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<ty
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D>
for ty::ListWithCachedTypeInfo<ty::Clause<'tcx>> for ty::ListWithCachedTypeInfo<ty::Clause<'tcx>>
{ {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
@ -439,7 +462,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D>
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<FieldIdx> { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<FieldIdx> {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
decoder decoder
@ -448,7 +471,7 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<Fi
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<LocalDefId> { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<LocalDefId> {
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
decoder.interner().mk_local_def_ids_from_iter( decoder.interner().mk_local_def_ids_from_iter(
@ -457,15 +480,13 @@ impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for ty::List<Lo
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for &'tcx ty::List<LocalDefId> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for &'tcx ty::List<LocalDefId> {
fn decode(d: &mut D) -> Self { fn decode(d: &mut D) -> Self {
RefDecodable::decode(d) RefDecodable::decode(d)
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for ty::List<(VariantIdx, FieldIdx)> {
for ty::List<(VariantIdx, FieldIdx)>
{
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
let len = decoder.read_usize(); let len = decoder.read_usize();
decoder.interner().mk_offset_of_from_iter( decoder.interner().mk_offset_of_from_iter(
@ -503,14 +524,14 @@ macro_rules! impl_arena_allocatable_decoder {
([]$args:tt) => {}; ([]$args:tt) => {};
([decode $(, $attrs:ident)*] ([decode $(, $attrs:ident)*]
[$name:ident: $ty:ty]) => { [$name:ident: $ty:ty]) => {
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for $ty { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for $ty {
#[inline] #[inline]
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
decode_arena_allocable(decoder) decode_arena_allocable(decoder)
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [$ty] { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [$ty] {
#[inline] #[inline]
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
decode_arena_allocable_slice(decoder) decode_arena_allocable_slice(decoder)
@ -532,14 +553,14 @@ arena_types!(impl_arena_allocatable_decoders);
macro_rules! impl_arena_copy_decoder { macro_rules! impl_arena_copy_decoder {
(<$tcx:tt> $($ty:ty,)*) => { (<$tcx:tt> $($ty:ty,)*) => {
$(impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for $ty { $(impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for $ty {
#[inline] #[inline]
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().arena.alloc(Decodable::decode(decoder)) decoder.interner().arena.alloc(Decodable::decode(decoder))
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> RefDecodable<'tcx, D> for [$ty] { impl<'tcx, D: TyDecoder<'tcx>> RefDecodable<'tcx, D> for [$ty] {
#[inline] #[inline]
fn decode(decoder: &mut D) -> &'tcx Self { fn decode(decoder: &mut D) -> &'tcx Self {
decoder.interner().arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder)) decoder.interner().arena.alloc_from_iter(<Vec<_> as Decodable<D>>::decode(decoder))

View File

@ -34,7 +34,7 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Const<'tcx> {
} }
} }
impl<'tcx> rustc_type_ir::visit::Flags for Const<'tcx> { impl<'tcx> rustc_type_ir::Flags for Const<'tcx> {
fn flags(&self) -> TypeFlags { fn flags(&self) -> TypeFlags {
self.0.flags self.0.flags
} }

View File

@ -49,11 +49,10 @@ use rustc_session::{Limit, MetadataKind, Session};
use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId}; use rustc_span::def_id::{CRATE_DEF_ID, DefPathHash, StableCrateId};
use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym}; use rustc_span::{DUMMY_SP, Ident, Span, Symbol, kw, sym};
use rustc_type_ir::TyKind::*; use rustc_type_ir::TyKind::*;
use rustc_type_ir::fold::TypeFoldable;
use rustc_type_ir::lang_items::TraitSolverLangItem; use rustc_type_ir::lang_items::TraitSolverLangItem;
pub use rustc_type_ir::lift::Lift; pub use rustc_type_ir::lift::Lift;
use rustc_type_ir::{ use rustc_type_ir::{
CollectAndApply, Interner, TypeFlags, WithCachedTypeInfo, elaborate, search_graph, CollectAndApply, Interner, TypeFlags, TypeFoldable, WithCachedTypeInfo, elaborate, search_graph,
}; };
use tracing::{debug, instrument}; use tracing::{debug, instrument};

View File

@ -1,8 +1,9 @@
use tracing::debug; use tracing::debug;
use crate::query::Providers; use crate::query::Providers;
use crate::ty::fold::{TypeFoldable, TypeFolder, TypeSuperFoldable}; use crate::ty::{
use crate::ty::{self, Ty, TyCtxt, TypeFlags, TypeVisitableExt}; self, Ty, TyCtxt, TypeFlags, TypeFoldable, TypeFolder, TypeSuperFoldable, TypeVisitableExt,
};
pub(super) fn provide(providers: &mut Providers) { pub(super) fn provide(providers: &mut Providers) {
*providers = Providers { erase_regions_ty, ..*providers }; *providers = Providers { erase_regions_ty, ..*providers };

View File

@ -1,12 +1,11 @@
use rustc_data_structures::fx::FxIndexMap; use rustc_data_structures::fx::FxIndexMap;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_type_ir::data_structures::DelayedMap; use rustc_type_ir::data_structures::DelayedMap;
pub use rustc_type_ir::fold::{
FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable, fold_regions, shift_region,
shift_vars,
};
use crate::ty::{self, Binder, BoundTy, Ty, TyCtxt, TypeVisitableExt}; use crate::ty::{
self, Binder, BoundTy, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
TypeVisitableExt,
};
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Some sample folders // Some sample folders
@ -129,7 +128,7 @@ where
ty::Bound(debruijn, bound_ty) if debruijn == self.current_index => { ty::Bound(debruijn, bound_ty) if debruijn == self.current_index => {
let ty = self.delegate.replace_ty(bound_ty); let ty = self.delegate.replace_ty(bound_ty);
debug_assert!(!ty.has_vars_bound_above(ty::INNERMOST)); debug_assert!(!ty.has_vars_bound_above(ty::INNERMOST));
ty::fold::shift_vars(self.tcx, ty, self.current_index.as_u32()) ty::shift_vars(self.tcx, ty, self.current_index.as_u32())
} }
_ => { _ => {
if !t.has_vars_bound_at_or_above(self.current_index) { if !t.has_vars_bound_at_or_above(self.current_index) {
@ -169,7 +168,7 @@ where
ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => { ty::ConstKind::Bound(debruijn, bound_const) if debruijn == self.current_index => {
let ct = self.delegate.replace_const(bound_const); let ct = self.delegate.replace_const(bound_const);
debug_assert!(!ct.has_vars_bound_above(ty::INNERMOST)); debug_assert!(!ct.has_vars_bound_above(ty::INNERMOST));
ty::fold::shift_vars(self.tcx, ct, self.current_index.as_u32()) ty::shift_vars(self.tcx, ct, self.current_index.as_u32())
} }
_ => ct.super_fold_with(self), _ => ct.super_fold_with(self),
} }

View File

@ -8,16 +8,16 @@ use std::ptr::NonNull;
use rustc_data_structures::intern::Interned; use rustc_data_structures::intern::Interned;
use rustc_errors::{DiagArgValue, IntoDiagArg}; use rustc_errors::{DiagArgValue, IntoDiagArg};
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_macros::{HashStable, TyDecodable, TyEncodable, TypeFoldable, TypeVisitable, extension}; use rustc_macros::{HashStable, TyDecodable, TyEncodable, extension};
use rustc_serialize::{Decodable, Encodable}; use rustc_serialize::{Decodable, Encodable};
use rustc_type_ir::WithCachedTypeInfo; use rustc_type_ir::WithCachedTypeInfo;
use smallvec::SmallVec; use smallvec::SmallVec;
use crate::ty::codec::{TyDecoder, TyEncoder}; use crate::ty::codec::{TyDecoder, TyEncoder};
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable};
use crate::ty::visit::{TypeVisitable, TypeVisitor, VisitorResult, walk_visitable_list};
use crate::ty::{ use crate::ty::{
self, ClosureArgs, CoroutineArgs, CoroutineClosureArgs, InlineConstArgs, Lift, List, Ty, TyCtxt, self, ClosureArgs, CoroutineArgs, CoroutineClosureArgs, FallibleTypeFolder, InlineConstArgs,
Lift, List, Ty, TyCtxt, TypeFoldable, TypeVisitable, TypeVisitor, VisitorResult,
walk_visitable_list,
}; };
pub type GenericArgKind<'tcx> = rustc_type_ir::GenericArgKind<TyCtxt<'tcx>>; pub type GenericArgKind<'tcx> = rustc_type_ir::GenericArgKind<TyCtxt<'tcx>>;
@ -334,13 +334,13 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for GenericArg<'tcx> {
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for GenericArg<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for GenericArg<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.unpack().encode(e) self.unpack().encode(e)
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for GenericArg<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for GenericArg<'tcx> {
fn decode(d: &mut D) -> GenericArg<'tcx> { fn decode(d: &mut D) -> GenericArg<'tcx> {
GenericArgKind::decode(d).pack() GenericArgKind::decode(d).pack()
} }

View File

@ -68,7 +68,7 @@ pub use self::context::{
CtxtInterners, CurrentGcx, DeducedParamAttrs, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt, CtxtInterners, CurrentGcx, DeducedParamAttrs, Feed, FreeRegionInfo, GlobalCtxt, Lift, TyCtxt,
TyCtxtFeed, tls, TyCtxtFeed, tls,
}; };
pub use self::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder, TypeSuperFoldable}; pub use self::fold::*;
pub use self::instance::{Instance, InstanceKind, ReifyReason, ShortInstance, UnusedGenericParams}; pub use self::instance::{Instance, InstanceKind, ReifyReason, ShortInstance, UnusedGenericParams};
pub use self::list::{List, ListWithCachedTypeInfo}; pub use self::list::{List, ListWithCachedTypeInfo};
pub use self::opaque_types::OpaqueTypeKey; pub use self::opaque_types::OpaqueTypeKey;
@ -98,13 +98,14 @@ pub use self::typeck_results::{
CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, IsIdentity, CanonicalUserType, CanonicalUserTypeAnnotation, CanonicalUserTypeAnnotations, IsIdentity,
Rust2024IncompatiblePatInfo, TypeckResults, UserType, UserTypeAnnotationIndex, UserTypeKind, Rust2024IncompatiblePatInfo, TypeckResults, UserType, UserTypeAnnotationIndex, UserTypeKind,
}; };
pub use self::visit::{TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor}; pub use self::visit::*;
use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason}; use crate::error::{OpaqueHiddenTypeMismatch, TypeMismatchReason};
use crate::metadata::ModChild; use crate::metadata::ModChild;
use crate::middle::privacy::EffectiveVisibilities; use crate::middle::privacy::EffectiveVisibilities;
use crate::mir::{Body, CoroutineLayout}; use crate::mir::{Body, CoroutineLayout};
use crate::query::{IntoQueryParam, Providers}; use crate::query::{IntoQueryParam, Providers};
use crate::ty; use crate::ty;
use crate::ty::codec::{TyDecoder, TyEncoder};
pub use crate::ty::diagnostics::*; pub use crate::ty::diagnostics::*;
use crate::ty::fast_reject::SimplifiedType; use crate::ty::fast_reject::SimplifiedType;
use crate::ty::util::Discr; use crate::ty::util::Discr;
@ -116,7 +117,6 @@ pub mod codec;
pub mod error; pub mod error;
pub mod fast_reject; pub mod fast_reject;
pub mod flags; pub mod flags;
pub mod fold;
pub mod inhabitedness; pub mod inhabitedness;
pub mod layout; pub mod layout;
pub mod normalize_erasing_regions; pub mod normalize_erasing_regions;
@ -126,7 +126,6 @@ pub mod relate;
pub mod significant_drop_order; pub mod significant_drop_order;
pub mod trait_def; pub mod trait_def;
pub mod util; pub mod util;
pub mod visit;
pub mod vtable; pub mod vtable;
pub mod walk; pub mod walk;
@ -138,6 +137,7 @@ mod context;
mod diagnostics; mod diagnostics;
mod elaborate_impl; mod elaborate_impl;
mod erase_regions; mod erase_regions;
mod fold;
mod generic_args; mod generic_args;
mod generics; mod generics;
mod impls_ty; mod impls_ty;
@ -154,6 +154,7 @@ mod structural_impls;
#[allow(hidden_glob_reexports)] #[allow(hidden_glob_reexports)]
mod sty; mod sty;
mod typeck_results; mod typeck_results;
mod visit;
// Data types // Data types
@ -442,7 +443,7 @@ impl<'tcx> rustc_type_ir::inherent::IntoKind for Ty<'tcx> {
} }
} }
impl<'tcx> rustc_type_ir::visit::Flags for Ty<'tcx> { impl<'tcx> rustc_type_ir::Flags for Ty<'tcx> {
fn flags(&self) -> TypeFlags { fn flags(&self) -> TypeFlags {
self.0.flags self.0.flags
} }
@ -549,13 +550,13 @@ impl<'tcx> TypeVisitable<TyCtxt<'tcx>> for Term<'tcx> {
} }
} }
impl<'tcx, E: TyEncoder<I = TyCtxt<'tcx>>> Encodable<E> for Term<'tcx> { impl<'tcx, E: TyEncoder<'tcx>> Encodable<E> for Term<'tcx> {
fn encode(&self, e: &mut E) { fn encode(&self, e: &mut E) {
self.unpack().encode(e) self.unpack().encode(e)
} }
} }
impl<'tcx, D: TyDecoder<I = TyCtxt<'tcx>>> Decodable<D> for Term<'tcx> { impl<'tcx, D: TyDecoder<'tcx>> Decodable<D> for Term<'tcx> {
fn decode(d: &mut D) -> Self { fn decode(d: &mut D) -> Self {
let res: TermKind<'tcx> = Decodable::decode(d); let res: TermKind<'tcx> = Decodable::decode(d);
res.pack() res.pack()
@ -938,7 +939,7 @@ impl rustc_type_ir::inherent::PlaceholderLike for PlaceholderConst {
pub type Clauses<'tcx> = &'tcx ListWithCachedTypeInfo<Clause<'tcx>>; pub type Clauses<'tcx> = &'tcx ListWithCachedTypeInfo<Clause<'tcx>>;
impl<'tcx> rustc_type_ir::visit::Flags for Clauses<'tcx> { impl<'tcx> rustc_type_ir::Flags for Clauses<'tcx> {
fn flags(&self) -> TypeFlags { fn flags(&self) -> TypeFlags {
(**self).flags() (**self).flags()
} }

View File

@ -11,8 +11,10 @@ use rustc_macros::{HashStable, TyDecodable, TyEncodable};
use tracing::{debug, instrument}; use tracing::{debug, instrument};
use crate::traits::query::NoSolution; use crate::traits::query::NoSolution;
use crate::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeFolder}; use crate::ty::{
use crate::ty::{self, EarlyBinder, GenericArgsRef, Ty, TyCtxt, TypeVisitableExt}; self, EarlyBinder, FallibleTypeFolder, GenericArgsRef, Ty, TyCtxt, TypeFoldable, TypeFolder,
TypeVisitableExt,
};
#[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)] #[derive(Debug, Copy, Clone, HashStable, TyEncodable, TyDecodable)]
pub enum NormalizationError<'tcx> { pub enum NormalizationError<'tcx> {

View File

@ -4,8 +4,9 @@ use rustc_span::def_id::DefId;
use tracing::{debug, instrument, trace}; use tracing::{debug, instrument, trace};
use crate::error::ConstNotUsedTraitAlias; use crate::error::ConstNotUsedTraitAlias;
use crate::ty::fold::{TypeFolder, TypeSuperFoldable}; use crate::ty::{
use crate::ty::{self, GenericArg, GenericArgKind, Ty, TyCtxt, TypeFoldable}; self, GenericArg, GenericArgKind, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable,
};
pub type OpaqueTypeKey<'tcx> = rustc_type_ir::OpaqueTypeKey<TyCtxt<'tcx>>; pub type OpaqueTypeKey<'tcx> = rustc_type_ir::OpaqueTypeKey<TyCtxt<'tcx>>;

Some files were not shown because too many files have changed in this diff Show More