From 29b51cdff36fc52a30d52f86e29e4c7c95eaf92d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Feb 2023 14:24:13 +1100 Subject: [PATCH 1/6] Tweak the slice interners. All the slice interners have a wrapper that handles the empty slice case. We can instead handle this in the `slice_interners!` macro, avoiding the need for most of the wrappers, and allowing the interner functions to be renamed from `_intern_foos` to `intern_foos`. The two exceptions: - intern_predicates: I kept this wrapper because there's a FIXME comment about a possible future change. - intern_poly_existential_predicates: I kept this wrapper because it asserts that the slice is empty and sorted. --- compiler/rustc_middle/src/ty/context.rs | 83 +++++++------------------ 1 file changed, 24 insertions(+), 59 deletions(-) diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 796daa7646f9c..ef1166374999e 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -6,7 +6,7 @@ pub mod tls; use crate::arena::Arena; use crate::dep_graph::{DepGraph, DepKindStruct}; -use crate::infer::canonical::{CanonicalVarInfo, CanonicalVarInfos}; +use crate::infer::canonical::CanonicalVarInfo; use crate::lint::struct_lint_level; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; use crate::middle::resolve_bound_vars; @@ -1565,24 +1565,28 @@ macro_rules! slice_interners { ($($field:ident: $method:ident($ty:ty)),+ $(,)?) => ( impl<'tcx> TyCtxt<'tcx> { $(pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> { - self.interners.$field.intern_ref(v, || { - InternedInSet(List::from_arena(&*self.arena, v)) - }).0 + if v.is_empty() { + List::empty() + } else { + self.interners.$field.intern_ref(v, || { + InternedInSet(List::from_arena(&*self.arena, v)) + }).0 + } })+ } ); } slice_interners!( - const_lists: _intern_const_list(Const<'tcx>), - substs: _intern_substs(GenericArg<'tcx>), - canonical_var_infos: _intern_canonical_var_infos(CanonicalVarInfo<'tcx>), + const_lists: intern_const_list(Const<'tcx>), + substs: intern_substs(GenericArg<'tcx>), + canonical_var_infos: intern_canonical_var_infos(CanonicalVarInfo<'tcx>), poly_existential_predicates: _intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>), predicates: _intern_predicates(Predicate<'tcx>), - projs: _intern_projs(ProjectionKind), - place_elems: _intern_place_elems(PlaceElem<'tcx>), - bound_variable_kinds: _intern_bound_variable_kinds(ty::BoundVariableKind), + projs: intern_projs(ProjectionKind), + place_elems: intern_place_elems(PlaceElem<'tcx>), + bound_variable_kinds: intern_bound_variable_kinds(ty::BoundVariableKind), ); impl<'tcx> TyCtxt<'tcx> { @@ -2152,12 +2156,7 @@ impl<'tcx> TyCtxt<'tcx> { // FIXME consider asking the input slice to be sorted to avoid // re-interning permutations, in which case that would be asserted // here. - if preds.is_empty() { - // The macro-generated method below asserts we don't intern an empty slice. - List::empty() - } else { - self._intern_predicates(preds) - } + self._intern_predicates(preds) } pub fn mk_const_list(self, iter: I) -> T::Output @@ -2168,50 +2167,16 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.intern_const_list(xs)) } - pub fn intern_const_list(self, cs: &[ty::Const<'tcx>]) -> &'tcx List> { - if cs.is_empty() { List::empty() } else { self._intern_const_list(cs) } - } - pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List> { - if ts.is_empty() { - List::empty() - } else { - // Actually intern type lists as lists of `GenericArg`s. - // - // Transmuting from `Ty<'tcx>` to `GenericArg<'tcx>` is sound - // as explained in ty_slice_as_generic_arg`. With this, - // we guarantee that even when transmuting between `List>` - // and `List>`, the uniqueness requirement for - // lists is upheld. - let substs = self._intern_substs(ty::subst::ty_slice_as_generic_args(ts)); - substs.try_as_type_list().unwrap() - } - } - - pub fn intern_substs(self, ts: &[GenericArg<'tcx>]) -> &'tcx List> { - if ts.is_empty() { List::empty() } else { self._intern_substs(ts) } - } - - pub fn intern_projs(self, ps: &[ProjectionKind]) -> &'tcx List { - if ps.is_empty() { List::empty() } else { self._intern_projs(ps) } - } - - pub fn intern_place_elems(self, ts: &[PlaceElem<'tcx>]) -> &'tcx List> { - if ts.is_empty() { List::empty() } else { self._intern_place_elems(ts) } - } - - pub fn intern_canonical_var_infos( - self, - ts: &[CanonicalVarInfo<'tcx>], - ) -> CanonicalVarInfos<'tcx> { - if ts.is_empty() { List::empty() } else { self._intern_canonical_var_infos(ts) } - } - - pub fn intern_bound_variable_kinds( - self, - ts: &[ty::BoundVariableKind], - ) -> &'tcx List { - if ts.is_empty() { List::empty() } else { self._intern_bound_variable_kinds(ts) } + // Actually intern type lists as lists of `GenericArg`s. + // + // Transmuting from `Ty<'tcx>` to `GenericArg<'tcx>` is sound + // as explained in ty_slice_as_generic_arg`. With this, + // we guarantee that even when transmuting between `List>` + // and `List>`, the uniqueness requirement for + // lists is upheld. + let substs = self.intern_substs(ty::subst::ty_slice_as_generic_args(ts)); + substs.try_as_type_list().unwrap() } // Unlike various other `mk_*` functions, this one uses `I: IntoIterator` From 2200911616c3054f0c090db54ea78bdfb666dade Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Fri, 17 Feb 2023 14:33:08 +1100 Subject: [PATCH 2/6] Rename many interner functions. (This is a large commit. The changes to `compiler/rustc_middle/src/ty/context.rs` are the most important ones.) The current naming scheme is a mess, with a mix of `_intern_`, `intern_` and `mk_` prefixes, with little consistency. In particular, in many cases it's easy to use an iterator interner when a (preferable) slice interner is available. The guiding principles of the new naming system: - No `_intern_` prefixes. - The `intern_` prefix is for internal operations. - The `mk_` prefix is for external operations. - For cases where there is a slice interner and an iterator interner, the former is `mk_foo` and the latter is `mk_foo_from_iter`. Also, `slice_interners!` and `direct_interners!` can now be `pub` or non-`pub`, which helps enforce the internal/external operations division. It's not perfect, but I think it's a clear improvement. The following lists show everything that was renamed. slice_interners - const_list - mk_const_list -> mk_const_list_from_iter - intern_const_list -> mk_const_list - substs - mk_substs -> mk_substs_from_iter - intern_substs -> mk_substs - check_substs -> check_and_mk_substs (this is a weird one) - canonical_var_infos - intern_canonical_var_infos -> mk_canonical_var_infos - poly_existential_predicates - mk_poly_existential_predicates -> mk_poly_existential_predicates_from_iter - intern_poly_existential_predicates -> mk_poly_existential_predicates - _intern_poly_existential_predicates -> intern_poly_existential_predicates - predicates - mk_predicates -> mk_predicates_from_iter - intern_predicates -> mk_predicates - _intern_predicates -> intern_predicates - projs - intern_projs -> mk_projs - place_elems - mk_place_elems -> mk_place_elems_from_iter - intern_place_elems -> mk_place_elems - bound_variable_kinds - mk_bound_variable_kinds -> mk_bound_variable_kinds_from_iter - intern_bound_variable_kinds -> mk_bound_variable_kinds direct_interners - region - intern_region (unchanged) - const - mk_const_internal -> intern_const - const_allocation - intern_const_alloc -> mk_const_alloc - layout - intern_layout -> mk_layout - adt_def - intern_adt_def -> mk_adt_def_from_data (unusual case, hard to avoid) - alloc_adt_def(!) -> mk_adt_def - external_constraints - intern_external_constraints -> mk_external_constraints Other - type_list - mk_type_list -> mk_type_list_from_iter - intern_type_list -> mk_type_list - tup - mk_tup -> mk_tup_from_iter - intern_tup -> mk_tup --- .../src/diagnostics/conflict_errors.rs | 2 +- compiler/rustc_borrowck/src/type_check/mod.rs | 2 +- .../rustc_borrowck/src/universal_regions.rs | 12 +- .../rustc_codegen_cranelift/src/abi/mod.rs | 6 +- .../src/codegen_i128.rs | 4 +- .../src/intrinsics/llvm_x86.rs | 2 +- .../rustc_codegen_cranelift/src/main_shim.rs | 4 +- compiler/rustc_codegen_cranelift/src/num.rs | 2 +- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 11 +- .../src/back/symbol_export.rs | 2 +- compiler/rustc_codegen_ssa/src/base.rs | 2 +- compiler/rustc_codegen_ssa/src/mir/block.rs | 4 +- compiler/rustc_codegen_ssa/src/mir/rvalue.rs | 2 +- .../src/const_eval/eval_queries.rs | 2 +- .../rustc_const_eval/src/interpret/intern.rs | 6 +- .../src/interpret/intrinsics.rs | 2 +- .../interpret/intrinsics/caller_location.rs | 2 +- .../src/interpret/operator.rs | 2 +- .../src/interpret/terminator.rs | 3 +- .../src/transform/promote_consts.rs | 2 +- .../src/transform/validate.rs | 2 +- .../rustc_hir_analysis/src/astconv/errors.rs | 2 +- .../src/astconv/generics.rs | 2 +- .../rustc_hir_analysis/src/astconv/mod.rs | 12 +- .../src/check/compare_impl_item.rs | 14 +- .../rustc_hir_analysis/src/check/intrinsic.rs | 8 +- .../rustc_hir_analysis/src/check/wfcheck.rs | 7 +- compiler/rustc_hir_analysis/src/collect.rs | 2 +- .../src/collect/item_bounds.rs | 2 +- compiler/rustc_hir_typeck/src/callee.rs | 2 +- compiler/rustc_hir_typeck/src/closure.rs | 2 +- compiler/rustc_hir_typeck/src/expr.rs | 2 +- .../rustc_hir_typeck/src/fn_ctxt/checks.rs | 4 +- .../src/generator_interior/mod.rs | 4 +- .../rustc_hir_typeck/src/method/suggest.rs | 4 +- compiler/rustc_hir_typeck/src/pat.rs | 6 +- compiler/rustc_hir_typeck/src/upvar.rs | 6 +- .../src/infer/canonical/canonicalizer.rs | 2 +- .../rustc_infer/src/infer/canonical/mod.rs | 2 +- .../src/infer/canonical/query_response.rs | 8 +- .../src/infer/error_reporting/mod.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 6 +- compiler/rustc_metadata/src/native_libs.rs | 2 +- compiler/rustc_metadata/src/rmeta/decoder.rs | 2 +- compiler/rustc_middle/src/infer/canonical.rs | 4 +- compiler/rustc_middle/src/mir/mod.rs | 7 +- compiler/rustc_middle/src/mir/tcx.rs | 6 +- .../rustc_middle/src/mir/type_foldable.rs | 2 +- compiler/rustc_middle/src/mir/visit.rs | 2 +- compiler/rustc_middle/src/traits/solve.rs | 20 ++- compiler/rustc_middle/src/ty/adt.rs | 2 +- compiler/rustc_middle/src/ty/codec.rs | 30 ++-- compiler/rustc_middle/src/ty/context.rs | 134 +++++++++--------- compiler/rustc_middle/src/ty/fold.rs | 2 +- compiler/rustc_middle/src/ty/impls_ty.rs | 2 +- compiler/rustc_middle/src/ty/instance.rs | 2 +- compiler/rustc_middle/src/ty/layout.rs | 8 +- compiler/rustc_middle/src/ty/mod.rs | 2 +- compiler/rustc_middle/src/ty/opaque_types.rs | 2 +- compiler/rustc_middle/src/ty/relate.rs | 15 +- .../rustc_middle/src/ty/structural_impls.rs | 8 +- compiler/rustc_middle/src/ty/sty.rs | 16 +-- compiler/rustc_middle/src/ty/subst.rs | 20 +-- compiler/rustc_middle/src/ty/vtable.rs | 2 +- .../src/build/expr/as_constant.rs | 4 +- .../src/build/expr/as_operand.rs | 2 +- .../src/build/expr/as_place.rs | 4 +- .../src/build/expr/as_rvalue.rs | 2 +- .../rustc_mir_build/src/build/matches/mod.rs | 4 +- compiler/rustc_mir_build/src/build/mod.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/expr.rs | 2 +- compiler/rustc_mir_build/src/thir/cx/mod.rs | 5 +- .../src/move_paths/builder.rs | 6 +- compiler/rustc_mir_transform/src/copy_prop.rs | 2 +- .../src/elaborate_box_derefs.rs | 4 +- compiler/rustc_mir_transform/src/generator.rs | 19 ++- compiler/rustc_mir_transform/src/inline.rs | 2 +- .../rustc_mir_transform/src/instcombine.rs | 2 +- .../rustc_mir_transform/src/large_enums.rs | 7 +- compiler/rustc_mir_transform/src/lib.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 8 +- compiler/rustc_mir_transform/src/sroa.rs | 2 +- compiler/rustc_monomorphize/src/collector.rs | 2 +- .../src/typeid/typeid_itanium_cxx_abi.rs | 4 +- .../rustc_trait_selection/src/solve/mod.rs | 5 +- .../src/solve/trait_goals.rs | 12 +- .../solve/trait_goals/structural_traits.rs | 6 +- .../src/traits/auto_trait.rs | 4 +- .../rustc_trait_selection/src/traits/mod.rs | 9 +- .../src/traits/object_safety.rs | 13 +- .../src/traits/project.rs | 2 +- .../src/traits/select/confirmation.rs | 13 +- .../src/traits/select/mod.rs | 4 +- .../rustc_trait_selection/src/traits/util.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 4 +- compiler/rustc_traits/src/chalk/mod.rs | 4 +- compiler/rustc_ty_utils/src/abi.rs | 12 +- compiler/rustc_ty_utils/src/consts.rs | 2 +- compiler/rustc_ty_utils/src/implied_bounds.rs | 6 +- compiler/rustc_ty_utils/src/layout.rs | 40 +++--- compiler/rustc_ty_utils/src/needs_drop.rs | 4 +- compiler/rustc_ty_utils/src/ty.rs | 13 +- src/tools/clippy/clippy_lints/src/derive.rs | 2 +- .../src/methods/needless_collect.rs | 2 +- .../src/methods/unnecessary_to_owned.rs | 2 +- .../clippy_lints/src/redundant_slicing.rs | 2 +- src/tools/clippy/clippy_utils/src/consts.rs | 4 +- src/tools/clippy/clippy_utils/src/ty.rs | 4 +- src/tools/miri/src/eval.rs | 2 +- .../rust-analyzer/crates/hir-ty/src/layout.rs | 2 +- 111 files changed, 364 insertions(+), 363 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs index 262e093b0fa2a..7a1066f6b5878 100644 --- a/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs @@ -1494,7 +1494,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { assert!(root_place.projection.is_empty()); let proper_span = self.body.local_decls[root_place.local].source_info.span; - let root_place_projection = self.infcx.tcx.intern_place_elems(root_place.projection); + let root_place_projection = self.infcx.tcx.mk_place_elems(root_place.projection); if self.access_place_error_reported.contains(&( Place { local: root_place.local, projection: root_place_projection }, diff --git a/compiler/rustc_borrowck/src/type_check/mod.rs b/compiler/rustc_borrowck/src/type_check/mod.rs index c4e7e1f8ffa30..a49da3da6c013 100644 --- a/compiler/rustc_borrowck/src/type_check/mod.rs +++ b/compiler/rustc_borrowck/src/type_check/mod.rs @@ -2633,7 +2633,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { DefKind::InlineConst => substs.as_inline_const().parent_substs(), other => bug!("unexpected item {:?}", other), }; - let parent_substs = tcx.intern_substs(parent_substs); + let parent_substs = tcx.mk_substs(parent_substs); assert_eq!(typeck_root_substs.len(), parent_substs.len()); if let Err(_) = self.eq_substs( diff --git a/compiler/rustc_borrowck/src/universal_regions.rs b/compiler/rustc_borrowck/src/universal_regions.rs index 3e8731755fc60..e058fe0db222c 100644 --- a/compiler/rustc_borrowck/src/universal_regions.rs +++ b/compiler/rustc_borrowck/src/universal_regions.rs @@ -516,7 +516,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let va_list_ty = self.infcx.tcx.type_of(va_list_did).subst(self.infcx.tcx, &[region.into()]); - unnormalized_input_tys = self.infcx.tcx.mk_type_list( + unnormalized_input_tys = self.infcx.tcx.mk_type_list_from_iter( unnormalized_input_tys.iter().copied().chain(iter::once(va_list_ty)), ); } @@ -656,7 +656,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { assert_eq!(self.mir_def.did.to_def_id(), def_id); let closure_sig = substs.as_closure().sig(); let inputs_and_output = closure_sig.inputs_and_output(); - let bound_vars = tcx.mk_bound_variable_kinds( + let bound_vars = tcx.mk_bound_variable_kinds_from_iter( inputs_and_output .bound_vars() .iter() @@ -680,7 +680,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { }; ty::Binder::bind_with_vars( - tcx.mk_type_list( + tcx.mk_type_list_from_iter( iter::once(closure_ty).chain(inputs).chain(iter::once(output)), ), bound_vars, @@ -693,7 +693,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { let output = substs.as_generator().return_ty(); let generator_ty = tcx.mk_generator(def_id, substs, movability); let inputs_and_output = - self.infcx.tcx.intern_type_list(&[generator_ty, resume_ty, output]); + self.infcx.tcx.mk_type_list(&[generator_ty, resume_ty, output]); ty::Binder::dummy(inputs_and_output) } @@ -709,13 +709,13 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> { assert_eq!(self.mir_def.did.to_def_id(), def_id); let ty = tcx.type_of(self.mir_def.def_id_for_type_of()).subst_identity(); let ty = indices.fold_to_region_vids(tcx, ty); - ty::Binder::dummy(tcx.intern_type_list(&[ty])) + ty::Binder::dummy(tcx.mk_type_list(&[ty])) } DefiningTy::InlineConst(def_id, substs) => { assert_eq!(self.mir_def.did.to_def_id(), def_id); let ty = substs.as_inline_const().ty(); - ty::Binder::dummy(tcx.intern_type_list(&[ty])) + ty::Binder::dummy(tcx.mk_type_list(&[ty])) } } } diff --git a/compiler/rustc_codegen_cranelift/src/abi/mod.rs b/compiler/rustc_codegen_cranelift/src/abi/mod.rs index 3c34585d4191e..74396a66f54e0 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/mod.rs @@ -405,9 +405,9 @@ pub(crate) fn codegen_terminator_call<'tcx>( }; let extra_args = &args[fn_sig.inputs().skip_binder().len()..]; - let extra_args = fx - .tcx - .mk_type_list(extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx)))); + let extra_args = fx.tcx.mk_type_list_from_iter( + extra_args.iter().map(|op_arg| fx.monomorphize(op_arg.ty(fx.mir, fx.tcx))), + ); let fn_abi = if let Some(instance) = instance { RevealAllLayoutCx(fx.tcx).fn_abi_of_instance(instance, extra_args) } else { diff --git a/compiler/rustc_codegen_cranelift/src/codegen_i128.rs b/compiler/rustc_codegen_cranelift/src/codegen_i128.rs index b4a2537b5ea93..40bfe70771c19 100644 --- a/compiler/rustc_codegen_cranelift/src/codegen_i128.rs +++ b/compiler/rustc_codegen_cranelift/src/codegen_i128.rs @@ -56,7 +56,7 @@ pub(crate) fn maybe_codegen<'tcx>( Some(fx.easy_call("__multi3", &[lhs, rhs], val_ty)) } } else { - let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]); + let out_ty = fx.tcx.mk_tup(&[lhs.layout().ty, fx.tcx.types.bool]); let oflow = CPlace::new_stack_slot(fx, fx.layout_of(fx.tcx.types.i32)); let lhs = lhs.load_scalar(fx); let rhs = rhs.load_scalar(fx); @@ -78,7 +78,7 @@ pub(crate) fn maybe_codegen<'tcx>( } BinOp::Add | BinOp::Sub | BinOp::Mul => { assert!(checked); - let out_ty = fx.tcx.intern_tup(&[lhs.layout().ty, fx.tcx.types.bool]); + let out_ty = fx.tcx.mk_tup(&[lhs.layout().ty, fx.tcx.types.bool]); let out_place = CPlace::new_stack_slot(fx, fx.layout_of(out_ty)); let (param_types, args) = if fx.tcx.sess.target.is_like_windows { let (lhs_ptr, lhs_extra) = lhs.force_stack(fx); diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs index cbac2e667652b..e5c4b244a1afd 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs @@ -191,7 +191,7 @@ fn llvm_add_sub<'tcx>( // carry0 | carry1 -> carry or borrow respectively let cb_out = fx.bcx.ins().bor(cb0, cb1); - let layout = fx.layout_of(fx.tcx.intern_tup(&[fx.tcx.types.u8, fx.tcx.types.u64])); + let layout = fx.layout_of(fx.tcx.mk_tup(&[fx.tcx.types.u8, fx.tcx.types.u64])); let val = CValue::by_val_pair(cb_out, c, layout); ret.write_cvalue(fx, val); } diff --git a/compiler/rustc_codegen_cranelift/src/main_shim.rs b/compiler/rustc_codegen_cranelift/src/main_shim.rs index 26327107df4c5..be908df83e8f5 100644 --- a/compiler/rustc_codegen_cranelift/src/main_shim.rs +++ b/compiler/rustc_codegen_cranelift/src/main_shim.rs @@ -119,7 +119,7 @@ pub(crate) fn maybe_create_entry_wrapper( tcx, ParamEnv::reveal_all(), report.def_id, - tcx.intern_substs(&[GenericArg::from(main_ret_ty)]), + tcx.mk_substs(&[GenericArg::from(main_ret_ty)]), ) .unwrap() .unwrap() @@ -146,7 +146,7 @@ pub(crate) fn maybe_create_entry_wrapper( tcx, ParamEnv::reveal_all(), start_def_id, - tcx.intern_substs(&[main_ret_ty.into()]), + tcx.mk_substs(&[main_ret_ty.into()]), ) .unwrap() .unwrap() diff --git a/compiler/rustc_codegen_cranelift/src/num.rs b/compiler/rustc_codegen_cranelift/src/num.rs index 05905a7bcdf30..c058ece96d8e3 100644 --- a/compiler/rustc_codegen_cranelift/src/num.rs +++ b/compiler/rustc_codegen_cranelift/src/num.rs @@ -289,7 +289,7 @@ pub(crate) fn codegen_checked_int_binop<'tcx>( _ => bug!("binop {:?} on checked int/uint lhs: {:?} rhs: {:?}", bin_op, in_lhs, in_rhs), }; - let out_layout = fx.layout_of(fx.tcx.intern_tup(&[in_lhs.layout().ty, fx.tcx.types.bool])); + let out_layout = fx.layout_of(fx.tcx.mk_tup(&[in_lhs.layout().ty, fx.tcx.types.bool])); CValue::by_val_pair(res, has_overflow, out_layout) } diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index 4424b31c0542c..fc746fbd599f2 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -383,7 +383,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> { tcx, ty::ParamEnv::reveal_all(), def_id, - tcx.intern_substs(&[]), + tcx.mk_substs(&[]), ) .unwrap().unwrap(), ), diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 37ee0e14020c3..47dcbba59ac3c 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -520,14 +520,9 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { let tcx = self.tcx; let llfn = match tcx.lang_items().eh_personality() { Some(def_id) if !wants_msvc_seh(self.sess()) => self.get_fn_addr( - ty::Instance::resolve( - tcx, - ty::ParamEnv::reveal_all(), - def_id, - tcx.intern_substs(&[]), - ) - .unwrap() - .unwrap(), + ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, tcx.mk_substs(&[])) + .unwrap() + .unwrap(), ), _ => { let name = if wants_msvc_seh(self.sess()) { diff --git a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs index 11bd47a8f0c79..067a3e167feea 100644 --- a/compiler/rustc_codegen_ssa/src/back/symbol_export.rs +++ b/compiler/rustc_codegen_ssa/src/back/symbol_export.rs @@ -373,7 +373,7 @@ fn upstream_monomorphizations_provider( ExportedSymbol::Generic(def_id, substs) => (def_id, substs), ExportedSymbol::DropGlue(ty) => { if let Some(drop_in_place_fn_def_id) = drop_in_place_fn_def_id { - (drop_in_place_fn_def_id, tcx.intern_substs(&[ty.into()])) + (drop_in_place_fn_def_id, tcx.mk_substs(&[ty.into()])) } else { // `drop_in_place` in place does not exist, don't try // to use it. diff --git a/compiler/rustc_codegen_ssa/src/base.rs b/compiler/rustc_codegen_ssa/src/base.rs index 4e13d4dbcb7a4..73179249bc4d8 100644 --- a/compiler/rustc_codegen_ssa/src/base.rs +++ b/compiler/rustc_codegen_ssa/src/base.rs @@ -476,7 +476,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( cx.tcx(), ty::ParamEnv::reveal_all(), start_def_id, - cx.tcx().intern_substs(&[main_ret_ty.into()]), + cx.tcx().mk_substs(&[main_ret_ty.into()]), ) .unwrap() .unwrap(), diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index cdc3e1dc237b2..f6c1b7a98aae7 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -783,7 +783,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }; let extra_args = &args[sig.inputs().skip_binder().len()..]; - let extra_args = bx.tcx().mk_type_list(extra_args.iter().map(|op_arg| { + let extra_args = bx.tcx().mk_type_list_from_iter(extra_args.iter().map(|op_arg| { let op_ty = op_arg.ty(self.mir, bx.tcx()); self.monomorphize(op_ty) })); @@ -1547,7 +1547,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { slot } else { let layout = cx.layout_of( - cx.tcx().intern_tup(&[cx.tcx().mk_mut_ptr(cx.tcx().types.u8), cx.tcx().types.i32]), + cx.tcx().mk_tup(&[cx.tcx().mk_mut_ptr(cx.tcx().types.u8), cx.tcx().types.i32]), ); let slot = PlaceRef::alloca(bx, layout); self.personality_slot = Some(slot); diff --git a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs index 41cd1c09a4e70..3d856986fb4f7 100644 --- a/compiler/rustc_codegen_ssa/src/mir/rvalue.rs +++ b/compiler/rustc_codegen_ssa/src/mir/rvalue.rs @@ -413,7 +413,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { lhs.layout.ty, ); let val_ty = op.ty(bx.tcx(), lhs.layout.ty, rhs.layout.ty); - let operand_ty = bx.tcx().intern_tup(&[val_ty, bx.tcx().types.bool]); + let operand_ty = bx.tcx().mk_tup(&[val_ty, bx.tcx().types.bool]); OperandRef { val: result, layout: bx.cx().layout_of(operand_ty) } } diff --git a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs index 45f7c75605584..7564ba17b404a 100644 --- a/compiler/rustc_const_eval/src/const_eval/eval_queries.rs +++ b/compiler/rustc_const_eval/src/const_eval/eval_queries.rs @@ -180,7 +180,7 @@ pub(super) fn op_to_const<'tcx>( (ecx.tcx.global_alloc(alloc_id).unwrap_memory(), offset.bytes()) } (None, _offset) => ( - ecx.tcx.intern_const_alloc(Allocation::from_bytes_byte_aligned_immutable( + ecx.tcx.mk_const_alloc(Allocation::from_bytes_byte_aligned_immutable( b"" as &[u8], )), 0, diff --git a/compiler/rustc_const_eval/src/interpret/intern.rs b/compiler/rustc_const_eval/src/interpret/intern.rs index 21ef1836188c0..b220d21f68b72 100644 --- a/compiler/rustc_const_eval/src/interpret/intern.rs +++ b/compiler/rustc_const_eval/src/interpret/intern.rs @@ -135,7 +135,7 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx, const_eval: }; // link the alloc id to the actual allocation leftover_allocations.extend(alloc.provenance().ptrs().iter().map(|&(_, alloc_id)| alloc_id)); - let alloc = tcx.intern_const_alloc(alloc); + let alloc = tcx.mk_const_alloc(alloc); tcx.set_alloc_id_memory(alloc_id, alloc); None } @@ -437,7 +437,7 @@ pub fn intern_const_alloc_recursive< alloc.mutability = Mutability::Not; } } - let alloc = tcx.intern_const_alloc(alloc); + let alloc = tcx.mk_const_alloc(alloc); tcx.set_alloc_id_memory(alloc_id, alloc); for &(_, alloc_id) in alloc.inner().provenance().ptrs().iter() { if leftover_allocations.insert(alloc_id) { @@ -479,6 +479,6 @@ impl<'mir, 'tcx: 'mir, M: super::intern::CompileTimeMachine<'mir, 'tcx, !>> f(self, &dest.into())?; let mut alloc = self.memory.alloc_map.remove(&dest.ptr.provenance.unwrap()).unwrap().1; alloc.mutability = Mutability::Not; - Ok(self.tcx.intern_const_alloc(alloc)) + Ok(self.tcx.mk_const_alloc(alloc)) } } diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index c5d558aeb6ccd..6e47646caeda8 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -45,7 +45,7 @@ fn numeric_intrinsic(name: Symbol, bits: u128, kind: Primitive) -> Scalar< pub(crate) fn alloc_type_name<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ConstAllocation<'tcx> { let path = crate::util::type_name(tcx, ty); let alloc = Allocation::from_bytes_byte_aligned_immutable(path.into_bytes()); - tcx.intern_const_alloc(alloc) + tcx.mk_const_alloc(alloc) } /// The logic for all nullary intrinsics is implemented here. These intrinsics don't get evaluated diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs b/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs index f6a3937870edd..cf52299b7ba82 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics/caller_location.rs @@ -96,7 +96,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let loc_ty = self .tcx .type_of(self.tcx.require_lang_item(LangItem::PanicLocation, None)) - .subst(*self.tcx, self.tcx.intern_substs(&[self.tcx.lifetimes.re_erased.into()])); + .subst(*self.tcx, self.tcx.mk_substs(&[self.tcx.lifetimes.re_erased.into()])); let loc_layout = self.layout_of(loc_ty).unwrap(); let location = self.allocate(loc_layout, MemoryKind::CallerLocation).unwrap(); diff --git a/compiler/rustc_const_eval/src/interpret/operator.rs b/compiler/rustc_const_eval/src/interpret/operator.rs index 422120084d318..4decfe863e634 100644 --- a/compiler/rustc_const_eval/src/interpret/operator.rs +++ b/compiler/rustc_const_eval/src/interpret/operator.rs @@ -19,7 +19,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { ) -> InterpResult<'tcx> { let (val, overflowed, ty) = self.overflowing_binary_op(op, &left, &right)?; debug_assert_eq!( - self.tcx.intern_tup(&[ty, self.tcx.types.bool]), + self.tcx.mk_tup(&[ty, self.tcx.types.bool]), dest.layout.ty, "type mismatch for result of {:?}", op, diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index d934cfbbb84ea..2aea7c79b6d3e 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -73,7 +73,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { let fn_sig = self.tcx.normalize_erasing_late_bound_regions(self.param_env, fn_sig_binder); let extra_args = &args[fn_sig.inputs().len()..]; - let extra_args = self.tcx.mk_type_list(extra_args.iter().map(|arg| arg.layout.ty)); + let extra_args = + self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout.ty)); let (fn_val, fn_abi, with_caller_location) = match *func.layout.ty.kind() { ty::FnPtr(_sig) => { diff --git a/compiler/rustc_const_eval/src/transform/promote_consts.rs b/compiler/rustc_const_eval/src/transform/promote_consts.rs index ba08f5d30d94b..3f3b66b0645a8 100644 --- a/compiler/rustc_const_eval/src/transform/promote_consts.rs +++ b/compiler/rustc_const_eval/src/transform/promote_consts.rs @@ -866,7 +866,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let mut projection = vec![PlaceElem::Deref]; projection.extend(place.projection); - place.projection = tcx.intern_place_elems(&projection); + place.projection = tcx.mk_place_elems(&projection); // Create a temp to hold the promoted reference. // This is because `*r` requires `r` to be a local, diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs index 3af2d0c4e668a..068491646f47b 100644 --- a/compiler/rustc_const_eval/src/transform/validate.rs +++ b/compiler/rustc_const_eval/src/transform/validate.rs @@ -315,7 +315,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> { } } ProjectionElem::Field(f, ty) => { - let parent = Place { local, projection: self.tcx.intern_place_elems(proj_base) }; + let parent = Place { local, projection: self.tcx.mk_place_elems(proj_base) }; let parent_ty = parent.ty(&self.body.local_decls, self.tcx); let fail_out_of_bounds = |this: &Self, location| { this.fail(location, format!("Out of bounds field {:?} for {:?}", f, parent_ty)); diff --git a/compiler/rustc_hir_analysis/src/astconv/errors.rs b/compiler/rustc_hir_analysis/src/astconv/errors.rs index 499b51eef7218..c49e4d9d5818e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/errors.rs +++ b/compiler/rustc_hir_analysis/src/astconv/errors.rs @@ -377,7 +377,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // `::Item = String`. let projection_ty = pred.skip_binder().projection_ty; - let substs_with_infer_self = tcx.mk_substs( + let substs_with_infer_self = tcx.mk_substs_from_iter( std::iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into()) .chain(projection_ty.substs.iter().skip(1)), ); diff --git a/compiler/rustc_hir_analysis/src/astconv/generics.rs b/compiler/rustc_hir_analysis/src/astconv/generics.rs index 630becc09d26e..7f6518ffd7148 100644 --- a/compiler/rustc_hir_analysis/src/astconv/generics.rs +++ b/compiler/rustc_hir_analysis/src/astconv/generics.rs @@ -370,7 +370,7 @@ pub fn create_substs_for_generic_args<'tcx, 'a>( } } - tcx.intern_substs(&substs) + tcx.mk_substs(&substs) } /// Checks that the correct number of generic arguments have been provided. diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 92dc02c8d3f15..49d4860314f30 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -381,7 +381,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { // here and so associated type bindings will be handled regardless of whether there are any // non-`Self` generic parameters. if generics.params.is_empty() { - return (tcx.intern_substs(parent_substs), arg_count); + return (tcx.mk_substs(parent_substs), arg_count); } struct SubstsForAstPathCtxt<'a, 'tcx> { @@ -1529,7 +1529,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { arg }) .collect(); - let substs = tcx.intern_substs(&substs[..]); + let substs = tcx.mk_substs(&substs); let span = i.bottom().1; let empty_generic_args = hir_trait_bounds.iter().any(|hir_bound| { @@ -1591,7 +1591,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { arg }) .collect(); - b.projection_ty.substs = tcx.intern_substs(&substs[..]); + b.projection_ty.substs = tcx.mk_substs(&substs); } ty::ExistentialProjection::erase_self_ty(tcx, b) @@ -1613,7 +1613,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { .collect::>(); v.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder())); v.dedup(); - let existential_predicates = tcx.intern_poly_existential_predicates(&v); + let existential_predicates = tcx.mk_poly_existential_predicates(&v); // Use explicitly-specified region bound. let region_bound = if !lifetime.is_elided() { @@ -3020,7 +3020,9 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { tcx.mk_ref(r, ty::TypeAndMut { ty: t, mutbl: mt.mutbl }) } hir::TyKind::Never => tcx.types.never, - hir::TyKind::Tup(fields) => tcx.mk_tup(fields.iter().map(|t| self.ast_ty_to_ty(t))), + hir::TyKind::Tup(fields) => { + tcx.mk_tup_from_iter(fields.iter().map(|t| self.ast_ty_to_ty(t))) + } hir::TyKind::BareFn(bf) => { require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, ast_ty.span); diff --git a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs index bdc9ff5cada9a..89b4e6227bd61 100644 --- a/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs +++ b/compiler/rustc_hir_analysis/src/check/compare_impl_item.rs @@ -196,7 +196,7 @@ fn compare_method_predicate_entailment<'tcx>( // the new hybrid bounds we computed. let normalize_cause = traits::ObligationCause::misc(impl_m_span, impl_m_def_id); let param_env = ty::ParamEnv::new( - tcx.intern_predicates(&hybrid_preds.predicates), + tcx.mk_predicates(&hybrid_preds.predicates), Reveal::UserFacing, hir::Constness::NotConst, ); @@ -1795,7 +1795,7 @@ fn compare_type_predicate_entailment<'tcx>( let impl_ty_span = tcx.def_span(impl_ty_def_id); let normalize_cause = traits::ObligationCause::misc(impl_ty_span, impl_ty_def_id); let param_env = ty::ParamEnv::new( - tcx.intern_predicates(&hybrid_preds.predicates), + tcx.mk_predicates(&hybrid_preds.predicates), Reveal::UserFacing, hir::Constness::NotConst, ); @@ -1937,8 +1937,8 @@ pub(super) fn check_type_bounds<'tcx>( .into() } }); - let bound_vars = tcx.intern_bound_variable_kinds(&bound_vars); - let impl_ty_substs = tcx.intern_substs(&substs); + let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); + let impl_ty_substs = tcx.mk_substs(&substs); let container_id = impl_ty.container_id(tcx); let rebased_substs = impl_ty_substs.rebase_onto(tcx, container_id, impl_trait_ref.substs); @@ -1978,11 +1978,7 @@ pub(super) fn check_type_bounds<'tcx>( .to_predicate(tcx), ), }; - ty::ParamEnv::new( - tcx.intern_predicates(&predicates), - Reveal::UserFacing, - param_env.constness(), - ) + ty::ParamEnv::new(tcx.mk_predicates(&predicates), Reveal::UserFacing, param_env.constness()) }; debug!(?normalize_param_env); diff --git a/compiler/rustc_hir_analysis/src/check/intrinsic.rs b/compiler/rustc_hir_analysis/src/check/intrinsic.rs index 4720fea8ef4ab..054284cced5ad 100644 --- a/compiler/rustc_hir_analysis/src/check/intrinsic.rs +++ b/compiler/rustc_hir_analysis/src/check/intrinsic.rs @@ -137,7 +137,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { let intrinsic_name = tcx.item_name(intrinsic_id); let name_str = intrinsic_name.as_str(); - let bound_vars = tcx.intern_bound_variable_kinds(&[ + let bound_vars = tcx.mk_bound_variable_kinds(&[ ty::BoundVariableKind::Region(ty::BrAnon(0, None)), ty::BoundVariableKind::Region(ty::BrEnv), ]); @@ -165,7 +165,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { "cxchg" | "cxchgweak" => ( 1, vec![tcx.mk_mut_ptr(param(0)), param(0), param(0)], - tcx.intern_tup(&[param(0), tcx.types.bool]), + tcx.mk_tup(&[param(0), tcx.types.bool]), ), "load" => (1, vec![tcx.mk_imm_ptr(param(0))], param(0)), "store" => (1, vec![tcx.mk_mut_ptr(param(0)), param(0)], tcx.mk_unit()), @@ -317,7 +317,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { | sym::bitreverse => (1, vec![param(0)], param(0)), sym::add_with_overflow | sym::sub_with_overflow | sym::mul_with_overflow => { - (1, vec![param(0), param(0)], tcx.intern_tup(&[param(0), tcx.types.bool])) + (1, vec![param(0), param(0)], tcx.mk_tup(&[param(0), tcx.types.bool])) } sym::ptr_guaranteed_cmp => { @@ -372,7 +372,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) { ( 1, vec![tcx.mk_imm_ref(tcx.mk_re_late_bound(ty::INNERMOST, br), param(0))], - tcx.mk_projection(discriminant_def_id, tcx.intern_substs(&[param(0).into()])), + tcx.mk_projection(discriminant_def_id, tcx.mk_substs(&[param(0).into()])), ) } diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 25be62534a5da..4cccdf30c5fa6 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -493,8 +493,9 @@ fn augment_param_env<'tcx>( return param_env; } - let bounds = - tcx.mk_predicates(param_env.caller_bounds().iter().chain(new_predicates.iter().cloned())); + let bounds = tcx.mk_predicates_from_iter( + param_env.caller_bounds().iter().chain(new_predicates.iter().cloned()), + ); // FIXME(compiler-errors): Perhaps there is a case where we need to normalize this // i.e. traits::normalize_param_env_or_error ty::ParamEnv::new(bounds, param_env.reveal(), param_env.constness()) @@ -1476,7 +1477,7 @@ fn check_fn_or_method<'tcx>( |idx| hir_decl.inputs.get(idx).map_or(hir_decl.output.span(), |arg: &hir::Ty<'_>| arg.span); sig.inputs_and_output = - tcx.mk_type_list(sig.inputs_and_output.iter().enumerate().map(|(idx, ty)| { + tcx.mk_type_list_from_iter(sig.inputs_and_output.iter().enumerate().map(|(idx, ty)| { wfcx.normalize( arg_span(idx), Some(WellFormedLoc::Param { diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index a2900037797c6..604d54cafb532 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -905,7 +905,7 @@ fn adt_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::AdtDef<'_> { } _ => bug!(), }; - tcx.alloc_adt_def(def_id.to_def_id(), kind, variants, repr) + tcx.mk_adt_def(def_id.to_def_id(), kind, variants, repr) } fn trait_def(tcx: TyCtxt<'_>, def_id: DefId) -> ty::TraitDef { diff --git a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs index 8d479f1c3e335..9cf3ff65a91ca 100644 --- a/compiler/rustc_hir_analysis/src/collect/item_bounds.rs +++ b/compiler/rustc_hir_analysis/src/collect/item_bounds.rs @@ -103,7 +103,7 @@ pub(super) fn item_bounds( tcx: TyCtxt<'_>, def_id: DefId, ) -> ty::EarlyBinder<&'_ ty::List>> { - let bounds = tcx.mk_predicates( + let bounds = tcx.mk_predicates_from_iter( util::elaborate_predicates( tcx, tcx.explicit_item_bounds(def_id).iter().map(|&(bound, _span)| bound), diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index fe2f6319c1ad3..6a0d5c01109df 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -232,7 +232,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let Some(trait_def_id) = opt_trait_def_id else { continue }; let opt_input_type = opt_arg_exprs.map(|arg_exprs| { - self.tcx.mk_tup(arg_exprs.iter().map(|e| { + self.tcx.mk_tup_from_iter(arg_exprs.iter().map(|e| { self.next_ty_var(TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span: e.span, diff --git a/compiler/rustc_hir_typeck/src/closure.rs b/compiler/rustc_hir_typeck/src/closure.rs index 6c7004283233a..d84fabb783490 100644 --- a/compiler/rustc_hir_typeck/src/closure.rs +++ b/compiler/rustc_hir_typeck/src/closure.rs @@ -127,7 +127,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // the `closures` table. let sig = bound_sig.map_bound(|sig| { self.tcx.mk_fn_sig( - [self.tcx.intern_tup(sig.inputs())], + [self.tcx.mk_tup(sig.inputs())], sig.output(), sig.c_variadic, sig.unsafety, diff --git a/compiler/rustc_hir_typeck/src/expr.rs b/compiler/rustc_hir_typeck/src/expr.rs index 6d54f6948c8ca..d192d16e8df8b 100644 --- a/compiler/rustc_hir_typeck/src/expr.rs +++ b/compiler/rustc_hir_typeck/src/expr.rs @@ -1492,7 +1492,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } _ => self.check_expr_with_expectation(&e, NoExpectation), }); - let tuple = self.tcx.mk_tup(elt_ts_iter); + let tuple = self.tcx.mk_tup_from_iter(elt_ts_iter); if let Err(guar) = tuple.error_reported() { self.tcx.ty_error(guar) } else { diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs index 99339153de2d6..2e62e13648c95 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs @@ -102,7 +102,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let err_inputs = match tuple_arguments { DontTupleArguments => err_inputs, - TupleArguments => vec![self.tcx.intern_tup(&err_inputs)], + TupleArguments => vec![self.tcx.mk_tup(&err_inputs)], }; self.check_argument_types( @@ -642,7 +642,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { && provided_arg_tys.len() == formal_and_expected_inputs.len() - 1 + tys.len() { // Wrap up the N provided arguments starting at this position in a tuple. - let provided_as_tuple = tcx.mk_tup( + let provided_as_tuple = tcx.mk_tup_from_iter( provided_arg_tys.iter().map(|(ty, _)| *ty).skip(mismatch_idx).take(tys.len()), ); diff --git a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs index e5f9292290ffe..2e41c2041f888 100644 --- a/compiler/rustc_hir_typeck/src/generator_interior/mod.rs +++ b/compiler/rustc_hir_typeck/src/generator_interior/mod.rs @@ -311,8 +311,8 @@ pub fn resolve_interior<'a, 'tcx>( }; // Extract type components to build the witness type. - let type_list = fcx.tcx.mk_type_list(type_causes.iter().map(|cause| cause.ty)); - let bound_vars = fcx.tcx.intern_bound_variable_kinds(&bound_vars); + let type_list = fcx.tcx.mk_type_list_from_iter(type_causes.iter().map(|cause| cause.ty)); + let bound_vars = fcx.tcx.mk_bound_variable_kinds(&bound_vars); let witness = fcx.tcx.mk_generator_witness(ty::Binder::bind_with_vars(type_list, bound_vars.clone())); diff --git a/compiler/rustc_hir_typeck/src/method/suggest.rs b/compiler/rustc_hir_typeck/src/method/suggest.rs index de8b24461b2f2..47a4d4e72dffd 100644 --- a/compiler/rustc_hir_typeck/src/method/suggest.rs +++ b/compiler/rustc_hir_typeck/src/method/suggest.rs @@ -574,7 +574,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // `::Item = String`. let projection_ty = pred.skip_binder().projection_ty; - let substs_with_infer_self = tcx.mk_substs( + let substs_with_infer_self = tcx.mk_substs_from_iter( iter::once(tcx.mk_ty_var(ty::TyVid::from_u32(0)).into()) .chain(projection_ty.substs.iter().skip(1)), ); @@ -1252,7 +1252,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { if let ty::Adt(def, substs) = target_ty.kind() { // If there are any inferred arguments, (`{integer}`), we should replace // them with underscores to allow the compiler to infer them - let infer_substs = self.tcx.mk_substs(substs.into_iter().map(|arg| { + let infer_substs = self.tcx.mk_substs_from_iter(substs.into_iter().map(|arg| { if !arg.is_suggestable(self.tcx, true) { has_unsuggestable_args = true; match arg.unpack() { diff --git a/compiler/rustc_hir_typeck/src/pat.rs b/compiler/rustc_hir_typeck/src/pat.rs index 9d95866fca4ab..c36c75e444368 100644 --- a/compiler/rustc_hir_typeck/src/pat.rs +++ b/compiler/rustc_hir_typeck/src/pat.rs @@ -1302,8 +1302,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { TypeVariableOrigin { kind: TypeVariableOriginKind::TypeInference, span }, ) }); - let element_tys = tcx.mk_type_list(element_tys_iter); - let pat_ty = tcx.intern_tup(element_tys); + let element_tys = tcx.mk_type_list_from_iter(element_tys_iter); + let pat_ty = tcx.mk_tup(element_tys); if let Some(mut err) = self.demand_eqtype_pat_diag(span, expected, pat_ty, ti) { let reported = err.emit(); // Walk subpatterns with an expected type of `err` in this case to silence @@ -1312,7 +1312,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { for (_, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { self.check_pat(elem, tcx.ty_error(reported), def_bm, ti); } - tcx.mk_tup(element_tys_iter) + tcx.mk_tup_from_iter(element_tys_iter) } else { for (i, elem) in elements.iter().enumerate_and_adjust(max_len, ddpos) { self.check_pat(elem, element_tys[i], def_bm, ti); diff --git a/compiler/rustc_hir_typeck/src/upvar.rs b/compiler/rustc_hir_typeck/src/upvar.rs index 7c8abb4186f11..e94915c754e8f 100644 --- a/compiler/rustc_hir_typeck/src/upvar.rs +++ b/compiler/rustc_hir_typeck/src/upvar.rs @@ -301,7 +301,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Build a tuple (U0..Un) of the final upvar types U0..Un // and unify the upvar tuple type in the closure with it: - let final_tupled_upvars_type = self.tcx.intern_tup(&final_upvar_tys); + let final_tupled_upvars_type = self.tcx.mk_tup(&final_upvar_tys); self.demand_suptype(span, substs.tupled_upvars_ty(), final_tupled_upvars_type); let fake_reads = delegate @@ -315,8 +315,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { self.typeck_results.borrow_mut().closure_size_eval.insert( closure_def_id, ClosureSizeProfileData { - before_feature_tys: self.tcx.intern_tup(&before_feature_tys), - after_feature_tys: self.tcx.intern_tup(&after_feature_tys), + before_feature_tys: self.tcx.mk_tup(&before_feature_tys), + after_feature_tys: self.tcx.mk_tup(&after_feature_tys), }, ); } diff --git a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs index f66f6bd4ae1bc..7ffd39de781b4 100644 --- a/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs +++ b/compiler/rustc_infer/src/infer/canonical/canonicalizer.rs @@ -572,7 +572,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> { debug_assert!(!out_value.needs_infer() && !out_value.has_placeholders()); let canonical_variables = - tcx.intern_canonical_var_infos(&canonicalizer.universe_canonicalized_variables()); + tcx.mk_canonical_var_infos(&canonicalizer.universe_canonicalized_variables()); let max_universe = canonical_variables .iter() diff --git a/compiler/rustc_infer/src/infer/canonical/mod.rs b/compiler/rustc_infer/src/infer/canonical/mod.rs index 4053546f00c3d..8c782a933a5ba 100644 --- a/compiler/rustc_infer/src/infer/canonical/mod.rs +++ b/compiler/rustc_infer/src/infer/canonical/mod.rs @@ -88,7 +88,7 @@ impl<'tcx> InferCtxt<'tcx> { universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex, ) -> CanonicalVarValues<'tcx> { CanonicalVarValues { - var_values: self.tcx.mk_substs( + var_values: self.tcx.mk_substs_from_iter( variables .iter() .map(|info| self.instantiate_canonical_var(span, info, &universe_map)), diff --git a/compiler/rustc_infer/src/infer/canonical/query_response.rs b/compiler/rustc_infer/src/infer/canonical/query_response.rs index 07e7589fee43a..832af91a4313c 100644 --- a/compiler/rustc_infer/src/infer/canonical/query_response.rs +++ b/compiler/rustc_infer/src/infer/canonical/query_response.rs @@ -474,8 +474,8 @@ impl<'tcx> InferCtxt<'tcx> { // given variable in the loop above, use that. Otherwise, use // a fresh inference variable. let result_subst = CanonicalVarValues { - var_values: self.tcx.mk_substs(query_response.variables.iter().enumerate().map( - |(index, info)| { + var_values: self.tcx.mk_substs_from_iter( + query_response.variables.iter().enumerate().map(|(index, info)| { if info.is_existential() { match opt_values[BoundVar::new(index)] { Some(k) => k, @@ -488,8 +488,8 @@ impl<'tcx> InferCtxt<'tcx> { universe_map[u.as_usize()] }) } - }, - )), + }), + ), }; let mut obligations = vec![]; diff --git a/compiler/rustc_infer/src/infer/error_reporting/mod.rs b/compiler/rustc_infer/src/infer/error_reporting/mod.rs index 95635405f894d..79efc1ce7bfc0 100644 --- a/compiler/rustc_infer/src/infer/error_reporting/mod.rs +++ b/compiler/rustc_infer/src/infer/error_reporting/mod.rs @@ -925,7 +925,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { ) -> Option<()> { // FIXME/HACK: Go back to `SubstsRef` to use its inherent methods, // ideally that shouldn't be necessary. - let sub = self.tcx.intern_substs(sub); + let sub = self.tcx.mk_substs(sub); for (i, ta) in sub.types().enumerate() { if ta == other_ty { self.highlight_outer(&mut t1_out, &mut t2_out, path, sub, i, other_ty); diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 4da7f3f502f12..45c12d2938fa4 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -677,21 +677,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) + (def, cx.tcx.mk_adt(def, cx.tcx.mk_substs(&[]))) } hir::ItemKind::Union(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) + (def, cx.tcx.mk_adt(def, cx.tcx.mk_substs(&[]))) } hir::ItemKind::Enum(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, cx.tcx.intern_substs(&[]))) + (def, cx.tcx.mk_adt(def, cx.tcx.mk_substs(&[]))) } _ => return, }; diff --git a/compiler/rustc_metadata/src/native_libs.rs b/compiler/rustc_metadata/src/native_libs.rs index d823989bb02b8..5a4d358e5dd62 100644 --- a/compiler/rustc_metadata/src/native_libs.rs +++ b/compiler/rustc_metadata/src/native_libs.rs @@ -502,7 +502,7 @@ impl<'tcx> Collector<'tcx> { .subst_identity() .fn_sig(self.tcx) .inputs() - .map_bound(|slice| self.tcx.intern_type_list(slice)), + .map_bound(|slice| self.tcx.mk_type_list(slice)), ); argument_types diff --git a/compiler/rustc_metadata/src/rmeta/decoder.rs b/compiler/rustc_metadata/src/rmeta/decoder.rs index 3457e51f8e6e9..b1e59b0a470b5 100644 --- a/compiler/rustc_metadata/src/rmeta/decoder.rs +++ b/compiler/rustc_metadata/src/rmeta/decoder.rs @@ -910,7 +910,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { std::iter::once(self.get_variant(&kind, item_id, did)).collect() }; - tcx.alloc_adt_def(did, adt_kind, variants, repr) + tcx.mk_adt_def(did, adt_kind, variants, repr) } fn get_generics(self, item_id: DefIndex, sess: &Session) -> ty::Generics { diff --git a/compiler/rustc_middle/src/infer/canonical.rs b/compiler/rustc_middle/src/infer/canonical.rs index e134ef8489c77..8712514a384c1 100644 --- a/compiler/rustc_middle/src/infer/canonical.rs +++ b/compiler/rustc_middle/src/infer/canonical.rs @@ -47,7 +47,7 @@ impl<'tcx> ty::TypeFoldable> for CanonicalVarInfos<'tcx> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_canonical_var_infos(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk_canonical_var_infos(v)) } } @@ -342,7 +342,7 @@ impl<'tcx> CanonicalVarValues<'tcx> { infos: CanonicalVarInfos<'tcx>, ) -> CanonicalVarValues<'tcx> { CanonicalVarValues { - var_values: tcx.mk_substs(infos.iter().enumerate().map( + var_values: tcx.mk_substs_from_iter(infos.iter().enumerate().map( |(i, info)| -> ty::GenericArg<'tcx> { match info.kind { CanonicalVarKind::Ty(_) | CanonicalVarKind::PlaceholderTy(_) => { diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index ccd8a33386693..7de9800d4c496 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -1620,7 +1620,7 @@ impl<'tcx> Place<'tcx> { &v }; - Place { local: self.local, projection: tcx.intern_place_elems(new_projections) } + Place { local: self.local, projection: tcx.mk_place_elems(new_projections) } } } @@ -2530,13 +2530,14 @@ impl<'tcx> ConstantKind<'tcx> { { InternalSubsts::identity_for_item(tcx, parent_did.to_def_id()) } else { - tcx.intern_substs(&[]) + tcx.mk_substs(&[]) }; debug!(?parent_substs); let did = def.did.to_def_id(); let child_substs = InternalSubsts::identity_for_item(tcx, did); - let substs = tcx.mk_substs(parent_substs.into_iter().chain(child_substs.into_iter())); + let substs = + tcx.mk_substs_from_iter(parent_substs.into_iter().chain(child_substs.into_iter())); debug!(?substs); let hir_id = tcx.hir().local_def_id_to_hir_id(def.did); diff --git a/compiler/rustc_middle/src/mir/tcx.rs b/compiler/rustc_middle/src/mir/tcx.rs index aa9f170477bcb..0aa2c500f51fb 100644 --- a/compiler/rustc_middle/src/mir/tcx.rs +++ b/compiler/rustc_middle/src/mir/tcx.rs @@ -194,14 +194,16 @@ impl<'tcx> Rvalue<'tcx> { let lhs_ty = lhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx); let ty = op.ty(tcx, lhs_ty, rhs_ty); - tcx.intern_tup(&[ty, tcx.types.bool]) + tcx.mk_tup(&[ty, tcx.types.bool]) } Rvalue::UnaryOp(UnOp::Not | UnOp::Neg, ref operand) => operand.ty(local_decls, tcx), Rvalue::Discriminant(ref place) => place.ty(local_decls, tcx).ty.discriminant_ty(tcx), Rvalue::NullaryOp(NullOp::SizeOf | NullOp::AlignOf, _) => tcx.types.usize, Rvalue::Aggregate(ref ak, ref ops) => match **ak { AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64), - AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))), + AggregateKind::Tuple => { + tcx.mk_tup_from_iter(ops.iter().map(|op| op.ty(local_decls, tcx))) + } AggregateKind::Adt(did, _, substs, _, _) => tcx.type_of(did).subst(tcx, substs), AggregateKind::Closure(did, substs) => tcx.mk_closure(did, substs), AggregateKind::Generator(did, substs, movability) => { diff --git a/compiler/rustc_middle/src/mir/type_foldable.rs b/compiler/rustc_middle/src/mir/type_foldable.rs index d0936d950b361..9881583214eb4 100644 --- a/compiler/rustc_middle/src/mir/type_foldable.rs +++ b/compiler/rustc_middle/src/mir/type_foldable.rs @@ -53,6 +53,6 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_place_elems(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk_place_elems(v)) } } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 7f0935fb149fa..5c056b29975c4 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -1045,7 +1045,7 @@ macro_rules! visit_place_fns { self.visit_local(&mut place.local, context, location); if let Some(new_projection) = self.process_projection(&place.projection, location) { - place.projection = self.tcx().intern_place_elems(&new_projection); + place.projection = self.tcx().mk_place_elems(&new_projection); } } diff --git a/compiler/rustc_middle/src/traits/solve.rs b/compiler/rustc_middle/src/traits/solve.rs index aadbce9e2ff3f..c5bf9717f036a 100644 --- a/compiler/rustc_middle/src/traits/solve.rs +++ b/compiler/rustc_middle/src/traits/solve.rs @@ -30,20 +30,18 @@ impl<'tcx> TypeFoldable> for ExternalConstraints<'tcx> { self, folder: &mut F, ) -> Result { - Ok(FallibleTypeFolder::interner(folder).intern_external_constraints( - ExternalConstraintsData { - regions: (), - opaque_types: self - .opaque_types - .iter() - .map(|opaque| opaque.try_fold_with(folder)) - .collect::>()?, - }, - )) + Ok(FallibleTypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData { + regions: (), + opaque_types: self + .opaque_types + .iter() + .map(|opaque| opaque.try_fold_with(folder)) + .collect::>()?, + })) } fn fold_with>>(self, folder: &mut F) -> Self { - TypeFolder::interner(folder).intern_external_constraints(ExternalConstraintsData { + TypeFolder::interner(folder).mk_external_constraints(ExternalConstraintsData { regions: (), opaque_types: self.opaque_types.iter().map(|opaque| opaque.fold_with(folder)).collect(), }) diff --git a/compiler/rustc_middle/src/ty/adt.rs b/compiler/rustc_middle/src/ty/adt.rs index f127b6275a21d..ec21030b3024d 100644 --- a/compiler/rustc_middle/src/ty/adt.rs +++ b/compiler/rustc_middle/src/ty/adt.rs @@ -54,7 +54,7 @@ bitflags! { /// The definition of a user-defined type, e.g., a `struct`, `enum`, or `union`. /// -/// These are all interned (by `alloc_adt_def`) into the global arena. +/// These are all interned (by `mk_adt_def`) into the global arena. /// /// The initialism *ADT* stands for an [*algebraic data type (ADT)*][adt]. /// This is slightly wrong because `union`s are not ADTs. diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index b9a1e23879cca..7ded1b6b42c79 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -244,7 +244,7 @@ impl<'tcx, D: TyDecoder>> Decodable for SubstsRef<'tcx> { fn decode(decoder: &mut D) -> Self { let len = decoder.read_usize(); let tcx = decoder.interner(); - tcx.mk_substs( + tcx.mk_substs_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ) } @@ -254,7 +254,7 @@ impl<'tcx, D: TyDecoder>> Decodable for mir::Place<'tcx> { fn decode(decoder: &mut D) -> Self { let local: mir::Local = Decodable::decode(decoder); let len = decoder.read_usize(); - let projection = decoder.interner().mk_place_elems( + let projection = decoder.interner().mk_place_elems_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ); mir::Place { local, projection } @@ -272,7 +272,7 @@ impl<'tcx, D: TyDecoder>> Decodable for CanonicalVarInfos<'t let len = decoder.read_usize(); let interned: Vec> = (0..len).map(|_| Decodable::decode(decoder)).collect(); - decoder.interner().intern_canonical_var_infos(interned.as_slice()) + decoder.interner().mk_canonical_var_infos(&interned) } } @@ -310,7 +310,9 @@ macro_rules! impl_decodable_via_ref { impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for ty::List> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder.interner().mk_type_list((0..len).map::, _>(|_| Decodable::decode(decoder))) + decoder + .interner() + .mk_type_list_from_iter((0..len).map::, _>(|_| Decodable::decode(decoder))) } } @@ -319,7 +321,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder.interner().mk_poly_existential_predicates( + decoder.interner().mk_poly_existential_predicates_from_iter( (0..len).map::, _>(|_| Decodable::decode(decoder)), ) } @@ -342,13 +344,13 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for [ty::ValTre impl<'tcx, D: TyDecoder>> Decodable for ConstAllocation<'tcx> { fn decode(decoder: &mut D) -> Self { - decoder.interner().intern_const_alloc(Decodable::decode(decoder)) + decoder.interner().mk_const_alloc(Decodable::decode(decoder)) } } impl<'tcx, D: TyDecoder>> Decodable for AdtDef<'tcx> { fn decode(decoder: &mut D) -> Self { - decoder.interner().intern_adt_def(Decodable::decode(decoder)) + decoder.interner().mk_adt_def_from_data(Decodable::decode(decoder)) } } @@ -375,7 +377,7 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder.interner().mk_bound_variable_kinds( + decoder.interner().mk_bound_variable_kinds_from_iter( (0..len).map::(|_| Decodable::decode(decoder)), ) } @@ -384,18 +386,18 @@ impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for ty::List> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - decoder - .interner() - .mk_const_list((0..len).map::, _>(|_| Decodable::decode(decoder))) + decoder.interner().mk_const_list_from_iter( + (0..len).map::, _>(|_| Decodable::decode(decoder)), + ) } } impl<'tcx, D: TyDecoder>> RefDecodable<'tcx, D> for ty::List> { fn decode(decoder: &mut D) -> &'tcx Self { let len = decoder.read_usize(); - let predicates: Vec<_> = - (0..len).map::, _>(|_| Decodable::decode(decoder)).collect(); - decoder.interner().intern_predicates(&predicates) + decoder.interner().mk_predicates_from_iter( + (0..len).map::, _>(|_| Decodable::decode(decoder)), + ) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index ef1166374999e..6a76a55e4ad72 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -177,7 +177,7 @@ impl<'tcx> CtxtInterners<'tcx> { } } - /// Interns a type. + /// Interns a type. (Use `mk_*` functions instead, where possible.) #[allow(rustc::usage_of_ty_tykind)] #[inline(never)] fn intern_ty(&self, kind: TyKind<'tcx>, sess: &Session, untracked: &Untracked) -> Ty<'tcx> { @@ -217,6 +217,7 @@ impl<'tcx> CtxtInterners<'tcx> { } } + /// Interns a predicate. (Use `mk_predicate` instead, where possible.) #[inline(never)] fn intern_predicate( &self, @@ -615,21 +616,21 @@ impl<'tcx> TyCtxt<'tcx> { self.arena.alloc(Steal::new(promoted)) } - pub fn alloc_adt_def( + pub fn mk_adt_def( self, did: DefId, kind: AdtKind, variants: IndexVec, repr: ReprOptions, ) -> ty::AdtDef<'tcx> { - self.intern_adt_def(ty::AdtDefData::new(self, did, kind, variants, repr)) + self.mk_adt_def_from_data(ty::AdtDefData::new(self, did, kind, variants, repr)) } /// Allocates a read-only byte or string literal for `mir::interpret`. pub fn allocate_bytes(self, bytes: &[u8]) -> interpret::AllocId { // Create an allocation that just contains these bytes. let alloc = interpret::Allocation::from_bytes_byte_aligned_immutable(bytes); - let alloc = self.intern_const_alloc(alloc); + let alloc = self.mk_const_alloc(alloc); self.create_memory_alloc(alloc) } @@ -1194,7 +1195,7 @@ impl<'tcx> TyCtxt<'tcx> { self.mk_imm_ref( self.lifetimes.re_static, self.type_of(self.require_lang_item(LangItem::PanicLocation, None)) - .subst(self, self.intern_substs(&[self.lifetimes.re_static.into()])), + .subst(self, self.mk_substs(&[self.lifetimes.re_static.into()])), ) } @@ -1276,7 +1277,7 @@ macro_rules! nop_lift { // Can't use the macros as we have reuse the `substs` here. // -// See `intern_type_list` for more info. +// See `mk_type_list` for more info. impl<'a, 'tcx> Lift<'tcx> for &'a List> { type Lifted = &'tcx List>; fn lift_to_tcx(self, tcx: TyCtxt<'tcx>) -> Option { @@ -1517,7 +1518,7 @@ impl<'tcx, T: Hash> Hash for InternedInSet<'tcx, List> { } macro_rules! direct_interners { - ($($name:ident: $method:ident($ty:ty): $ret_ctor:ident -> $ret_ty:ty,)+) => { + ($($name:ident: $vis:vis $method:ident($ty:ty): $ret_ctor:ident -> $ret_ty:ty,)+) => { $(impl<'tcx> Borrow<$ty> for InternedInSet<'tcx, $ty> { fn borrow<'a>(&'a self) -> &'a $ty { &self.0 @@ -1543,7 +1544,7 @@ macro_rules! direct_interners { } impl<'tcx> TyCtxt<'tcx> { - pub fn $method(self, v: $ty) -> $ret_ty { + $vis fn $method(self, v: $ty) -> $ret_ty { $ret_ctor(Interned::new_unchecked(self.interners.$name.intern(v, |v| { InternedInSet(self.interners.arena.alloc(v)) }).0)) @@ -1552,19 +1553,23 @@ macro_rules! direct_interners { } } +// Functions with a `mk_` prefix are intended for use outside this file and +// crate. Functions with an `intern_` prefix are intended for use within this +// file only, and have a corresponding `mk_` function. direct_interners! { region: intern_region(RegionKind<'tcx>): Region -> Region<'tcx>, - const_: mk_const_internal(ConstData<'tcx>): Const -> Const<'tcx>, - const_allocation: intern_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, - layout: intern_layout(LayoutS): Layout -> Layout<'tcx>, - adt_def: intern_adt_def(AdtDefData): AdtDef -> AdtDef<'tcx>, - external_constraints: intern_external_constraints(ExternalConstraintsData<'tcx>): ExternalConstraints -> ExternalConstraints<'tcx>, + const_: intern_const(ConstData<'tcx>): Const -> Const<'tcx>, + const_allocation: pub mk_const_alloc(Allocation): ConstAllocation -> ConstAllocation<'tcx>, + layout: pub mk_layout(LayoutS): Layout -> Layout<'tcx>, + adt_def: pub mk_adt_def_from_data(AdtDefData): AdtDef -> AdtDef<'tcx>, + external_constraints: pub mk_external_constraints(ExternalConstraintsData<'tcx>): + ExternalConstraints -> ExternalConstraints<'tcx>, } macro_rules! slice_interners { - ($($field:ident: $method:ident($ty:ty)),+ $(,)?) => ( + ($($field:ident: $vis:vis $method:ident($ty:ty)),+ $(,)?) => ( impl<'tcx> TyCtxt<'tcx> { - $(pub fn $method(self, v: &[$ty]) -> &'tcx List<$ty> { + $($vis fn $method(self, v: &[$ty]) -> &'tcx List<$ty> { if v.is_empty() { List::empty() } else { @@ -1577,16 +1582,18 @@ macro_rules! slice_interners { ); } +// These functions intern slices. They all have a corresponding +// `mk_foo_from_iter` function that interns an iterator. The slice version +// should be used when possible, because it's faster. slice_interners!( - const_lists: intern_const_list(Const<'tcx>), - substs: intern_substs(GenericArg<'tcx>), - canonical_var_infos: intern_canonical_var_infos(CanonicalVarInfo<'tcx>), - poly_existential_predicates: - _intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>), - predicates: _intern_predicates(Predicate<'tcx>), - projs: intern_projs(ProjectionKind), - place_elems: intern_place_elems(PlaceElem<'tcx>), - bound_variable_kinds: intern_bound_variable_kinds(ty::BoundVariableKind), + const_lists: pub mk_const_list(Const<'tcx>), + substs: pub mk_substs(GenericArg<'tcx>), + canonical_var_infos: pub mk_canonical_var_infos(CanonicalVarInfo<'tcx>), + poly_existential_predicates: intern_poly_existential_predicates(PolyExistentialPredicate<'tcx>), + predicates: intern_predicates(Predicate<'tcx>), + projs: pub mk_projs(ProjectionKind), + place_elems: pub mk_place_elems(PlaceElem<'tcx>), + bound_variable_kinds: pub mk_bound_variable_kinds(ty::BoundVariableKind), ); impl<'tcx> TyCtxt<'tcx> { @@ -1834,16 +1841,16 @@ impl<'tcx> TyCtxt<'tcx> { } #[inline] - pub fn intern_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> { - if ts.is_empty() { self.types.unit } else { self.mk_ty(Tuple(self.intern_type_list(&ts))) } + pub fn mk_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> { + if ts.is_empty() { self.types.unit } else { self.mk_ty(Tuple(self.mk_type_list(&ts))) } } - pub fn mk_tup(self, iter: I) -> T::Output + pub fn mk_tup_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply, Ty<'tcx>>, { - T::collect_and_apply(iter, |ts| self.intern_tup(ts)) + T::collect_and_apply(iter, |ts| self.mk_tup(ts)) } #[inline] @@ -1862,12 +1869,12 @@ impl<'tcx> TyCtxt<'tcx> { def_id: DefId, substs: impl IntoIterator>>, ) -> Ty<'tcx> { - let substs = self.check_substs(def_id, substs); + let substs = self.check_and_mk_substs(def_id, substs); self.mk_ty(FnDef(def_id, substs)) } #[inline(always)] - fn check_substs( + fn check_and_mk_substs( self, _def_id: DefId, substs: impl IntoIterator>>, @@ -1883,7 +1890,7 @@ impl<'tcx> TyCtxt<'tcx> { substs.collect::>(), ); } - self.mk_substs(substs) + self.mk_substs_from_iter(substs) } #[inline] @@ -1934,7 +1941,7 @@ impl<'tcx> TyCtxt<'tcx> { pub fn mk_task_context(self) -> Ty<'tcx> { let context_did = self.require_lang_item(LangItem::Context, None); let context_adt_ref = self.adt_def(context_did); - let context_substs = self.intern_substs(&[self.lifetimes.re_erased.into()]); + let context_substs = self.mk_substs(&[self.lifetimes.re_erased.into()]); let context_ty = self.mk_adt(context_adt_ref, context_substs); self.mk_mut_ref(self.lifetimes.re_erased, context_ty) } @@ -1946,7 +1953,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_const(self, kind: impl Into>, ty: Ty<'tcx>) -> Const<'tcx> { - self.mk_const_internal(ty::ConstData { kind: kind.into(), ty }) + self.intern_const(ty::ConstData { kind: kind.into(), ty }) } #[inline] @@ -2136,10 +2143,10 @@ impl<'tcx> TyCtxt<'tcx> { let mut projection = place.projection.to_vec(); projection.push(elem); - Place { local: place.local, projection: self.intern_place_elems(&projection) } + Place { local: place.local, projection: self.mk_place_elems(&projection) } } - pub fn intern_poly_existential_predicates( + pub fn mk_poly_existential_predicates( self, eps: &[PolyExistentialPredicate<'tcx>], ) -> &'tcx List> { @@ -2149,25 +2156,25 @@ impl<'tcx> TyCtxt<'tcx> { .all(|[a, b]| a.skip_binder().stable_cmp(self, &b.skip_binder()) != Ordering::Greater) ); - self._intern_poly_existential_predicates(eps) + self.intern_poly_existential_predicates(eps) } - pub fn intern_predicates(self, preds: &[Predicate<'tcx>]) -> &'tcx List> { + pub fn mk_predicates(self, preds: &[Predicate<'tcx>]) -> &'tcx List> { // FIXME consider asking the input slice to be sorted to avoid // re-interning permutations, in which case that would be asserted // here. - self._intern_predicates(preds) + self.intern_predicates(preds) } - pub fn mk_const_list(self, iter: I) -> T::Output + pub fn mk_const_list_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply, &'tcx List>>, { - T::collect_and_apply(iter, |xs| self.intern_const_list(xs)) + T::collect_and_apply(iter, |xs| self.mk_const_list(xs)) } - pub fn intern_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List> { + pub fn mk_type_list(self, ts: &[Ty<'tcx>]) -> &'tcx List> { // Actually intern type lists as lists of `GenericArg`s. // // Transmuting from `Ty<'tcx>` to `GenericArg<'tcx>` is sound @@ -2175,15 +2182,14 @@ impl<'tcx> TyCtxt<'tcx> { // we guarantee that even when transmuting between `List>` // and `List>`, the uniqueness requirement for // lists is upheld. - let substs = self.intern_substs(ty::subst::ty_slice_as_generic_args(ts)); + let substs = self.mk_substs(ty::subst::ty_slice_as_generic_args(ts)); substs.try_as_type_list().unwrap() } - // Unlike various other `mk_*` functions, this one uses `I: IntoIterator` - // instead of `I: Iterator`. Unlike those other functions, this one doesn't - // have a `intern_fn_sig` variant that can be used for cases where `I` is - // something like a `Vec`. That's because of the need to combine `inputs` - // and `output`. + // Unlike various other `mk_*_from_iter` functions, this one uses `I: + // IntoIterator` instead of `I: Iterator`, and it doesn't have a slice + // variant, because of the need to combine `inputs` and `output`. This + // explains the lack of `_from_iter` suffix. pub fn mk_fn_sig( self, inputs: I, @@ -2197,14 +2203,14 @@ impl<'tcx> TyCtxt<'tcx> { T: CollectAndApply, ty::FnSig<'tcx>>, { T::collect_and_apply(inputs.into_iter().chain(iter::once(output)), |xs| ty::FnSig { - inputs_and_output: self.intern_type_list(xs), + inputs_and_output: self.mk_type_list(xs), c_variadic, unsafety, abi, }) } - pub fn mk_poly_existential_predicates(self, iter: I) -> T::Output + pub fn mk_poly_existential_predicates_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply< @@ -2212,39 +2218,39 @@ impl<'tcx> TyCtxt<'tcx> { &'tcx List>, >, { - T::collect_and_apply(iter, |xs| self.intern_poly_existential_predicates(xs)) + T::collect_and_apply(iter, |xs| self.mk_poly_existential_predicates(xs)) } - pub fn mk_predicates(self, iter: I) -> T::Output + pub fn mk_predicates_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply, &'tcx List>>, { - T::collect_and_apply(iter, |xs| self.intern_predicates(xs)) + T::collect_and_apply(iter, |xs| self.mk_predicates(xs)) } - pub fn mk_type_list(self, iter: I) -> T::Output + pub fn mk_type_list_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply, &'tcx List>>, { - T::collect_and_apply(iter, |xs| self.intern_type_list(xs)) + T::collect_and_apply(iter, |xs| self.mk_type_list(xs)) } - pub fn mk_substs(self, iter: I) -> T::Output + pub fn mk_substs_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply, &'tcx List>>, { - T::collect_and_apply(iter, |xs| self.intern_substs(xs)) + T::collect_and_apply(iter, |xs| self.mk_substs(xs)) } - pub fn mk_place_elems(self, iter: I) -> T::Output + pub fn mk_place_elems_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply, &'tcx List>>, { - T::collect_and_apply(iter, |xs| self.intern_place_elems(xs)) + T::collect_and_apply(iter, |xs| self.mk_place_elems(xs)) } pub fn mk_substs_trait( @@ -2252,7 +2258,7 @@ impl<'tcx> TyCtxt<'tcx> { self_ty: Ty<'tcx>, rest: impl IntoIterator>, ) -> SubstsRef<'tcx> { - self.mk_substs(iter::once(self_ty.into()).chain(rest)) + self.mk_substs_from_iter(iter::once(self_ty.into()).chain(rest)) } pub fn mk_trait_ref( @@ -2260,7 +2266,7 @@ impl<'tcx> TyCtxt<'tcx> { trait_def_id: DefId, substs: impl IntoIterator>>, ) -> ty::TraitRef<'tcx> { - let substs = self.check_substs(trait_def_id, substs); + let substs = self.check_and_mk_substs(trait_def_id, substs); ty::TraitRef { def_id: trait_def_id, substs, _use_mk_trait_ref_instead: () } } @@ -2269,16 +2275,16 @@ impl<'tcx> TyCtxt<'tcx> { def_id: DefId, substs: impl IntoIterator>>, ) -> ty::AliasTy<'tcx> { - let substs = self.check_substs(def_id, substs); + let substs = self.check_and_mk_substs(def_id, substs); ty::AliasTy { def_id, substs, _use_mk_alias_ty_instead: () } } - pub fn mk_bound_variable_kinds(self, iter: I) -> T::Output + pub fn mk_bound_variable_kinds_from_iter(self, iter: I) -> T::Output where I: Iterator, T: CollectAndApply>, { - T::collect_and_apply(iter, |xs| self.intern_bound_variable_kinds(xs)) + T::collect_and_apply(iter, |xs| self.mk_bound_variable_kinds(xs)) } /// Emit a lint at `span` from a lint struct (some type that implements `DecorateLint`, @@ -2363,7 +2369,7 @@ impl<'tcx> TyCtxt<'tcx> { } pub fn late_bound_vars(self, id: HirId) -> &'tcx List { - self.intern_bound_variable_kinds( + self.mk_bound_variable_kinds( &self .late_bound_vars_map(id.owner) .and_then(|map| map.get(&id.local_id).cloned()) diff --git a/compiler/rustc_middle/src/ty/fold.rs b/compiler/rustc_middle/src/ty/fold.rs index e8a73832ce4c0..d66f436f947a3 100644 --- a/compiler/rustc_middle/src/ty/fold.rs +++ b/compiler/rustc_middle/src/ty/fold.rs @@ -422,7 +422,7 @@ impl<'tcx> TyCtxt<'tcx> { let mut map = Default::default(); let delegate = Anonymize { tcx: self, map: &mut map }; let inner = self.replace_escaping_bound_vars_uncached(value.skip_binder(), delegate); - let bound_vars = self.mk_bound_variable_kinds(map.into_values()); + let bound_vars = self.mk_bound_variable_kinds_from_iter(map.into_values()); Binder::bind_with_vars(inner, bound_vars) } } diff --git a/compiler/rustc_middle/src/ty/impls_ty.rs b/compiler/rustc_middle/src/ty/impls_ty.rs index 3e59c0b967c3d..4c7822acdf785 100644 --- a/compiler/rustc_middle/src/ty/impls_ty.rs +++ b/compiler/rustc_middle/src/ty/impls_ty.rs @@ -79,7 +79,7 @@ impl<'a, 'tcx> HashStable> for ty::subst::GenericArgKin // WARNING: We dedup cache the `HashStable` results for `List` // while ignoring types and freely transmute // between `List>` and `List>`. - // See `fn intern_type_list` for more details. + // See `fn mk_type_list` for more details. // // We therefore hash types without adding a hash for their discriminant. // diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index d07fa0e546f34..f4028a5a9f63a 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -540,7 +540,7 @@ impl<'tcx> Instance<'tcx> { pub fn resolve_drop_in_place(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> ty::Instance<'tcx> { let def_id = tcx.require_lang_item(LangItem::DropInPlace, None); - let substs = tcx.intern_substs(&[ty.into()]); + let substs = tcx.mk_substs(&[ty.into()]); Instance::expect_resolve(tcx, ty::ParamEnv::reveal_all(), def_id, substs) } diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 146803df02bcd..6c59cde86e39b 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -596,7 +596,7 @@ where ty::Adt(def, _) => def.variant(variant_index).fields.len(), _ => bug!(), }; - tcx.intern_layout(LayoutS { + tcx.mk_layout(LayoutS { variants: Variants::Single { index: variant_index }, fields: match NonZeroUsize::new(fields) { Some(fields) => FieldsShape::Union(fields), @@ -609,7 +609,7 @@ where }) } - Variants::Multiple { ref variants, .. } => cx.tcx().intern_layout(variants[variant_index].clone()), + Variants::Multiple { ref variants, .. } => cx.tcx().mk_layout(variants[variant_index].clone()), }; assert_eq!(*layout.variants(), Variants::Single { index: variant_index }); @@ -631,7 +631,7 @@ where let tcx = cx.tcx(); let tag_layout = |tag: Scalar| -> TyAndLayout<'tcx> { TyAndLayout { - layout: tcx.intern_layout(LayoutS::scalar(cx, tag)), + layout: tcx.mk_layout(LayoutS::scalar(cx, tag)), ty: tag.primitive().to_ty(tcx), } }; @@ -687,7 +687,7 @@ where Increase this counter if you tried to implement this but failed to do it without duplicating a lot of code from other places in the compiler: 2 - tcx.intern_tup(&[ + tcx.mk_tup(&[ tcx.mk_array(tcx.types.usize, 3), tcx.mk_array(Option), ]) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index c8b1c7f76f40d..17262a0be243c 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -757,7 +757,7 @@ impl<'tcx> Predicate<'tcx> { let new = EarlyBinder(shifted_pred).subst(tcx, trait_ref.skip_binder().substs); // 3) ['x] + ['b] -> ['x, 'b] let bound_vars = - tcx.mk_bound_variable_kinds(trait_bound_vars.iter().chain(pred_bound_vars)); + tcx.mk_bound_variable_kinds_from_iter(trait_bound_vars.iter().chain(pred_bound_vars)); tcx.reuse_or_mk_predicate(self, ty::Binder::bind_with_vars(new, bound_vars)) } } diff --git a/compiler/rustc_middle/src/ty/opaque_types.rs b/compiler/rustc_middle/src/ty/opaque_types.rs index 6463b38c7e19c..751f3066c9cc6 100644 --- a/compiler/rustc_middle/src/ty/opaque_types.rs +++ b/compiler/rustc_middle/src/ty/opaque_types.rs @@ -79,7 +79,7 @@ impl<'tcx> ReverseMapper<'tcx> { // during codegen. let generics = self.tcx.generics_of(def_id); - self.tcx.mk_substs(substs.iter().enumerate().map(|(index, kind)| { + self.tcx.mk_substs_from_iter(substs.iter().enumerate().map(|(index, kind)| { if index < generics.parent_count { // Accommodate missing regions in the parent kinds... self.fold_kind_no_missing_regions_error(kind) diff --git a/compiler/rustc_middle/src/ty/relate.rs b/compiler/rustc_middle/src/ty/relate.rs index 735b87d08e327..3fc5f5bed8fcd 100644 --- a/compiler/rustc_middle/src/ty/relate.rs +++ b/compiler/rustc_middle/src/ty/relate.rs @@ -144,7 +144,7 @@ pub fn relate_substs<'tcx, R: TypeRelation<'tcx>>( a_subst: SubstsRef<'tcx>, b_subst: SubstsRef<'tcx>, ) -> RelateResult<'tcx, SubstsRef<'tcx>> { - relation.tcx().mk_substs(iter::zip(a_subst, b_subst).map(|(a, b)| { + relation.tcx().mk_substs_from_iter(iter::zip(a_subst, b_subst).map(|(a, b)| { relation.relate_with_variance(ty::Invariant, ty::VarianceDiagInfo::default(), a, b) })) } @@ -171,7 +171,7 @@ pub fn relate_substs_with_variances<'tcx, R: TypeRelation<'tcx>>( relation.relate_with_variance(variance, variance_info, a, b) }); - tcx.mk_substs(params) + tcx.mk_substs_from_iter(params) } impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { @@ -222,7 +222,7 @@ impl<'tcx> Relate<'tcx> for ty::FnSig<'tcx> { r => r, }); Ok(ty::FnSig { - inputs_and_output: tcx.mk_type_list(inputs_and_output)?, + inputs_and_output: tcx.mk_type_list_from_iter(inputs_and_output)?, c_variadic: a.c_variadic, unsafety, abi, @@ -352,7 +352,8 @@ impl<'tcx> Relate<'tcx> for GeneratorWitness<'tcx> { ) -> RelateResult<'tcx, GeneratorWitness<'tcx>> { assert_eq!(a.0.len(), b.0.len()); let tcx = relation.tcx(); - let types = tcx.mk_type_list(iter::zip(a.0, b.0).map(|(a, b)| relation.relate(a, b)))?; + let types = + tcx.mk_type_list_from_iter(iter::zip(a.0, b.0).map(|(a, b)| relation.relate(a, b)))?; Ok(GeneratorWitness(types)) } } @@ -528,7 +529,7 @@ pub fn super_relate_tys<'tcx, R: TypeRelation<'tcx>>( (&ty::Tuple(as_), &ty::Tuple(bs)) => { if as_.len() == bs.len() { - Ok(tcx.mk_tup(iter::zip(as_, bs).map(|(a, b)| relation.relate(a, b)))?) + Ok(tcx.mk_tup_from_iter(iter::zip(as_, bs).map(|(a, b)| relation.relate(a, b)))?) } else if !(as_.is_empty() || bs.is_empty()) { Err(TypeError::TupleSize(expected_found(relation, as_.len(), bs.len()))) } else { @@ -673,7 +674,7 @@ pub fn super_relate_consts<'tcx, R: TypeRelation<'tcx>>( for (a_arg, b_arg) in aa.iter().zip(ba.iter()) { related_args.push(r.consts(a_arg, b_arg)?); } - let related_args = tcx.intern_const_list(&related_args); + let related_args = tcx.mk_const_list(&related_args); Expr::FunctionCall(func, related_args) } _ => return Err(TypeError::ConstMismatch(expected_found(r, a, b))), @@ -720,7 +721,7 @@ impl<'tcx> Relate<'tcx> for &'tcx ty::List> { _ => Err(TypeError::ExistentialMismatch(expected_found(relation, a, b))), } }); - tcx.mk_poly_existential_predicates(v) + tcx.mk_poly_existential_predicates_from_iter(v) } } diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index fbe5d8ccff570..43fbccea5cae0 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -430,7 +430,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_poly_existential_predicates(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk_poly_existential_predicates(v)) } } @@ -439,7 +439,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_const_list(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk_const_list(v)) } } @@ -448,7 +448,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_projs(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk_projs(v)) } } @@ -636,7 +636,7 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { self, folder: &mut F, ) -> Result { - ty::util::fold_list(self, folder, |tcx, v| tcx.intern_predicates(v)) + ty::util::fold_list(self, folder, |tcx, v| tcx.mk_predicates(v)) } } diff --git a/compiler/rustc_middle/src/ty/sty.rs b/compiler/rustc_middle/src/ty/sty.rs index 658f09a850d55..ba714541c9e8f 100644 --- a/compiler/rustc_middle/src/ty/sty.rs +++ b/compiler/rustc_middle/src/ty/sty.rs @@ -250,7 +250,7 @@ impl<'tcx> ClosureSubsts<'tcx> { parts: ClosureSubstsParts<'tcx, Ty<'tcx>>, ) -> ClosureSubsts<'tcx> { ClosureSubsts { - substs: tcx.mk_substs( + substs: tcx.mk_substs_from_iter( parts.parent_substs.iter().copied().chain( [parts.closure_kind_ty, parts.closure_sig_as_fn_ptr_ty, parts.tupled_upvars_ty] .iter() @@ -377,7 +377,7 @@ impl<'tcx> GeneratorSubsts<'tcx> { parts: GeneratorSubstsParts<'tcx, Ty<'tcx>>, ) -> GeneratorSubsts<'tcx> { GeneratorSubsts { - substs: tcx.mk_substs( + substs: tcx.mk_substs_from_iter( parts.parent_substs.iter().copied().chain( [ parts.resume_ty, @@ -655,7 +655,7 @@ impl<'tcx> InlineConstSubsts<'tcx> { parts: InlineConstSubstsParts<'tcx, Ty<'tcx>>, ) -> InlineConstSubsts<'tcx> { InlineConstSubsts { - substs: tcx.mk_substs( + substs: tcx.mk_substs_from_iter( parts.parent_substs.iter().copied().chain(std::iter::once(parts.ty.into())), ), } @@ -853,7 +853,7 @@ impl<'tcx> TraitRef<'tcx> { substs: SubstsRef<'tcx>, ) -> ty::TraitRef<'tcx> { let defs = tcx.generics_of(trait_id); - tcx.mk_trait_ref(trait_id, tcx.intern_substs(&substs[..defs.params.len()])) + tcx.mk_trait_ref(trait_id, tcx.mk_substs(&substs[..defs.params.len()])) } } @@ -899,7 +899,7 @@ impl<'tcx> ExistentialTraitRef<'tcx> { ty::ExistentialTraitRef { def_id: trait_ref.def_id, - substs: tcx.intern_substs(&trait_ref.substs[1..]), + substs: tcx.mk_substs(&trait_ref.substs[1..]), } } @@ -1551,7 +1551,7 @@ impl<'tcx> ExistentialProjection<'tcx> { pub fn trait_ref(&self, tcx: TyCtxt<'tcx>) -> ty::ExistentialTraitRef<'tcx> { let def_id = tcx.parent(self.def_id); let subst_count = tcx.generics_of(def_id).count() - 1; - let substs = tcx.intern_substs(&self.substs[..subst_count]); + let substs = tcx.mk_substs(&self.substs[..subst_count]); ty::ExistentialTraitRef { def_id, substs } } @@ -1579,7 +1579,7 @@ impl<'tcx> ExistentialProjection<'tcx> { Self { def_id: projection_predicate.projection_ty.def_id, - substs: tcx.intern_substs(&projection_predicate.projection_ty.substs[1..]), + substs: tcx.mk_substs(&projection_predicate.projection_ty.substs[1..]), term: projection_predicate.term, } } @@ -2209,7 +2209,7 @@ impl<'tcx> Ty<'tcx> { let assoc_items = tcx.associated_item_def_ids( tcx.require_lang_item(hir::LangItem::DiscriminantKind, None), ); - tcx.mk_projection(assoc_items[0], tcx.intern_substs(&[self.into()])) + tcx.mk_projection(assoc_items[0], tcx.mk_substs(&[self.into()])) } ty::Bool diff --git a/compiler/rustc_middle/src/ty/subst.rs b/compiler/rustc_middle/src/ty/subst.rs index 1ed3ef5745b6f..b090bd9d807c5 100644 --- a/compiler/rustc_middle/src/ty/subst.rs +++ b/compiler/rustc_middle/src/ty/subst.rs @@ -71,7 +71,7 @@ impl<'tcx> List> { /// Allows to freely switch between `List>` and `List>`. /// /// As lists are interned, `List>` and `List>` have - /// be interned together, see `intern_type_list` for more details. + /// be interned together, see `mk_type_list` for more details. #[inline] pub fn as_substs(&'tcx self) -> SubstsRef<'tcx> { assert_eq!(TYPE_TAG, 0); @@ -319,7 +319,7 @@ impl<'tcx> InternalSubsts<'tcx> { let count = defs.count(); let mut substs = SmallVec::with_capacity(count); Self::fill_item(&mut substs, tcx, defs, &mut mk_kind); - tcx.intern_substs(&substs) + tcx.mk_substs(&substs) } pub fn extend_to(&self, tcx: TyCtxt<'tcx>, def_id: DefId, mut mk_kind: F) -> SubstsRef<'tcx> @@ -468,11 +468,11 @@ impl<'tcx> InternalSubsts<'tcx> { target_substs: SubstsRef<'tcx>, ) -> SubstsRef<'tcx> { let defs = tcx.generics_of(source_ancestor); - tcx.mk_substs(target_substs.iter().chain(self.iter().skip(defs.params.len()))) + tcx.mk_substs_from_iter(target_substs.iter().chain(self.iter().skip(defs.params.len()))) } pub fn truncate_to(&self, tcx: TyCtxt<'tcx>, generics: &ty::Generics) -> SubstsRef<'tcx> { - tcx.mk_substs(self.iter().take(generics.count())) + tcx.mk_substs_from_iter(self.iter().take(generics.count())) } } @@ -486,14 +486,14 @@ impl<'tcx> TypeFoldable> for SubstsRef<'tcx> { // The match arms are in order of frequency. The 1, 2, and 0 cases are // typically hit in 90--99.99% of cases. When folding doesn't change // the substs, it's faster to reuse the existing substs rather than - // calling `intern_substs`. + // calling `mk_substs`. match self.len() { 1 => { let param0 = self[0].try_fold_with(folder)?; if param0 == self[0] { Ok(self) } else { - Ok(folder.interner().intern_substs(&[param0])) + Ok(folder.interner().mk_substs(&[param0])) } } 2 => { @@ -502,11 +502,11 @@ impl<'tcx> TypeFoldable> for SubstsRef<'tcx> { if param0 == self[0] && param1 == self[1] { Ok(self) } else { - Ok(folder.interner().intern_substs(&[param0, param1])) + Ok(folder.interner().mk_substs(&[param0, param1])) } } 0 => Ok(self), - _ => ty::util::fold_list(self, folder, |tcx, v| tcx.intern_substs(v)), + _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_substs(v)), } } } @@ -538,10 +538,10 @@ impl<'tcx> TypeFoldable> for &'tcx ty::List> { if param0 == self[0] && param1 == self[1] { Ok(self) } else { - Ok(folder.interner().intern_type_list(&[param0, param1])) + Ok(folder.interner().mk_type_list(&[param0, param1])) } } - _ => ty::util::fold_list(self, folder, |tcx, v| tcx.intern_type_list(v)), + _ => ty::util::fold_list(self, folder, |tcx, v| tcx.mk_type_list(v)), } } } diff --git a/compiler/rustc_middle/src/ty/vtable.rs b/compiler/rustc_middle/src/ty/vtable.rs index f77bd9f0c6ffc..b9b1cd73a8b9a 100644 --- a/compiler/rustc_middle/src/ty/vtable.rs +++ b/compiler/rustc_middle/src/ty/vtable.rs @@ -112,5 +112,5 @@ pub(super) fn vtable_allocation_provider<'tcx>( } vtable.mutability = Mutability::Not; - tcx.create_memory_alloc(tcx.intern_const_alloc(vtable)) + tcx.create_memory_alloc(tcx.mk_const_alloc(vtable)) } diff --git a/compiler/rustc_mir_build/src/build/expr/as_constant.rs b/compiler/rustc_mir_build/src/build/expr/as_constant.rs index 1d96893c7a3ea..2f63333d46b1d 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_constant.rs @@ -132,14 +132,14 @@ pub(crate) fn lit_to_mir_constant<'tcx>( (ast::LitKind::Str(s, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_str() => { let s = s.as_str(); let allocation = Allocation::from_bytes_byte_aligned_immutable(s.as_bytes()); - let allocation = tcx.intern_const_alloc(allocation); + let allocation = tcx.mk_const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: s.len() } } (ast::LitKind::ByteStr(data, _), ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Slice(_)) => { let allocation = Allocation::from_bytes_byte_aligned_immutable(data as &[u8]); - let allocation = tcx.intern_const_alloc(allocation); + let allocation = tcx.mk_const_alloc(allocation); ConstValue::Slice { data: allocation, start: 0, end: data.len() } } (ast::LitKind::ByteStr(data, _), ty::Ref(_, inner_ty, _)) if inner_ty.is_array() => { diff --git a/compiler/rustc_mir_build/src/build/expr/as_operand.rs b/compiler/rustc_mir_build/src/build/expr/as_operand.rs index c621efb3b3a52..ff3198847df6c 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_operand.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_operand.rs @@ -170,7 +170,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Return the operand *tmp0 to be used as the call argument let place = Place { local: operand, - projection: tcx.intern_place_elems(&[PlaceElem::Deref]), + projection: tcx.mk_place_elems(&[PlaceElem::Deref]), }; return block.and(Operand::Move(place)); diff --git a/compiler/rustc_mir_build/src/build/expr/as_place.rs b/compiler/rustc_mir_build/src/build/expr/as_place.rs index e22fa6365dcb4..eb20b2308c0bd 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_place.rs @@ -263,7 +263,7 @@ impl<'tcx> PlaceBuilder<'tcx> { let resolved = self.resolve_upvar(cx); let builder = resolved.as_ref().unwrap_or(self); let PlaceBase::Local(local) = builder.base else { return None }; - let projection = cx.tcx.intern_place_elems(&builder.projection); + let projection = cx.tcx.mk_place_elems(&builder.projection); Some(Place { local, projection }) } @@ -692,7 +692,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); let fake_borrow_temp = self.local_decls.push(LocalDecl::new(fake_borrow_ty, expr_span)); - let projection = tcx.intern_place_elems(&base_place.projection[..idx]); + let projection = tcx.mk_place_elems(&base_place.projection[..idx]); self.cfg.push_assign( block, source_info, diff --git a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs index fb0e9181b52ac..a4e48c1545d6c 100644 --- a/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/build/expr/as_rvalue.rs @@ -520,7 +520,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let source_info = self.source_info(span); let bool_ty = self.tcx.types.bool; if self.check_overflow && op.is_checkable() && ty.is_integral() { - let result_tup = self.tcx.intern_tup(&[ty, bool_ty]); + let result_tup = self.tcx.mk_tup(&[ty, bool_ty]); let result_value = self.temp(result_tup, span); self.cfg.push_assign( diff --git a/compiler/rustc_mir_build/src/build/matches/mod.rs b/compiler/rustc_mir_build/src/build/matches/mod.rs index 6b960ebdb16f1..de2851a1af9fd 100644 --- a/compiler/rustc_mir_build/src/build/matches/mod.rs +++ b/compiler/rustc_mir_build/src/build/matches/mod.rs @@ -1206,7 +1206,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fake_borrows.insert(Place { local: source.local, - projection: self.tcx.intern_place_elems(proj_base), + projection: self.tcx.mk_place_elems(proj_base), }); } } @@ -1743,7 +1743,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .map(|matched_place_ref| { let matched_place = Place { local: matched_place_ref.local, - projection: tcx.intern_place_elems(matched_place_ref.projection), + projection: tcx.mk_place_elems(matched_place_ref.projection), }; let fake_borrow_deref_ty = matched_place.ty(&self.local_decls, tcx).ty; let fake_borrow_ty = tcx.mk_imm_ref(tcx.lifetimes.re_erased, fake_borrow_deref_ty); diff --git a/compiler/rustc_mir_build/src/build/mod.rs b/compiler/rustc_mir_build/src/build/mod.rs index 27536fcddd759..a6de8684c0f8e 100644 --- a/compiler/rustc_mir_build/src/build/mod.rs +++ b/compiler/rustc_mir_build/src/build/mod.rs @@ -859,7 +859,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let use_place = Place { local: ty::CAPTURE_STRUCT_LOCAL, - projection: tcx.intern_place_elems(&projs), + projection: tcx.mk_place_elems(&projs), }; self.var_debug_info.push(VarDebugInfo { name: *sym, diff --git a/compiler/rustc_mir_build/src/thir/cx/expr.rs b/compiler/rustc_mir_build/src/thir/cx/expr.rs index 261b95ba95b0e..3b11fc77d8982 100644 --- a/compiler/rustc_mir_build/src/thir/cx/expr.rs +++ b/compiler/rustc_mir_build/src/thir/cx/expr.rs @@ -307,7 +307,7 @@ impl<'tcx> Cx<'tcx> { let arg_tys = args.iter().map(|e| self.typeck_results().expr_ty_adjusted(e)); let tupled_args = Expr { - ty: tcx.mk_tup(arg_tys), + ty: tcx.mk_tup_from_iter(arg_tys), temp_lifetime, span: expr.span, kind: ExprKind::Tuple { fields: self.mirror_exprs(args) }, diff --git a/compiler/rustc_mir_build/src/thir/cx/mod.rs b/compiler/rustc_mir_build/src/thir/cx/mod.rs index 74c35ef0fc241..20af60a511ea8 100644 --- a/compiler/rustc_mir_build/src/thir/cx/mod.rs +++ b/compiler/rustc_mir_build/src/thir/cx/mod.rs @@ -133,9 +133,8 @@ impl<'tcx> Cx<'tcx> { bug!("closure expr does not have closure type: {:?}", closure_ty); }; - let bound_vars = self - .tcx - .intern_bound_variable_kinds(&[ty::BoundVariableKind::Region(ty::BrEnv)]); + let bound_vars = + self.tcx.mk_bound_variable_kinds(&[ty::BoundVariableKind::Region(ty::BrEnv)]); let br = ty::BoundRegion { var: ty::BoundVar::from_usize(bound_vars.len() - 1), kind: ty::BrEnv, diff --git a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs index 6d30276aeabe0..4a163028fcf4a 100644 --- a/compiler/rustc_mir_dataflow/src/move_paths/builder.rs +++ b/compiler/rustc_mir_dataflow/src/move_paths/builder.rs @@ -126,7 +126,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { BorrowedContent { target_place: Place { local: place.local, - projection: tcx.intern_place_elems(proj), + projection: tcx.mk_place_elems(proj), }, }, )); @@ -165,7 +165,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { if union_path.is_none() { base = self.add_move_path(base, elem, |tcx| Place { local: place.local, - projection: tcx.intern_place_elems(&place.projection[..i + 1]), + projection: tcx.mk_place_elems(&place.projection[..i + 1]), }); } } @@ -476,7 +476,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { // `ConstIndex` patterns. This is done to ensure that all move paths // are disjoint, which is expected by drop elaboration. let base_place = - Place { local: place.local, projection: self.builder.tcx.intern_place_elems(base) }; + Place { local: place.local, projection: self.builder.tcx.mk_place_elems(base) }; let base_path = match self.move_path_for(base_place) { Ok(path) => path, Err(MoveError::UnionMove { path }) => { diff --git a/compiler/rustc_mir_transform/src/copy_prop.rs b/compiler/rustc_mir_transform/src/copy_prop.rs index c57ec137d4b77..f27beb64a14d9 100644 --- a/compiler/rustc_mir_transform/src/copy_prop.rs +++ b/compiler/rustc_mir_transform/src/copy_prop.rs @@ -124,7 +124,7 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> { fn visit_place(&mut self, place: &mut Place<'tcx>, ctxt: PlaceContext, loc: Location) { if let Some(new_projection) = self.process_projection(&place.projection, loc) { - place.projection = self.tcx().intern_place_elems(&new_projection); + place.projection = self.tcx().mk_place_elems(&new_projection); } let observes_address = match ctxt { diff --git a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs index dc583471c89d1..954bb5aff8de6 100644 --- a/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs +++ b/compiler/rustc_mir_transform/src/elaborate_box_derefs.rs @@ -17,7 +17,7 @@ pub fn build_ptr_tys<'tcx>( unique_did: DefId, nonnull_did: DefId, ) -> (Ty<'tcx>, Ty<'tcx>, Ty<'tcx>) { - let substs = tcx.intern_substs(&[pointee.into()]); + let substs = tcx.mk_substs(&[pointee.into()]); let unique_ty = tcx.type_of(unique_did).subst(tcx, substs); let nonnull_ty = tcx.type_of(nonnull_did).subst(tcx, substs); let ptr_ty = tcx.mk_imm_ptr(pointee); @@ -138,7 +138,7 @@ impl<'tcx> MirPass<'tcx> for ElaborateBoxDerefs { if let Some(mut new_projections) = new_projections { new_projections.extend_from_slice(&place.projection[last_deref..]); - place.projection = tcx.intern_place_elems(&new_projections); + place.projection = tcx.mk_place_elems(&new_projections); } } } diff --git a/compiler/rustc_mir_transform/src/generator.rs b/compiler/rustc_mir_transform/src/generator.rs index dc5f88f24f801..2e97312ee5048 100644 --- a/compiler/rustc_mir_transform/src/generator.rs +++ b/compiler/rustc_mir_transform/src/generator.rs @@ -126,7 +126,7 @@ impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor<'tcx> { place, Place { local: SELF_ARG, - projection: self.tcx().intern_place_elems(&[ProjectionElem::Deref]), + projection: self.tcx().mk_place_elems(&[ProjectionElem::Deref]), }, self.tcx, ); @@ -162,10 +162,9 @@ impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> { place, Place { local: SELF_ARG, - projection: self.tcx().intern_place_elems(&[ProjectionElem::Field( - Field::new(0), - self.ref_gen_ty, - )]), + projection: self + .tcx() + .mk_place_elems(&[ProjectionElem::Field(Field::new(0), self.ref_gen_ty)]), }, self.tcx, ); @@ -187,7 +186,7 @@ fn replace_base<'tcx>(place: &mut Place<'tcx>, new_base: Place<'tcx>, tcx: TyCtx let mut new_projection = new_base.projection.to_vec(); new_projection.append(&mut place.projection.to_vec()); - place.projection = tcx.intern_place_elems(&new_projection); + place.projection = tcx.mk_place_elems(&new_projection); } const SELF_ARG: Local = Local::from_u32(1); @@ -300,7 +299,7 @@ impl<'tcx> TransformVisitor<'tcx> { let mut projection = base.projection.to_vec(); projection.push(ProjectionElem::Field(Field::new(idx), ty)); - Place { local: base.local, projection: self.tcx.intern_place_elems(&projection) } + Place { local: base.local, projection: self.tcx.mk_place_elems(&projection) } } // Create a statement which changes the discriminant @@ -427,7 +426,7 @@ fn make_generator_state_argument_pinned<'tcx>(tcx: TyCtxt<'tcx>, body: &mut Body let pin_did = tcx.require_lang_item(LangItem::Pin, Some(body.span)); let pin_adt_ref = tcx.adt_def(pin_did); - let substs = tcx.intern_substs(&[ref_gen_ty.into()]); + let substs = tcx.mk_substs(&[ref_gen_ty.into()]); let pin_ref_gen_ty = tcx.mk_adt(pin_adt_ref, substs); // Replace the by ref generator argument @@ -1450,13 +1449,13 @@ impl<'tcx> MirPass<'tcx> for StateTransform { // Compute Poll 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(&[body.return_ty().into()]); + let poll_substs = tcx.mk_substs(&[body.return_ty().into()]); (poll_adt_ref, poll_substs) } else { // Compute GeneratorState 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(&[yield_ty.into(), body.return_ty().into()]); + let state_substs = tcx.mk_substs(&[yield_ty.into(), body.return_ty().into()]); (state_adt_ref, state_substs) }; let ret_ty = tcx.mk_adt(state_adt_ref, state_substs); diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 8c6b0463a739a..6e6d6566f4bc0 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -888,7 +888,7 @@ impl<'tcx> Visitor<'tcx> for CostChecker<'_, 'tcx> { location: Location, ) { if let ProjectionElem::Field(f, ty) = elem { - let parent = Place { local, projection: self.tcx.intern_place_elems(proj_base) }; + let parent = Place { local, projection: self.tcx.mk_place_elems(proj_base) }; let parent_ty = parent.ty(&self.callee_body.local_decls, self.tcx); let check_equal = |this: &mut Self, f_ty| { if !util::is_equal_up_to_subtyping(this.tcx, this.param_env, ty, f_ty) { diff --git a/compiler/rustc_mir_transform/src/instcombine.rs b/compiler/rustc_mir_transform/src/instcombine.rs index 3896f0e57ead9..14e644bc344ca 100644 --- a/compiler/rustc_mir_transform/src/instcombine.rs +++ b/compiler/rustc_mir_transform/src/instcombine.rs @@ -121,7 +121,7 @@ impl<'tcx> InstCombineContext<'tcx, '_> { *rvalue = Rvalue::Use(Operand::Copy(Place { local: base.local, - projection: self.tcx.intern_place_elems(base.projection), + projection: self.tcx.mk_place_elems(base.projection), })); } } diff --git a/compiler/rustc_mir_transform/src/large_enums.rs b/compiler/rustc_mir_transform/src/large_enums.rs index 2ca33a624e206..89e0a007dac0d 100644 --- a/compiler/rustc_mir_transform/src/large_enums.rs +++ b/compiler/rustc_mir_transform/src/large_enums.rs @@ -114,7 +114,7 @@ impl EnumSizeOpt { tcx.data_layout.ptr_sized_integer().align(&tcx.data_layout).abi, Mutability::Not, ); - let alloc = tcx.create_memory_alloc(tcx.intern_const_alloc(alloc)); + let alloc = tcx.create_memory_alloc(tcx.mk_const_alloc(alloc)); Some((*adt_def, num_discrs, *alloc_cache.entry(ty).or_insert(alloc))) } fn optim<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { @@ -197,9 +197,8 @@ impl EnumSizeOpt { size_place, Rvalue::Use(Operand::Copy(Place { local: size_array_local, - projection: tcx.intern_place_elems(&[PlaceElem::Index( - discr_cast_place.local, - )]), + projection: tcx + .mk_place_elems(&[PlaceElem::Index(discr_cast_place.local)]), })), )), }; diff --git a/compiler/rustc_mir_transform/src/lib.rs b/compiler/rustc_mir_transform/src/lib.rs index bdd1e8fb98f75..4193eb7d6e878 100644 --- a/compiler/rustc_mir_transform/src/lib.rs +++ b/compiler/rustc_mir_transform/src/lib.rs @@ -192,7 +192,7 @@ fn remap_mir_for_const_eval_select<'tcx>( let arguments = (0..num_args).map(|x| { let mut place_elems = place_elems.to_vec(); place_elems.push(ProjectionElem::Field(x.into(), fields[x])); - let projection = tcx.intern_place_elems(&place_elems); + let projection = tcx.mk_place_elems(&place_elems); let place = Place { local: place.local, projection, diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 682ad081f5cf3..ebe63d6cb7e33 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -147,7 +147,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) assert!(!matches!(ty, Some(ty) if ty.is_generator())); let substs = if let Some(ty) = ty { - tcx.intern_substs(&[ty.into()]) + tcx.mk_substs(&[ty.into()]) } else { InternalSubsts::identity_for_item(tcx, def_id) }; @@ -597,7 +597,7 @@ fn build_call_shim<'tcx>( let untuple_args = sig.inputs(); // Create substitutions for the `Self` and `Args` generic parameters of the shim body. - let arg_tup = tcx.intern_tup(untuple_args); + let arg_tup = tcx.mk_tup(untuple_args); (Some([ty.into(), arg_tup.into()]), Some(untuple_args)) } else { @@ -632,7 +632,7 @@ fn build_call_shim<'tcx>( Adjustment::Deref => tcx.mk_imm_ptr(fnty), Adjustment::RefMut => tcx.mk_mut_ptr(fnty), }; - sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output); + sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output); } // FIXME(eddyb) avoid having this snippet both here and in @@ -643,7 +643,7 @@ fn build_call_shim<'tcx>( let self_arg = &mut inputs_and_output[0]; debug_assert!(tcx.generics_of(def_id).has_self && *self_arg == tcx.types.self_param); *self_arg = tcx.mk_mut_ptr(*self_arg); - sig.inputs_and_output = tcx.intern_type_list(&inputs_and_output); + sig.inputs_and_output = tcx.mk_type_list(&inputs_and_output); } let span = tcx.def_span(def_id); diff --git a/compiler/rustc_mir_transform/src/sroa.rs b/compiler/rustc_mir_transform/src/sroa.rs index 8a37423b2a052..13168e9a268ed 100644 --- a/compiler/rustc_mir_transform/src/sroa.rs +++ b/compiler/rustc_mir_transform/src/sroa.rs @@ -122,7 +122,7 @@ impl<'tcx> ReplacementMap<'tcx> { let &[PlaceElem::Field(f, _), ref rest @ ..] = place.projection else { return None; }; let fields = self.fragments[place.local].as_ref()?; let (_, new_local) = fields[f]?; - Some(Place { local: new_local, projection: tcx.intern_place_elems(&rest) }) + Some(Place { local: new_local, projection: tcx.mk_place_elems(&rest) }) } fn place_fragments( diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index ff409a8071611..45e659eab6c85 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1298,7 +1298,7 @@ impl<'v> RootCollector<'_, 'v> { self.tcx, ty::ParamEnv::reveal_all(), start_def_id, - self.tcx.intern_substs(&[main_ret_ty.into()]), + self.tcx.mk_substs(&[main_ret_ty.into()]), ) .unwrap() .unwrap(); diff --git a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs index 1d299e2925631..1a679f32ca59b 100644 --- a/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs +++ b/compiler/rustc_symbol_mangling/src/typeid/typeid_itanium_cxx_abi.rs @@ -675,7 +675,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio _ if ty.is_unit() => {} ty::Tuple(tys) => { - ty = tcx.mk_tup(tys.iter().map(|ty| transform_ty(tcx, ty, options))); + ty = tcx.mk_tup_from_iter(tys.iter().map(|ty| transform_ty(tcx, ty, options))); } ty::Array(ty0, len) => { @@ -825,7 +825,7 @@ fn transform_substs<'tcx>( subst } }); - tcx.mk_substs(substs) + tcx.mk_substs_from_iter(substs) } /// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor diff --git a/compiler/rustc_trait_selection/src/solve/mod.rs b/compiler/rustc_trait_selection/src/solve/mod.rs index c080f7e59fa22..71f536dd3cb31 100644 --- a/compiler/rustc_trait_selection/src/solve/mod.rs +++ b/compiler/rustc_trait_selection/src/solve/mod.rs @@ -567,7 +567,7 @@ fn compute_external_query_constraints<'tcx>( ) -> Result, NoSolution> { let region_obligations = infcx.take_registered_region_obligations(); let opaque_types = infcx.take_opaque_types_for_query_response(); - Ok(infcx.tcx.intern_external_constraints(ExternalConstraintsData { + Ok(infcx.tcx.mk_external_constraints(ExternalConstraintsData { // FIXME: Now that's definitely wrong :) // // Should also do the leak check here I think @@ -616,8 +616,7 @@ pub(super) fn response_no_constraints<'tcx>( var_values: CanonicalVarValues::make_identity(tcx, goal.variables), // FIXME: maybe we should store the "no response" version in tcx, like // we do for tcx.types and stuff. - external_constraints: tcx - .intern_external_constraints(ExternalConstraintsData::default()), + external_constraints: tcx.mk_external_constraints(ExternalConstraintsData::default()), certainty, }, }) diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals.rs b/compiler/rustc_trait_selection/src/solve/trait_goals.rs index aff79739d45ff..68bb7c877e3d9 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals.rs @@ -343,9 +343,10 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { // Substitute just the unsizing params from B into A. The type after // this substitution must be equal to B. This is so we don't unsize // unrelated type parameters. - let new_a_substs = tcx.mk_substs(a_substs.iter().enumerate().map(|(i, a)| { - if unsizing_params.contains(i as u32) { b_substs[i] } else { a } - })); + let new_a_substs = + tcx.mk_substs_from_iter(a_substs.iter().enumerate().map(|(i, a)| { + if unsizing_params.contains(i as u32) { b_substs[i] } else { a } + })); let unsized_a_ty = tcx.mk_adt(a_def, new_a_substs); // Finally, we require that `TailA: Unsize` for the tail field @@ -368,7 +369,8 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { let b_last_ty = b_tys.last().unwrap(); // Substitute just the tail field of B., and require that they're equal. - let unsized_a_ty = tcx.mk_tup(a_rest_tys.iter().chain([b_last_ty]).copied()); + let unsized_a_ty = + tcx.mk_tup_from_iter(a_rest_tys.iter().chain([b_last_ty]).copied()); let mut nested_goals = ecx.eq(goal.param_env, unsized_a_ty, b_ty)?; // Similar to ADTs, require that the rest of the fields are equal. @@ -425,7 +427,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for TraitPredicate<'tcx> { .map(ty::ExistentialPredicate::AutoTrait) .map(ty::Binder::dummy), ); - let new_a_data = tcx.mk_poly_existential_predicates(new_a_data); + let new_a_data = tcx.mk_poly_existential_predicates_from_iter(new_a_data); let new_a_ty = tcx.mk_dynamic(new_a_data, b_region, ty::Dyn); // We also require that A's lifetime outlives B's lifetime. diff --git a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs index 2c13465d347c4..3a887f54587f4 100644 --- a/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs +++ b/compiler/rustc_trait_selection/src/solve/trait_goals/structural_traits.rs @@ -189,11 +189,9 @@ pub(crate) fn extract_tupled_inputs_and_output_from_callable<'tcx>( ty::FnDef(def_id, substs) => Ok(Some( tcx.fn_sig(def_id) .subst(tcx, substs) - .map_bound(|sig| (tcx.intern_tup(sig.inputs()), sig.output())), + .map_bound(|sig| (tcx.mk_tup(sig.inputs()), sig.output())), )), - ty::FnPtr(sig) => { - Ok(Some(sig.map_bound(|sig| (tcx.intern_tup(sig.inputs()), sig.output())))) - } + ty::FnPtr(sig) => Ok(Some(sig.map_bound(|sig| (tcx.mk_tup(sig.inputs()), sig.output())))), ty::Closure(_, substs) => { let closure_substs = substs.as_closure(); match closure_substs.kind_ty().to_opt_closure_kind() { diff --git a/compiler/rustc_trait_selection/src/traits/auto_trait.rs b/compiler/rustc_trait_selection/src/traits/auto_trait.rs index 6f2b0856d516a..1fb8659bb27d3 100644 --- a/compiler/rustc_trait_selection/src/traits/auto_trait.rs +++ b/compiler/rustc_trait_selection/src/traits/auto_trait.rs @@ -350,14 +350,14 @@ impl<'tcx> AutoTraitFinder<'tcx> { ) .map(|o| o.predicate); new_env = ty::ParamEnv::new( - tcx.mk_predicates(normalized_preds), + tcx.mk_predicates_from_iter(normalized_preds), param_env.reveal(), param_env.constness(), ); } let final_user_env = ty::ParamEnv::new( - tcx.mk_predicates(user_computed_preds.into_iter()), + tcx.mk_predicates_from_iter(user_computed_preds.into_iter()), user_env.reveal(), user_env.constness(), ); diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index c8b233bfe26aa..b2317f55d2595 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -281,7 +281,7 @@ pub fn normalize_param_env_or_error<'tcx>( debug!("normalize_param_env_or_error: elaborated-predicates={:?}", predicates); let elaborated_env = ty::ParamEnv::new( - tcx.intern_predicates(&predicates), + tcx.mk_predicates(&predicates), unnormalized_env.reveal(), unnormalized_env.constness(), ); @@ -333,10 +333,9 @@ pub fn normalize_param_env_or_error<'tcx>( // Not sure whether it is better to include the unnormalized TypeOutlives predicates // here. I believe they should not matter, because we are ignoring TypeOutlives param-env // predicates here anyway. Keeping them here anyway because it seems safer. - let outlives_env: Vec<_> = - non_outlives_predicates.iter().chain(&outlives_predicates).cloned().collect(); + let outlives_env = non_outlives_predicates.iter().chain(&outlives_predicates).cloned(); let outlives_env = ty::ParamEnv::new( - tcx.intern_predicates(&outlives_env), + tcx.mk_predicates_from_iter(outlives_env), unnormalized_env.reveal(), unnormalized_env.constness(), ); @@ -356,7 +355,7 @@ pub fn normalize_param_env_or_error<'tcx>( predicates.extend(outlives_predicates); debug!("normalize_param_env_or_error: final predicates={:?}", predicates); ty::ParamEnv::new( - tcx.intern_predicates(&predicates), + tcx.mk_predicates(&predicates), unnormalized_env.reveal(), unnormalized_env.constness(), ) diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index b87f75422ef60..4eacb5211f760 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -18,10 +18,10 @@ use rustc_errors::{DelayDm, FatalError, MultiSpan}; use rustc_hir as hir; use rustc_hir::def_id::DefId; use rustc_middle::ty::subst::{GenericArg, InternalSubsts}; +use rustc_middle::ty::ToPredicate; use rustc_middle::ty::{ self, EarlyBinder, Ty, TyCtxt, TypeSuperVisitable, TypeVisitable, TypeVisitor, }; -use rustc_middle::ty::{Predicate, ToPredicate}; use rustc_session::lint::builtin::WHERE_CLAUSES_OBJECT_SAFETY; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -666,8 +666,9 @@ fn object_ty_for_trait<'tcx>( elaborated_predicates.sort_by(|a, b| a.skip_binder().stable_cmp(tcx, &b.skip_binder())); elaborated_predicates.dedup(); - let existential_predicates = tcx - .mk_poly_existential_predicates(iter::once(trait_predicate).chain(elaborated_predicates)); + let existential_predicates = tcx.mk_poly_existential_predicates_from_iter( + iter::once(trait_predicate).chain(elaborated_predicates), + ); debug!(?existential_predicates); tcx.mk_dynamic(existential_predicates, lifetime, ty::Dyn) @@ -766,11 +767,11 @@ fn receiver_is_dispatchable<'tcx>( ty::Binder::dummy(tcx.mk_trait_ref(trait_def_id, substs)).to_predicate(tcx) }; - let caller_bounds: Vec> = - param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]).collect(); + let caller_bounds = + param_env.caller_bounds().iter().chain([unsize_predicate, trait_predicate]); ty::ParamEnv::new( - tcx.intern_predicates(&caller_bounds), + tcx.mk_predicates_from_iter(caller_bounds), param_env.reveal(), param_env.constness(), ) diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs index 14bba00b57e05..e5b0f9d3300a6 100644 --- a/compiler/rustc_trait_selection/src/traits/project.rs +++ b/compiler/rustc_trait_selection/src/traits/project.rs @@ -1906,7 +1906,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>( ) -> Progress<'tcx> { let tcx = selcx.tcx(); let self_ty = obligation.predicate.self_ty(); - let substs = tcx.intern_substs(&[self_ty.into()]); + let substs = tcx.mk_substs(&[self_ty.into()]); let lang_items = tcx.lang_items(); let item_def_id = obligation.predicate.def_id; let trait_def_id = tcx.trait_of_item(item_def_id).unwrap(); diff --git a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs index 270f513ce3cd1..21c158fd0fddd 100644 --- a/compiler/rustc_trait_selection/src/traits/select/confirmation.rs +++ b/compiler/rustc_trait_selection/src/traits/select/confirmation.rs @@ -564,8 +564,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .into() } }); - let bound_vars = tcx.intern_bound_variable_kinds(&bound_vars); - let assoc_ty_substs = tcx.intern_substs(&substs); + let bound_vars = tcx.mk_bound_variable_kinds(&bound_vars); + let assoc_ty_substs = tcx.mk_substs(&substs); let bound = bound.map_bound(|b| b.kind().skip_binder()).subst(tcx, assoc_ty_substs); tcx.mk_predicate(ty::Binder::bind_with_vars(bound, bound_vars)) @@ -880,7 +880,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map(ty::ExistentialPredicate::AutoTrait) .map(ty::Binder::dummy), ); - let existential_predicates = tcx.mk_poly_existential_predicates(iter); + let existential_predicates = tcx.mk_poly_existential_predicates_from_iter(iter); let source_trait = tcx.mk_dynamic(existential_predicates, r_b, repr_a); // Require that the traits involved in this upcast are **equal**; @@ -979,7 +979,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { .map(ty::ExistentialPredicate::AutoTrait) .map(ty::Binder::dummy), ); - let existential_predicates = tcx.mk_poly_existential_predicates(iter); + let existential_predicates = tcx.mk_poly_existential_predicates_from_iter(iter); let source_trait = tcx.mk_dynamic(existential_predicates, r_b, dyn_a); // Require that the traits involved in this upcast are **equal**; @@ -1099,7 +1099,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Check that the source struct with the target's // unsizing parameters is equal to the target. - let substs = tcx.mk_substs(substs_a.iter().enumerate().map(|(i, k)| { + let substs = tcx.mk_substs_from_iter(substs_a.iter().enumerate().map(|(i, k)| { if unsizing_params.contains(i as u32) { substs_b[i] } else { k } })); let new_struct = tcx.mk_adt(def, substs); @@ -1131,7 +1131,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { // Check that the source tuple with the target's // last element is equal to the target. - let new_tuple = tcx.mk_tup(a_mid.iter().copied().chain(iter::once(b_last))); + let new_tuple = + tcx.mk_tup_from_iter(a_mid.iter().copied().chain(iter::once(b_last))); let InferOk { obligations, .. } = self .infcx .at(&obligation.cause, obligation.param_env) diff --git a/compiler/rustc_trait_selection/src/traits/select/mod.rs b/compiler/rustc_trait_selection/src/traits/select/mod.rs index e2fb954e31f36..a2c16e6d0b462 100644 --- a/compiler/rustc_trait_selection/src/traits/select/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/select/mod.rs @@ -2230,7 +2230,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> { } } // (*) binder moved here - let all_vars = self.tcx().mk_bound_variable_kinds( + let all_vars = self.tcx().mk_bound_variable_kinds_from_iter( obligation.predicate.bound_vars().iter().chain(binder.bound_vars().iter()), ); Where(ty::Binder::bind_with_vars(witness_tys.to_vec(), all_vars)) @@ -3034,7 +3034,7 @@ fn bind_generator_hidden_types_above<'tcx>( if considering_regions { debug_assert!(!hidden_types.has_erased_regions()); } - let bound_vars = tcx.mk_bound_variable_kinds(bound_vars.iter().chain( + let bound_vars = tcx.mk_bound_variable_kinds_from_iter(bound_vars.iter().chain( (num_bound_variables..counter).map(|i| ty::BoundVariableKind::Region(ty::BrAnon(i, None))), )); ty::Binder::bind_with_vars(hidden_types, bound_vars) diff --git a/compiler/rustc_trait_selection/src/traits/util.rs b/compiler/rustc_trait_selection/src/traits/util.rs index 638a6592c088d..bcf63d5a6f628 100644 --- a/compiler/rustc_trait_selection/src/traits/util.rs +++ b/compiler/rustc_trait_selection/src/traits/util.rs @@ -292,7 +292,7 @@ pub fn closure_trait_ref_and_return_type<'tcx>( assert!(!self_ty.has_escaping_bound_vars()); let arguments_tuple = match tuple_arguments { TupleArgumentsFlag::No => sig.skip_binder().inputs()[0], - TupleArgumentsFlag::Yes => tcx.intern_tup(sig.skip_binder().inputs()), + TupleArgumentsFlag::Yes => tcx.mk_tup(sig.skip_binder().inputs()), }; let trait_ref = tcx.mk_trait_ref(fn_trait_def_id, [self_ty, arguments_tuple]); sig.map_bound(|sig| (trait_ref, sig.output())) diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 50cd1d1c0e8e1..179ed1220f913 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -62,7 +62,9 @@ impl<'tcx> LowerInto<'tcx, chalk_ir::Substitution>> for Subst impl<'tcx> LowerInto<'tcx, SubstsRef<'tcx>> for &chalk_ir::Substitution> { fn lower_into(self, interner: RustInterner<'tcx>) -> SubstsRef<'tcx> { - interner.tcx.mk_substs(self.iter(interner).map(|subst| subst.lower_into(interner))) + interner + .tcx + .mk_substs_from_iter(self.iter(interner).map(|subst| subst.lower_into(interner))) } } diff --git a/compiler/rustc_traits/src/chalk/mod.rs b/compiler/rustc_traits/src/chalk/mod.rs index 5855a8e28dd1d..1fbc3214967f6 100644 --- a/compiler/rustc_traits/src/chalk/mod.rs +++ b/compiler/rustc_traits/src/chalk/mod.rs @@ -96,7 +96,7 @@ pub(crate) fn evaluate_goal<'tcx>( use rustc_middle::infer::canonical::CanonicalVarInfo; let mut reverse_param_substitutor = ReverseParamsSubstitutor::new(tcx, params); - let var_values = tcx.mk_substs( + let var_values = tcx.mk_substs_from_iter( subst .as_slice(interner) .iter() @@ -126,7 +126,7 @@ pub(crate) fn evaluate_goal<'tcx>( let max_universe = binders.iter(interner).map(|v| v.skip_kind().counter).max().unwrap_or(0); let sol = Canonical { max_universe: ty::UniverseIndex::from_usize(max_universe), - variables: tcx.intern_canonical_var_infos(&variables), + variables: tcx.mk_canonical_var_infos(&variables), value: QueryResponse { var_values: CanonicalVarValues { var_values }, region_constraints: QueryRegionConstraints::default(), diff --git a/compiler/rustc_ty_utils/src/abi.rs b/compiler/rustc_ty_utils/src/abi.rs index 41924dc2a6d93..35c9f95eb03b1 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` 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` 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/consts.rs b/compiler/rustc_ty_utils/src/consts.rs index ae824a31f759f..f2635271609b8 100644 --- a/compiler/rustc_ty_utils/src/consts.rs +++ b/compiler/rustc_ty_utils/src/consts.rs @@ -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/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs index eb307e66e342d..7fecee2a38bd0 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> { 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/layout.rs b/compiler/rustc_ty_utils/src/layout.rs index a400fbfe683ef..e3132fcc4c412 100644 --- a/compiler/rustc_ty_utils/src/layout.rs +++ b/compiler/rustc_ty_utils/src/layout.rs @@ -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/needs_drop.rs b/compiler/rustc_ty_utils/src/needs_drop.rs index c177d60bb5967..de7fd003176bb 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::, _>>() - .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::, _>>() - .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 853c50f52462f..18159778a8e39 100644 --- a/compiler/rustc_ty_utils/src/ty.rs +++ b/compiler/rustc_ty_utils/src/ty.rs @@ -98,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_misc()]); + 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()) @@ -226,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); @@ -386,7 +383,7 @@ fn well_formed_types_in_env(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List, def_id: DefId) -> ty::ParamEnv<'_> { diff --git a/src/tools/clippy/clippy_lints/src/derive.rs b/src/tools/clippy/clippy_lints/src/derive.rs index 1cdcccd5f146c..b8428d66a5dc8 100644 --- a/src/tools/clippy/clippy_lints/src/derive.rs +++ b/src/tools/clippy/clippy_lints/src/derive.rs @@ -514,7 +514,7 @@ fn param_env_for_derived_eq(tcx: TyCtxt<'_>, did: DefId, eq_trait_id: DefId) -> } ParamEnv::new( - tcx.mk_predicates(ty_predicates.iter().map(|&(p, _)| p).chain( + tcx.mk_predicates_from_iter(ty_predicates.iter().map(|&(p, _)| p).chain( params.iter().filter(|&&(_, needs_eq)| needs_eq).map(|&(param, _)| { tcx.mk_predicate(Binder::dummy(PredicateKind::Clause(Clause::Trait(TraitPredicate { trait_ref: tcx.mk_trait_ref(eq_trait_id, [tcx.mk_param_from_def(param)]), diff --git a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs index 8ddbacc3d7ad4..0b0c6adc5045a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs +++ b/src/tools/clippy/clippy_lints/src/methods/needless_collect.rs @@ -173,7 +173,7 @@ fn is_contains_sig(cx: &LateContext<'_>, call_id: HirId, iter_expr: &Expr<'_>) - && let Some(iter_item) = cx.tcx .associated_items(iter_trait) .find_by_name_and_kind(cx.tcx, Ident::with_dummy_span(Symbol::intern("Item")), AssocKind::Type, iter_trait) - && let substs = cx.tcx.intern_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) + && let substs = cx.tcx.mk_substs(&[GenericArg::from(typeck.expr_ty_adjusted(iter_expr))]) && let proj_ty = cx.tcx.mk_projection(iter_item.def_id, substs) && let Ok(item_ty) = cx.tcx.try_normalize_erasing_regions(cx.param_env, proj_ty) { diff --git a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs index 4e5af1c7c7124..df26b36b7b32a 100644 --- a/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs +++ b/src/tools/clippy/clippy_lints/src/methods/unnecessary_to_owned.rs @@ -414,7 +414,7 @@ fn can_change_type<'a>(cx: &LateContext<'a>, mut expr: &'a Expr<'a>, mut ty: Ty< } }); - let new_subst = cx.tcx.mk_substs( + let new_subst = cx.tcx.mk_substs_from_iter( call_substs.iter() .enumerate() .map(|(i, t)| diff --git a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs index 398329e455bfa..2fdd775ad4893 100644 --- a/src/tools/clippy/clippy_lints/src/redundant_slicing.rs +++ b/src/tools/clippy/clippy_lints/src/redundant_slicing.rs @@ -134,7 +134,7 @@ impl<'tcx> LateLintPass<'tcx> for RedundantSlicing { } else if let Some(target_id) = cx.tcx.lang_items().deref_target() { if let Ok(deref_ty) = cx.tcx.try_normalize_erasing_regions( cx.param_env, - cx.tcx.mk_projection(target_id, cx.tcx.intern_substs(&[GenericArg::from(indexed_ty)])), + cx.tcx.mk_projection(target_id, cx.tcx.mk_substs(&[GenericArg::from(indexed_ty)])), ) { if deref_ty == expr_ty { let snip = snippet_with_context(cx, indexed.span, ctxt, "..", &mut app).0; diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index 8b00ce2cc2586..e3bfffacb5250 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -237,7 +237,7 @@ pub fn constant<'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.intern_substs(&[]), + substs: lcx.tcx.mk_substs(&[]), }; cx.expr(e).map(|cst| (cst, cx.needed_resolution)) } @@ -306,7 +306,7 @@ pub fn constant_context<'a, 'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.intern_substs(&[]), + substs: lcx.tcx.mk_substs(&[]), } } diff --git a/src/tools/clippy/clippy_utils/src/ty.rs b/src/tools/clippy/clippy_utils/src/ty.rs index 34b9bb5994efa..f8ec4bb54930a 100644 --- a/src/tools/clippy/clippy_utils/src/ty.rs +++ b/src/tools/clippy/clippy_utils/src/ty.rs @@ -237,7 +237,7 @@ pub fn implements_trait_with_env<'tcx>( kind: TypeVariableOriginKind::MiscVariable, span: DUMMY_SP, }; - let ty_params = tcx.mk_substs( + let ty_params = tcx.mk_substs_from_iter( ty_params .into_iter() .map(|arg| arg.unwrap_or_else(|| infcx.next_ty_var(orig).into())), @@ -1065,7 +1065,7 @@ pub fn make_projection<'tcx>( tcx, container_id, assoc_ty, - tcx.mk_substs(substs.into_iter().map(Into::into)), + tcx.mk_substs_from_iter(substs.into_iter().map(Into::into)), ) } diff --git a/src/tools/miri/src/eval.rs b/src/tools/miri/src/eval.rs index ebb71b57ae395..8443e90793867 100644 --- a/src/tools/miri/src/eval.rs +++ b/src/tools/miri/src/eval.rs @@ -363,7 +363,7 @@ pub fn create_ecx<'mir, 'tcx: 'mir>( tcx, ty::ParamEnv::reveal_all(), start_id, - tcx.intern_substs(&[ty::subst::GenericArg::from(main_ret_ty)]), + tcx.mk_substs(&[ty::subst::GenericArg::from(main_ret_ty)]), ) .unwrap() .unwrap(); diff --git a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs index c82c274524acd..f21b4f84c4cd5 100644 --- a/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs +++ b/src/tools/rust-analyzer/crates/hir-ty/src/layout.rs @@ -173,7 +173,7 @@ pub fn layout_of_ty(db: &dyn HirDatabase, ty: &Ty, krate: CrateId) -> Result Date: Mon, 20 Feb 2023 09:52:58 +1100 Subject: [PATCH 3/6] Replace a `mk_ty` call with `mk_bound`. --- compiler/rustc_hir_analysis/src/astconv/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/rustc_hir_analysis/src/astconv/mod.rs b/compiler/rustc_hir_analysis/src/astconv/mod.rs index 49d4860314f30..43dd5b3621a6e 100644 --- a/compiler/rustc_hir_analysis/src/astconv/mod.rs +++ b/compiler/rustc_hir_analysis/src/astconv/mod.rs @@ -2810,7 +2810,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o { var: ty::BoundVar::from_u32(index), kind: ty::BoundTyKind::Param(def_id, name), }; - tcx.mk_ty(ty::Bound(debruijn, br)) + tcx.mk_bound(debruijn, br) } Some(rbv::ResolvedArg::EarlyBound(_)) => { let def_id = def_id.expect_local(); From 11c2c596e4263787f63bcb7ecd317359f2d704c1 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 20 Feb 2023 10:19:09 +1100 Subject: [PATCH 4/6] Rename `mk_{ty,region}` as `mk_{ty,region}_from_kind`. To discourage accidental use -- there are more specific `mk_*` functions for all `Ty` and `Region` kinds. --- compiler/rustc_middle/src/ty/codec.rs | 4 +- compiler/rustc_middle/src/ty/context.rs | 68 +++++++++++-------- .../rustc_middle/src/ty/structural_impls.rs | 2 +- compiler/rustc_traits/src/chalk/lowering.rs | 2 +- 4 files changed, 42 insertions(+), 34 deletions(-) diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 7ded1b6b42c79..99a5921d93dcc 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -207,7 +207,7 @@ impl<'tcx, D: TyDecoder>> Decodable for Ty<'tcx> { }) } else { let tcx = decoder.interner(); - tcx.mk_ty(rustc_type_ir::TyKind::decode(decoder)) + tcx.mk_ty_from_kind(rustc_type_ir::TyKind::decode(decoder)) } } } @@ -263,7 +263,7 @@ impl<'tcx, D: TyDecoder>> Decodable for mir::Place<'tcx> { impl<'tcx, D: TyDecoder>> Decodable for ty::Region<'tcx> { fn decode(decoder: &mut D) -> Self { - decoder.interner().mk_region(Decodable::decode(decoder)) + decoder.interner().mk_region_from_kind(Decodable::decode(decoder)) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index 6a76a55e4ad72..e5301791318b5 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -720,7 +720,7 @@ impl<'tcx> TyCtxt<'tcx> { /// Constructs a `TyKind::Error` type with current `ErrorGuaranteed` #[track_caller] pub fn ty_error(self, reported: ErrorGuaranteed) -> Ty<'tcx> { - self.mk_ty(Error(reported)) + self.mk_ty_from_kind(Error(reported)) } /// Constructs a `TyKind::Error` type and registers a `delay_span_bug` to ensure it gets used. @@ -734,7 +734,7 @@ impl<'tcx> TyCtxt<'tcx> { #[track_caller] pub fn ty_error_with_message>(self, span: S, msg: &str) -> Ty<'tcx> { let reported = self.sess.delay_span_bug(span, msg); - self.mk_ty(Error(reported)) + self.mk_ty_from_kind(Error(reported)) } /// Constructs a `RegionKind::ReError` lifetime. @@ -1681,7 +1681,7 @@ impl<'tcx> TyCtxt<'tcx> { // Avoid this in favour of more specific `mk_*` methods, where possible. #[allow(rustc::usage_of_ty_tykind)] #[inline] - pub fn mk_ty(self, st: TyKind<'tcx>) -> Ty<'tcx> { + pub fn mk_ty_from_kind(self, st: TyKind<'tcx>) -> Ty<'tcx> { self.interners.intern_ty( st, self.sess, @@ -1746,12 +1746,12 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_adt(self, def: AdtDef<'tcx>, substs: SubstsRef<'tcx>) -> Ty<'tcx> { // Take a copy of substs so that we own the vectors inside. - self.mk_ty(Adt(def, substs)) + self.mk_ty_from_kind(Adt(def, substs)) } #[inline] pub fn mk_foreign(self, def_id: DefId) -> Ty<'tcx> { - self.mk_ty(Foreign(def_id)) + self.mk_ty_from_kind(Foreign(def_id)) } fn mk_generic_adt(self, wrapper_def_id: DefId, ty_param: Ty<'tcx>) -> Ty<'tcx> { @@ -1768,7 +1768,7 @@ impl<'tcx> TyCtxt<'tcx> { } } }); - self.mk_ty(Adt(adt_def, substs)) + self.mk_ty_from_kind(Adt(adt_def, substs)) } #[inline] @@ -1797,12 +1797,12 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_ptr(self, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { - self.mk_ty(RawPtr(tm)) + self.mk_ty_from_kind(RawPtr(tm)) } #[inline] pub fn mk_ref(self, r: Region<'tcx>, tm: TypeAndMut<'tcx>) -> Ty<'tcx> { - self.mk_ty(Ref(r, tm.ty, tm.mutbl)) + self.mk_ty_from_kind(Ref(r, tm.ty, tm.mutbl)) } #[inline] @@ -1827,22 +1827,26 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_array(self, ty: Ty<'tcx>, n: u64) -> Ty<'tcx> { - self.mk_ty(Array(ty, ty::Const::from_target_usize(self, n))) + self.mk_ty_from_kind(Array(ty, ty::Const::from_target_usize(self, n))) } #[inline] pub fn mk_array_with_const_len(self, ty: Ty<'tcx>, ct: Const<'tcx>) -> Ty<'tcx> { - self.mk_ty(Array(ty, ct)) + self.mk_ty_from_kind(Array(ty, ct)) } #[inline] pub fn mk_slice(self, ty: Ty<'tcx>) -> Ty<'tcx> { - self.mk_ty(Slice(ty)) + self.mk_ty_from_kind(Slice(ty)) } #[inline] pub fn mk_tup(self, ts: &[Ty<'tcx>]) -> Ty<'tcx> { - if ts.is_empty() { self.types.unit } else { self.mk_ty(Tuple(self.mk_type_list(&ts))) } + if ts.is_empty() { + self.types.unit + } else { + self.mk_ty_from_kind(Tuple(self.mk_type_list(&ts))) + } } pub fn mk_tup_from_iter(self, iter: I) -> T::Output @@ -1870,7 +1874,7 @@ impl<'tcx> TyCtxt<'tcx> { substs: impl IntoIterator>>, ) -> Ty<'tcx> { let substs = self.check_and_mk_substs(def_id, substs); - self.mk_ty(FnDef(def_id, substs)) + self.mk_ty_from_kind(FnDef(def_id, substs)) } #[inline(always)] @@ -1895,7 +1899,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_fn_ptr(self, fty: PolyFnSig<'tcx>) -> Ty<'tcx> { - self.mk_ty(FnPtr(fty)) + self.mk_ty_from_kind(FnPtr(fty)) } #[inline] @@ -1905,7 +1909,7 @@ impl<'tcx> TyCtxt<'tcx> { reg: ty::Region<'tcx>, repr: DynKind, ) -> Ty<'tcx> { - self.mk_ty(Dynamic(obj, reg, repr)) + self.mk_ty_from_kind(Dynamic(obj, reg, repr)) } #[inline] @@ -1919,7 +1923,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_closure(self, closure_id: DefId, closure_substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty(Closure(closure_id, closure_substs)) + self.mk_ty_from_kind(Closure(closure_id, closure_substs)) } #[inline] @@ -1929,12 +1933,12 @@ impl<'tcx> TyCtxt<'tcx> { generator_substs: SubstsRef<'tcx>, movability: hir::Movability, ) -> Ty<'tcx> { - self.mk_ty(Generator(id, generator_substs, movability)) + self.mk_ty_from_kind(Generator(id, generator_substs, movability)) } #[inline] pub fn mk_generator_witness(self, types: ty::Binder<'tcx, &'tcx List>>) -> Ty<'tcx> { - self.mk_ty(GeneratorWitness(types)) + self.mk_ty_from_kind(GeneratorWitness(types)) } /// Creates a `&mut Context<'_>` [`Ty`] with erased lifetimes. @@ -1948,7 +1952,7 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_generator_witness_mir(self, id: DefId, substs: SubstsRef<'tcx>) -> Ty<'tcx> { - self.mk_ty(GeneratorWitnessMIR(id, substs)) + self.mk_ty_from_kind(GeneratorWitnessMIR(id, substs)) } #[inline] @@ -1959,17 +1963,21 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_ty_var(self, v: TyVid) -> Ty<'tcx> { // Use a pre-interned one when possible. - self.types.ty_vars.get(v.as_usize()).copied().unwrap_or_else(|| self.mk_ty(Infer(TyVar(v)))) + self.types + .ty_vars + .get(v.as_usize()) + .copied() + .unwrap_or_else(|| self.mk_ty_from_kind(Infer(TyVar(v)))) } #[inline] pub fn mk_int_var(self, v: IntVid) -> Ty<'tcx> { - self.mk_ty(Infer(IntVar(v))) + self.mk_ty_from_kind(Infer(IntVar(v))) } #[inline] pub fn mk_float_var(self, v: FloatVid) -> Ty<'tcx> { - self.mk_ty(Infer(FloatVar(v))) + self.mk_ty_from_kind(Infer(FloatVar(v))) } #[inline] @@ -1979,7 +1987,7 @@ impl<'tcx> TyCtxt<'tcx> { .fresh_tys .get(n as usize) .copied() - .unwrap_or_else(|| self.mk_ty(Infer(ty::FreshTy(n)))) + .unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshTy(n)))) } #[inline] @@ -1989,7 +1997,7 @@ impl<'tcx> TyCtxt<'tcx> { .fresh_int_tys .get(n as usize) .copied() - .unwrap_or_else(|| self.mk_ty(Infer(ty::FreshIntTy(n)))) + .unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshIntTy(n)))) } #[inline] @@ -1999,12 +2007,12 @@ impl<'tcx> TyCtxt<'tcx> { .fresh_float_tys .get(n as usize) .copied() - .unwrap_or_else(|| self.mk_ty(Infer(ty::FreshFloatTy(n)))) + .unwrap_or_else(|| self.mk_ty_from_kind(Infer(ty::FreshFloatTy(n)))) } #[inline] pub fn mk_ty_param(self, index: u32, name: Symbol) -> Ty<'tcx> { - self.mk_ty(Param(ParamTy { index, name })) + self.mk_ty_from_kind(Param(ParamTy { index, name })) } pub fn mk_param_from_def(self, param: &ty::GenericParamDef) -> GenericArg<'tcx> { @@ -2026,17 +2034,17 @@ impl<'tcx> TyCtxt<'tcx> { #[inline] pub fn mk_bound(self, index: ty::DebruijnIndex, bound_ty: ty::BoundTy) -> Ty<'tcx> { - self.mk_ty(Bound(index, bound_ty)) + self.mk_ty_from_kind(Bound(index, bound_ty)) } #[inline] pub fn mk_placeholder(self, placeholder: ty::PlaceholderType) -> Ty<'tcx> { - self.mk_ty(Placeholder(placeholder)) + self.mk_ty_from_kind(Placeholder(placeholder)) } #[inline] pub fn mk_alias(self, kind: ty::AliasKind, alias_ty: ty::AliasTy<'tcx>) -> Ty<'tcx> { - self.mk_ty(Alias(kind, alias_ty)) + self.mk_ty_from_kind(Alias(kind, alias_ty)) } #[inline] @@ -2089,7 +2097,7 @@ impl<'tcx> TyCtxt<'tcx> { // Avoid this in favour of more specific `mk_re_*` methods, where possible, // to avoid the cost of the `match`. - pub fn mk_region(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> { + pub fn mk_region_from_kind(self, kind: ty::RegionKind<'tcx>) -> Region<'tcx> { match kind { ty::ReEarlyBound(region) => self.mk_re_early_bound(region), ty::ReLateBound(debruijn, region) => self.mk_re_late_bound(debruijn, region), diff --git a/compiler/rustc_middle/src/ty/structural_impls.rs b/compiler/rustc_middle/src/ty/structural_impls.rs index 43fbccea5cae0..1d4d76da5722b 100644 --- a/compiler/rustc_middle/src/ty/structural_impls.rs +++ b/compiler/rustc_middle/src/ty/structural_impls.rs @@ -513,7 +513,7 @@ impl<'tcx> TypeSuperFoldable> for Ty<'tcx> { | ty::Foreign(..) => return Ok(self), }; - Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty(kind) }) + Ok(if *self.kind() == kind { self } else { folder.interner().mk_ty_from_kind(kind) }) } } diff --git a/compiler/rustc_traits/src/chalk/lowering.rs b/compiler/rustc_traits/src/chalk/lowering.rs index 179ed1220f913..60e22d1001c81 100644 --- a/compiler/rustc_traits/src/chalk/lowering.rs +++ b/compiler/rustc_traits/src/chalk/lowering.rs @@ -489,7 +489,7 @@ impl<'tcx> LowerInto<'tcx, Ty<'tcx>> for &chalk_ir::Ty> { TyKind::InferenceVar(_, _) => unimplemented!(), TyKind::Dyn(_) => unimplemented!(), }; - interner.tcx.mk_ty(kind) + interner.tcx.mk_ty_from_kind(kind) } } From c09f5b6a6b82f785165c68546d323011fad052c0 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 20 Feb 2023 10:46:37 +1100 Subject: [PATCH 5/6] Add `mk_canonical_var_infos_from_iter`. It's missing, and is useful in two places. --- compiler/rustc_middle/src/ty/codec.rs | 6 ++-- compiler/rustc_middle/src/ty/context.rs | 8 ++++++ compiler/rustc_traits/src/chalk/mod.rs | 37 ++++++++++++------------- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/compiler/rustc_middle/src/ty/codec.rs b/compiler/rustc_middle/src/ty/codec.rs index 99a5921d93dcc..3ce80e06ad9ef 100644 --- a/compiler/rustc_middle/src/ty/codec.rs +++ b/compiler/rustc_middle/src/ty/codec.rs @@ -270,9 +270,9 @@ impl<'tcx, D: TyDecoder>> Decodable for ty::Region<'tcx> { impl<'tcx, D: TyDecoder>> Decodable for CanonicalVarInfos<'tcx> { fn decode(decoder: &mut D) -> Self { let len = decoder.read_usize(); - let interned: Vec> = - (0..len).map(|_| Decodable::decode(decoder)).collect(); - decoder.interner().mk_canonical_var_infos(&interned) + decoder.interner().mk_canonical_var_infos_from_iter( + (0..len).map::, _>(|_| Decodable::decode(decoder)), + ) } } diff --git a/compiler/rustc_middle/src/ty/context.rs b/compiler/rustc_middle/src/ty/context.rs index e5301791318b5..212dec9413038 100644 --- a/compiler/rustc_middle/src/ty/context.rs +++ b/compiler/rustc_middle/src/ty/context.rs @@ -2253,6 +2253,14 @@ impl<'tcx> TyCtxt<'tcx> { T::collect_and_apply(iter, |xs| self.mk_substs(xs)) } + pub fn mk_canonical_var_infos_from_iter(self, iter: I) -> T::Output + where + I: Iterator, + T: CollectAndApply, &'tcx List>>, + { + T::collect_and_apply(iter, |xs| self.mk_canonical_var_infos(xs)) + } + pub fn mk_place_elems_from_iter(self, iter: I) -> T::Output where I: Iterator, diff --git a/compiler/rustc_traits/src/chalk/mod.rs b/compiler/rustc_traits/src/chalk/mod.rs index 1fbc3214967f6..a5ebc26a8bc96 100644 --- a/compiler/rustc_traits/src/chalk/mod.rs +++ b/compiler/rustc_traits/src/chalk/mod.rs @@ -102,31 +102,28 @@ pub(crate) fn evaluate_goal<'tcx>( .iter() .map(|p| p.lower_into(interner).fold_with(&mut reverse_param_substitutor)), ); - let variables: Vec<_> = binders - .iter(interner) - .map(|var| { - let kind = match var.kind { - chalk_ir::VariableKind::Ty(ty_kind) => CanonicalVarKind::Ty(match ty_kind { - chalk_ir::TyVariableKind::General => CanonicalTyVarKind::General( - ty::UniverseIndex::from_usize(var.skip_kind().counter), - ), - chalk_ir::TyVariableKind::Integer => CanonicalTyVarKind::Int, - chalk_ir::TyVariableKind::Float => CanonicalTyVarKind::Float, - }), - chalk_ir::VariableKind::Lifetime => CanonicalVarKind::Region( + let variables = binders.iter(interner).map(|var| { + let kind = match var.kind { + chalk_ir::VariableKind::Ty(ty_kind) => CanonicalVarKind::Ty(match ty_kind { + chalk_ir::TyVariableKind::General => CanonicalTyVarKind::General( ty::UniverseIndex::from_usize(var.skip_kind().counter), ), - // FIXME(compiler-errors): We don't currently have a way of turning - // a Chalk ty back into a rustc ty, right? - chalk_ir::VariableKind::Const(_) => todo!(), - }; - CanonicalVarInfo { kind } - }) - .collect(); + chalk_ir::TyVariableKind::Integer => CanonicalTyVarKind::Int, + chalk_ir::TyVariableKind::Float => CanonicalTyVarKind::Float, + }), + chalk_ir::VariableKind::Lifetime => { + CanonicalVarKind::Region(ty::UniverseIndex::from_usize(var.skip_kind().counter)) + } + // FIXME(compiler-errors): We don't currently have a way of turning + // a Chalk ty back into a rustc ty, right? + chalk_ir::VariableKind::Const(_) => todo!(), + }; + CanonicalVarInfo { kind } + }); let max_universe = binders.iter(interner).map(|v| v.skip_kind().counter).max().unwrap_or(0); let sol = Canonical { max_universe: ty::UniverseIndex::from_usize(max_universe), - variables: tcx.mk_canonical_var_infos(&variables), + variables: tcx.mk_canonical_var_infos_from_iter(variables), value: QueryResponse { var_values: CanonicalVarValues { var_values }, region_constraints: QueryRegionConstraints::default(), From 08f28f94479d09ae5f7d2cf1d3c018b714751c35 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Mon, 20 Feb 2023 14:52:23 +1100 Subject: [PATCH 6/6] Use `List::empty()` instead of `mk_substs(&[])`. --- compiler/rustc_codegen_gcc/src/context.rs | 2 +- compiler/rustc_codegen_llvm/src/context.rs | 2 +- compiler/rustc_lint/src/builtin.rs | 6 +++--- compiler/rustc_middle/src/mir/mod.rs | 2 +- src/tools/clippy/clippy_utils/src/consts.rs | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/compiler/rustc_codegen_gcc/src/context.rs b/compiler/rustc_codegen_gcc/src/context.rs index fc746fbd599f2..457006319afb8 100644 --- a/compiler/rustc_codegen_gcc/src/context.rs +++ b/compiler/rustc_codegen_gcc/src/context.rs @@ -383,7 +383,7 @@ impl<'gcc, 'tcx> MiscMethods<'tcx> for CodegenCx<'gcc, 'tcx> { tcx, ty::ParamEnv::reveal_all(), def_id, - tcx.mk_substs(&[]), + ty::List::empty(), ) .unwrap().unwrap(), ), diff --git a/compiler/rustc_codegen_llvm/src/context.rs b/compiler/rustc_codegen_llvm/src/context.rs index 47dcbba59ac3c..3d29968d5d688 100644 --- a/compiler/rustc_codegen_llvm/src/context.rs +++ b/compiler/rustc_codegen_llvm/src/context.rs @@ -520,7 +520,7 @@ impl<'ll, 'tcx> MiscMethods<'tcx> for CodegenCx<'ll, 'tcx> { let tcx = self.tcx; let llfn = match tcx.lang_items().eh_personality() { Some(def_id) if !wants_msvc_seh(self.sess()) => self.get_fn_addr( - ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, tcx.mk_substs(&[])) + ty::Instance::resolve(tcx, ty::ParamEnv::reveal_all(), def_id, ty::List::empty()) .unwrap() .unwrap(), ), diff --git a/compiler/rustc_lint/src/builtin.rs b/compiler/rustc_lint/src/builtin.rs index 45c12d2938fa4..59540aaf18fc5 100644 --- a/compiler/rustc_lint/src/builtin.rs +++ b/compiler/rustc_lint/src/builtin.rs @@ -677,21 +677,21 @@ impl<'tcx> LateLintPass<'tcx> for MissingCopyImplementations { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, cx.tcx.mk_substs(&[]))) + (def, cx.tcx.mk_adt(def, ty::List::empty())) } hir::ItemKind::Union(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, cx.tcx.mk_substs(&[]))) + (def, cx.tcx.mk_adt(def, ty::List::empty())) } hir::ItemKind::Enum(_, ref ast_generics) => { if !ast_generics.params.is_empty() { return; } let def = cx.tcx.adt_def(item.owner_id); - (def, cx.tcx.mk_adt(def, cx.tcx.mk_substs(&[]))) + (def, cx.tcx.mk_adt(def, ty::List::empty())) } _ => return, }; diff --git a/compiler/rustc_middle/src/mir/mod.rs b/compiler/rustc_middle/src/mir/mod.rs index 7de9800d4c496..0d78c6135b336 100644 --- a/compiler/rustc_middle/src/mir/mod.rs +++ b/compiler/rustc_middle/src/mir/mod.rs @@ -2530,7 +2530,7 @@ impl<'tcx> ConstantKind<'tcx> { { InternalSubsts::identity_for_item(tcx, parent_did.to_def_id()) } else { - tcx.mk_substs(&[]) + List::empty() }; debug!(?parent_substs); diff --git a/src/tools/clippy/clippy_utils/src/consts.rs b/src/tools/clippy/clippy_utils/src/consts.rs index e3bfffacb5250..bb8890dcaf988 100644 --- a/src/tools/clippy/clippy_utils/src/consts.rs +++ b/src/tools/clippy/clippy_utils/src/consts.rs @@ -237,7 +237,7 @@ pub fn constant<'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.mk_substs(&[]), + substs: ty::List::empty(), }; cx.expr(e).map(|cst| (cst, cx.needed_resolution)) } @@ -306,7 +306,7 @@ pub fn constant_context<'a, 'tcx>( typeck_results, param_env: lcx.param_env, needed_resolution: false, - substs: lcx.tcx.mk_substs(&[]), + substs: ty::List::empty(), } }