diff options
| author | bors <bors@rust-lang.org> | 2023-02-26 17:17:25 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2023-02-26 17:17:25 +0000 |
| commit | 56ac6bfc87cce22feffc079c0540c8774b00a5ca (patch) | |
| tree | e430c91fb4e29070945f79df7a47639e5cf4f9b1 /compiler/rustc_ty_utils | |
| parent | ffd12f67cfa28891bbd1fa81d5e80a128f346ace (diff) | |
| parent | cb45103358c0fef99d7659e0949b3c65b3eabdd6 (diff) | |
| download | rust-56ac6bfc87cce22feffc079c0540c8774b00a5ca.tar.gz rust-56ac6bfc87cce22feffc079c0540c8774b00a5ca.zip | |
Auto merge of #2803 - RalfJung:rustup, r=RalfJung
Rustup
Diffstat (limited to 'compiler/rustc_ty_utils')
| -rw-r--r-- | compiler/rustc_ty_utils/locales/en-US.ftl | 47 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/abi.rs | 12 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/assoc.rs | 103 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/consts.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/errors.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/implied_bounds.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/instance.rs | 2 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/layout.rs | 42 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/lib.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/needs_drop.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_ty_utils/src/ty.rs | 19 |
11 files changed, 195 insertions, 50 deletions
diff --git a/compiler/rustc_ty_utils/locales/en-US.ftl b/compiler/rustc_ty_utils/locales/en-US.ftl new file mode 100644 index 00000000000..abe65a0e3fe --- /dev/null +++ b/compiler/rustc_ty_utils/locales/en-US.ftl @@ -0,0 +1,47 @@ +ty_utils_needs_drop_overflow = overflow while checking whether `{$query_ty}` requires drop + +ty_utils_generic_constant_too_complex = overly complex generic constant + .help = consider moving this anonymous constant into a `const` function + .maybe_supported = this operation may be supported in the future + +ty_utils_borrow_not_supported = borrowing is not supported in generic constants + +ty_utils_address_and_deref_not_supported = dereferencing or taking the address is not supported in generic constants + +ty_utils_array_not_supported = array construction is not supported in generic constants + +ty_utils_block_not_supported = blocks are not supported in generic constants + +ty_utils_never_to_any_not_supported = converting nevers to any is not supported in generic constants + +ty_utils_tuple_not_supported = tuple construction is not supported in generic constants + +ty_utils_index_not_supported = indexing is not supported in generic constants + +ty_utils_field_not_supported = field access is not supported in generic constants + +ty_utils_const_block_not_supported = const blocks are not supported in generic constants + +ty_utils_adt_not_supported = struct/enum construction is not supported in generic constants + +ty_utils_pointer_not_supported = pointer casts are not allowed in generic constants + +ty_utils_yield_not_supported = generator control flow is not allowed in generic constants + +ty_utils_loop_not_supported = loops and loop control flow are not supported in generic constants + +ty_utils_box_not_supported = allocations are not allowed in generic constants + +ty_utils_binary_not_supported = unsupported binary operation in generic constants + +ty_utils_logical_op_not_supported = unsupported operation in generic constants, short-circuiting operations would imply control flow + +ty_utils_assign_not_supported = assignment is not supported in generic constants + +ty_utils_closure_and_return_not_supported = closures and function keywords are not supported in generic constants + +ty_utils_control_flow_not_supported = control flow is not supported in generic constants + +ty_utils_inline_asm_not_supported = assembly is not supported in generic constants + +ty_utils_operation_not_supported = unsupported operation in generic constants diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 41924dc2a6d..35c9f95eb03 100644 --- a/compiler/rustc_ty_utils/src/abi.rs +++ b/compiler/rustc_ty_utils/src/abi.rs @@ -54,7 +54,7 @@ fn fn_sig_for_fn_abi<'tcx>( sig = sig.map_bound(|mut sig| { let mut inputs_and_output = sig.inputs_and_output.to_vec(); inputs_and_output[0] = tcx.mk_mut_ptr(inputs_and_output[0]); - sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output); + sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output); sig }); } @@ -63,7 +63,7 @@ fn fn_sig_for_fn_abi<'tcx>( ty::Closure(def_id, substs) => { let sig = substs.as_closure().sig(); - let bound_vars = tcx.mk_bound_variable_kinds( + let bound_vars = tcx.mk_bound_variable_kinds_from_iter( sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), ); let br = ty::BoundRegion { @@ -88,7 +88,7 @@ fn fn_sig_for_fn_abi<'tcx>( ty::Generator(did, substs, _) => { let sig = substs.as_generator().poly_sig(); - let bound_vars = tcx.mk_bound_variable_kinds( + let bound_vars = tcx.mk_bound_variable_kinds_from_iter( sig.bound_vars().iter().chain(iter::once(ty::BoundVariableKind::Region(ty::BrEnv))), ); let br = ty::BoundRegion { @@ -99,7 +99,7 @@ fn fn_sig_for_fn_abi<'tcx>( let pin_did = tcx.require_lang_item(LangItem::Pin, None); let pin_adt_ref = tcx.adt_def(pin_did); - let pin_substs = tcx.intern_substs(&[env_ty.into()]); + let pin_substs = tcx.mk_substs(&[env_ty.into()]); let env_ty = tcx.mk_adt(pin_adt_ref, pin_substs); let sig = sig.skip_binder(); @@ -111,7 +111,7 @@ fn fn_sig_for_fn_abi<'tcx>( // The signature should be `Future::poll(_, &mut Context<'_>) -> Poll<Output>` let poll_did = tcx.require_lang_item(LangItem::Poll, None); let poll_adt_ref = tcx.adt_def(poll_did); - let poll_substs = tcx.intern_substs(&[sig.return_ty.into()]); + let poll_substs = tcx.mk_substs(&[sig.return_ty.into()]); let ret_ty = tcx.mk_adt(poll_adt_ref, poll_substs); // We have to replace the `ResumeTy` that is used for type and borrow checking @@ -133,7 +133,7 @@ fn fn_sig_for_fn_abi<'tcx>( // The signature should be `Generator::resume(_, Resume) -> GeneratorState<Yield, Return>` let state_did = tcx.require_lang_item(LangItem::GeneratorState, None); let state_adt_ref = tcx.adt_def(state_did); - let state_substs = tcx.intern_substs(&[sig.yield_ty.into(), sig.return_ty.into()]); + let state_substs = tcx.mk_substs(&[sig.yield_ty.into(), sig.return_ty.into()]); let ret_ty = tcx.mk_adt(state_adt_ref, state_substs); (sig.resume_ty, ret_ty) diff --git a/compiler/rustc_ty_utils/src/assoc.rs b/compiler/rustc_ty_utils/src/assoc.rs index 164cac6a010..d4866b5dbdd 100644 --- a/compiler/rustc_ty_utils/src/assoc.rs +++ b/compiler/rustc_ty_utils/src/assoc.rs @@ -1,13 +1,18 @@ use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; -use rustc_hir::def_id::DefId; -use rustc_middle::ty::{self, TyCtxt}; +use rustc_hir::def::DefKind; +use rustc_hir::def_id::{DefId, LocalDefId}; +use rustc_hir::definitions::DefPathData; +use rustc_hir::intravisit::{self, Visitor}; +use rustc_middle::ty::{self, DefIdTree, TyCtxt}; pub fn provide(providers: &mut ty::query::Providers) { *providers = ty::query::Providers { associated_item, associated_item_def_ids, associated_items, + associated_items_for_impl_trait_in_trait, + associated_item_for_impl_trait_in_trait, impl_item_implementor_ids, ..*providers }; @@ -112,3 +117,97 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A fn_has_self_parameter: has_self, } } + +/// Given an `fn_def_id` of a trait or of an impl that implements a given trait: +/// if `fn_def_id` is the def id of a function defined inside a trait, then it creates and returns +/// the associated items that correspond to each impl trait in return position for that trait. +/// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it +/// creates and returns the associated items that correspond to each impl trait in return position +/// of the implemented trait. +fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -> &'_ [DefId] { + let parent_def_id = tcx.parent(fn_def_id); + + match tcx.def_kind(parent_def_id) { + DefKind::Trait => { + struct RPITVisitor { + rpits: Vec<LocalDefId>, + } + + impl<'v> Visitor<'v> for RPITVisitor { + fn visit_ty(&mut self, ty: &'v hir::Ty<'v>) { + if let hir::TyKind::OpaqueDef(item_id, _, _) = ty.kind { + self.rpits.push(item_id.owner_id.def_id) + } + intravisit::walk_ty(self, ty) + } + } + + let mut visitor = RPITVisitor { rpits: Vec::new() }; + + if let Some(output) = tcx.hir().get_fn_output(fn_def_id.expect_local()) { + visitor.visit_fn_ret_ty(output); + + tcx.arena.alloc_from_iter(visitor.rpits.iter().map(|opaque_ty_def_id| { + tcx.associated_item_for_impl_trait_in_trait(opaque_ty_def_id).to_def_id() + })) + } else { + &[] + } + } + + DefKind::Impl { .. } => { + let Some(trait_fn_def_id) = tcx.associated_item(fn_def_id).trait_item_def_id else { return &[] }; + + tcx.arena.alloc_from_iter( + tcx.associated_items_for_impl_trait_in_trait(trait_fn_def_id).iter().map( + move |trait_assoc_def_id| { + impl_associated_item_for_impl_trait_in_trait( + tcx, + trait_assoc_def_id.expect_local(), + fn_def_id.expect_local(), + ) + .to_def_id() + }, + ), + ) + } + + def_kind => bug!( + "associated_items_for_impl_trait_in_trait: {:?} should be Trait or Impl but is {:?}", + parent_def_id, + def_kind + ), + } +} + +/// Given an `opaque_ty_def_id` corresponding to an impl trait in trait, create and return the +/// corresponding associated item. +fn associated_item_for_impl_trait_in_trait( + tcx: TyCtxt<'_>, + opaque_ty_def_id: LocalDefId, +) -> LocalDefId { + let fn_def_id = tcx.impl_trait_in_trait_parent(opaque_ty_def_id.to_def_id()); + let trait_def_id = tcx.parent(fn_def_id); + assert_eq!(tcx.def_kind(trait_def_id), DefKind::Trait); + + let span = tcx.def_span(opaque_ty_def_id); + let trait_assoc_ty = + tcx.at(span).create_def(trait_def_id.expect_local(), DefPathData::ImplTraitAssocTy); + trait_assoc_ty.def_id() +} + +/// Given an `trait_assoc_def_id` that corresponds to a previously synthethized impl trait in trait +/// into an associated type and an `impl_def_id` corresponding to an impl block, create and return +/// the corresponding associated item inside the impl block. +fn impl_associated_item_for_impl_trait_in_trait( + tcx: TyCtxt<'_>, + trait_assoc_def_id: LocalDefId, + impl_fn_def_id: LocalDefId, +) -> LocalDefId { + let impl_def_id = tcx.local_parent(impl_fn_def_id); + + let span = tcx.def_span(trait_assoc_def_id); + let impl_assoc_ty = tcx.at(span).create_def(impl_def_id, DefPathData::ImplTraitAssocTy); + + impl_assoc_ty.def_id() +} diff --git a/compiler/rustc_ty_utils/src/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index 852156c24f4..f2635271609 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -5,7 +5,7 @@ use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput}; use rustc_middle::thir::visit; use rustc_middle::thir::visit::Visitor; use rustc_middle::ty::abstract_const::CastKind; -use rustc_middle::ty::{self, Expr, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, Expr, TyCtxt, TypeVisitableExt}; use rustc_middle::{mir, thir}; use rustc_span::Span; use rustc_target::abi::VariantIdx; @@ -144,7 +144,7 @@ fn recurse_build<'tcx>( for &id in args.iter() { new_args.push(recurse_build(tcx, body, id, root_span)?); } - let new_args = tcx.intern_const_list(&new_args); + let new_args = tcx.mk_const_list(&new_args); tcx.mk_const(Expr::FunctionCall(fun, new_args), node.ty) } &ExprKind::Binary { op, lhs, rhs } if check_binop(op) => { diff --git a/compiler/rustc_ty_utils/src/errors.rs b/compiler/rustc_ty_utils/src/errors.rs index c05eeb353a8..ab3e62f0484 100644 --- a/compiler/rustc_ty_utils/src/errors.rs +++ b/compiler/rustc_ty_utils/src/errors.rs @@ -16,7 +16,7 @@ pub struct NeedsDropOverflow<'tcx> { pub struct GenericConstantTooComplex { #[primary_span] pub span: Span, - #[note(maybe_supported)] + #[note(ty_utils_maybe_supported)] pub maybe_supported: Option<()>, #[subdiagnostic] pub sub: GenericConstantTooComplexSub, diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index eb307e66e34..7fecee2a38b 100644 --- a/compiler/rustc_ty_utils/src/implied_bounds.rs +++ b/compiler/rustc_ty_utils/src/implied_bounds.rs @@ -19,16 +19,16 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> { let mut assumed_wf_types: Vec<_> = tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into(); assumed_wf_types.extend(liberated_sig.inputs_and_output); - tcx.intern_type_list(&assumed_wf_types) + tcx.mk_type_list(&assumed_wf_types) } DefKind::Impl { .. } => { match tcx.impl_trait_ref(def_id) { Some(trait_ref) => { let types: Vec<_> = trait_ref.skip_binder().substs.types().collect(); - tcx.intern_type_list(&types) + tcx.mk_type_list(&types) } // Only the impl self type - None => tcx.intern_type_list(&[tcx.type_of(def_id).subst_identity()]), + None => tcx.mk_type_list(&[tcx.type_of(def_id).subst_identity()]), } } DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)), diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index de7230b0cfa..2eaeca73da7 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -3,7 +3,7 @@ use rustc_hir::def_id::{DefId, LocalDefId}; use rustc_infer::infer::TyCtxtInferExt; use rustc_middle::traits::CodegenObligationError; use rustc_middle::ty::subst::SubstsRef; -use rustc_middle::ty::{self, Instance, TyCtxt, TypeVisitable}; +use rustc_middle::ty::{self, Instance, TyCtxt, TypeVisitableExt}; use rustc_span::sym; use rustc_trait_selection::traits; use traits::{translate_substs, Reveal}; diff --git a/compiler/rustc_ty_utils/src/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index 1a62794b0b4..e3132fcc4c4 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -7,7 +7,7 @@ use rustc_middle::ty::layout::{ IntegerExt, LayoutCx, LayoutError, LayoutOf, TyAndLayout, MAX_SIMD_LANES, }; use rustc_middle::ty::{ - self, subst::SubstsRef, AdtDef, EarlyBinder, ReprOptions, Ty, TyCtxt, TypeVisitable, + self, subst::SubstsRef, AdtDef, EarlyBinder, ReprOptions, Ty, TyCtxt, TypeVisitableExt, }; use rustc_session::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo}; use rustc_span::symbol::Symbol; @@ -104,23 +104,23 @@ fn layout_of_uncached<'tcx>( assert!(size.bits() <= 128); Scalar::Initialized { value, valid_range: WrappingRange::full(size) } }; - let scalar = |value: Primitive| tcx.intern_layout(LayoutS::scalar(cx, scalar_unit(value))); + let scalar = |value: Primitive| tcx.mk_layout(LayoutS::scalar(cx, scalar_unit(value))); let univariant = |fields: &[Layout<'_>], repr: &ReprOptions, kind| { - Ok(tcx.intern_layout(univariant_uninterned(cx, ty, fields, repr, kind)?)) + Ok(tcx.mk_layout(univariant_uninterned(cx, ty, fields, repr, kind)?)) }; debug_assert!(!ty.has_non_region_infer()); Ok(match *ty.kind() { // Basic scalars. - ty::Bool => tcx.intern_layout(LayoutS::scalar( + ty::Bool => tcx.mk_layout(LayoutS::scalar( cx, Scalar::Initialized { value: Int(I8, false), valid_range: WrappingRange { start: 0, end: 1 }, }, )), - ty::Char => tcx.intern_layout(LayoutS::scalar( + ty::Char => tcx.mk_layout(LayoutS::scalar( cx, Scalar::Initialized { value: Int(I32, false), @@ -136,11 +136,11 @@ fn layout_of_uncached<'tcx>( ty::FnPtr(_) => { let mut ptr = scalar_unit(Pointer(dl.instruction_address_space)); ptr.valid_range_mut().start = 1; - tcx.intern_layout(LayoutS::scalar(cx, ptr)) + tcx.mk_layout(LayoutS::scalar(cx, ptr)) } // The never type. - ty::Never => tcx.intern_layout(cx.layout_of_never_type()), + ty::Never => tcx.mk_layout(cx.layout_of_never_type()), // Potentially-wide pointers. ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => { @@ -151,7 +151,7 @@ fn layout_of_uncached<'tcx>( let pointee = tcx.normalize_erasing_regions(param_env, pointee); if pointee.is_sized(tcx, param_env) { - return Ok(tcx.intern_layout(LayoutS::scalar(cx, data_ptr))); + return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr))); } let unsized_part = tcx.struct_tail_erasing_lifetimes(pointee, param_env); @@ -164,7 +164,7 @@ fn layout_of_uncached<'tcx>( let metadata_layout = cx.layout_of(metadata_ty)?; // If the metadata is a 1-zst, then the pointer is thin. if metadata_layout.is_zst() && metadata_layout.align.abi.bytes() == 1 { - return Ok(tcx.intern_layout(LayoutS::scalar(cx, data_ptr))); + return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr))); } let Abi::Scalar(metadata) = metadata_layout.abi else { @@ -174,7 +174,7 @@ fn layout_of_uncached<'tcx>( } else { match unsized_part.kind() { ty::Foreign(..) => { - return Ok(tcx.intern_layout(LayoutS::scalar(cx, data_ptr))); + return Ok(tcx.mk_layout(LayoutS::scalar(cx, data_ptr))); } ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)), ty::Dynamic(..) => { @@ -189,7 +189,7 @@ fn layout_of_uncached<'tcx>( }; // Effectively a (ptr, meta) tuple. - tcx.intern_layout(cx.scalar_pair(data_ptr, metadata)) + tcx.mk_layout(cx.scalar_pair(data_ptr, metadata)) } ty::Dynamic(_, _, ty::DynStar) => { @@ -197,7 +197,7 @@ fn layout_of_uncached<'tcx>( data.valid_range_mut().start = 0; let mut vtable = scalar_unit(Pointer(AddressSpace::DATA)); vtable.valid_range_mut().start = 1; - tcx.intern_layout(cx.scalar_pair(data, vtable)) + tcx.mk_layout(cx.scalar_pair(data, vtable)) } // Arrays and slices. @@ -222,7 +222,7 @@ fn layout_of_uncached<'tcx>( let largest_niche = if count != 0 { element.largest_niche } else { None }; - tcx.intern_layout(LayoutS { + tcx.mk_layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields: FieldsShape::Array { stride: element.size, count }, abi, @@ -233,7 +233,7 @@ fn layout_of_uncached<'tcx>( } ty::Slice(element) => { let element = cx.layout_of(element)?; - tcx.intern_layout(LayoutS { + tcx.mk_layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields: FieldsShape::Array { stride: element.size, count: 0 }, abi: Abi::Aggregate { sized: false }, @@ -242,7 +242,7 @@ fn layout_of_uncached<'tcx>( size: Size::ZERO, }) } - ty::Str => tcx.intern_layout(LayoutS { + ty::Str => tcx.mk_layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields: FieldsShape::Array { stride: Size::from_bytes(1), count: 0 }, abi: Abi::Aggregate { sized: false }, @@ -265,7 +265,7 @@ fn layout_of_uncached<'tcx>( Abi::Aggregate { ref mut sized } => *sized = false, _ => bug!(), } - tcx.intern_layout(unit) + tcx.mk_layout(unit) } ty::Generator(def_id, substs, _) => generator_layout(cx, ty, def_id, substs)?, @@ -394,7 +394,7 @@ fn layout_of_uncached<'tcx>( FieldsShape::Array { stride: e_ly.size, count: e_len } }; - tcx.intern_layout(LayoutS { + tcx.mk_layout(LayoutS { variants: Variants::Single { index: VariantIdx::new(0) }, fields, abi: Abi::Vector { element: e_abi, count: e_len }, @@ -427,12 +427,12 @@ fn layout_of_uncached<'tcx>( return Err(LayoutError::Unknown(ty)); } - return Ok(tcx.intern_layout( + return Ok(tcx.mk_layout( cx.layout_of_union(&def.repr(), &variants).ok_or(LayoutError::Unknown(ty))?, )); } - tcx.intern_layout( + tcx.mk_layout( cx.layout_of_struct_or_enum( &def.repr(), &variants, @@ -636,7 +636,7 @@ fn generator_layout<'tcx>( value: Primitive::Int(discr_int, false), valid_range: WrappingRange { start: 0, end: max_discr }, }; - let tag_layout = cx.tcx.intern_layout(LayoutS::scalar(cx, tag)); + let tag_layout = cx.tcx.mk_layout(LayoutS::scalar(cx, tag)); let promoted_layouts = ineligible_locals .iter() @@ -784,7 +784,7 @@ fn generator_layout<'tcx>( Abi::Aggregate { sized: true } }; - let layout = tcx.intern_layout(LayoutS { + let layout = tcx.mk_layout(LayoutS { variants: Variants::Multiple { tag, tag_encoding: TagEncoding::Direct, diff --git a/compiler/rustc_ty_utils/src/lib.rs b/compiler/rustc_ty_utils/src/lib.rs index 0853de601b0..35f468aa952 100644 --- a/compiler/rustc_ty_utils/src/lib.rs +++ b/compiler/rustc_ty_utils/src/lib.rs @@ -15,6 +15,8 @@ extern crate rustc_middle; #[macro_use] extern crate tracing; +use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage}; +use rustc_macros::fluent_messages; use rustc_middle::ty::query::Providers; mod abi; @@ -31,6 +33,8 @@ pub mod representability; mod structural_match; mod ty; +fluent_messages! { "../locales/en-US.ftl" } + pub fn provide(providers: &mut Providers) { abi::provide(providers); assoc::provide(providers); diff --git a/compiler/rustc_ty_utils/src/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index c177d60bb59..de7fd003176 100644 --- a/compiler/rustc_ty_utils/src/needs_drop.rs +++ b/compiler/rustc_ty_utils/src/needs_drop.rs @@ -303,7 +303,7 @@ fn adt_drop_tys<'tcx>( false, ) .collect::<Result<Vec<_>, _>>() - .map(|components| tcx.intern_type_list(&components)) + .map(|components| tcx.mk_type_list(&components)) } // If `def_id` refers to a generic ADT, the queries above and below act as if they had been handed // a `tcx.make_ty(def, identity_substs)` and as such it is legal to substitute the generic parameters @@ -320,7 +320,7 @@ fn adt_significant_drop_tys( true, ) .collect::<Result<Vec<_>, _>>() - .map(|components| tcx.intern_type_list(&components)) + .map(|components| tcx.mk_type_list(&components)) } pub(crate) fn provide(providers: &mut ty::query::Providers) { diff --git a/compiler/rustc_ty_utils/src/ty.rs b/compiler/rustc_ty_utils/src/ty.rs index f1af0073e4d..18159778a8e 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -2,11 +2,9 @@ use rustc_data_structures::fx::{FxHashSet, FxIndexSet}; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_index::bit_set::BitSet; -#[cfg(not(bootstrap))] -use rustc_middle::ty::ir::TypeVisitable; use rustc_middle::ty::{ - self, ir::TypeVisitor, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt, - TypeSuperVisitable, + self, Binder, EarlyBinder, Predicate, PredicateKind, ToPredicate, Ty, TyCtxt, + TypeSuperVisitable, TypeVisitable, TypeVisitor, }; use rustc_session::config::TraitSolver; use rustc_span::def_id::{DefId, CRATE_DEF_ID}; @@ -100,12 +98,12 @@ fn impl_defaultness(tcx: TyCtxt<'_>, def_id: DefId) -> hir::Defaultness { fn adt_sized_constraint(tcx: TyCtxt<'_>, def_id: DefId) -> &[Ty<'_>] { if let Some(def_id) = def_id.as_local() { if matches!(tcx.representability(def_id), ty::Representability::Infinite) { - return tcx.intern_type_list(&[tcx.ty_error()]); + return tcx.mk_type_list(&[tcx.ty_error_misc()]); } } let def = tcx.adt_def(def_id); - let result = tcx.mk_type_list( + let result = tcx.mk_type_list_from_iter( def.variants() .iter() .flat_map(|v| v.fields.last()) @@ -228,11 +226,8 @@ fn param_env(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { None => hir::Constness::NotConst, }; - let unnormalized_env = ty::ParamEnv::new( - tcx.intern_predicates(&predicates), - traits::Reveal::UserFacing, - constness, - ); + let unnormalized_env = + ty::ParamEnv::new(tcx.mk_predicates(&predicates), traits::Reveal::UserFacing, constness); let body_id = local_did.unwrap_or(CRATE_DEF_ID); let cause = traits::ObligationCause::misc(tcx.def_span(def_id), body_id); @@ -388,7 +383,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Predica } }); - tcx.mk_predicates(clauses.chain(input_clauses)) + tcx.mk_predicates_from_iter(clauses.chain(input_clauses)) } fn param_env_reveal_all_normalized(tcx: TyCtxt<'_>, def_id: DefId) -> ty::ParamEnv<'_> { |
