diff options
| author | Michael Goulet <michael@errs.io> | 2022-10-26 23:53:47 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2022-12-13 04:56:44 +0000 |
| commit | f705d646738ea8b1238e1c9a58c16532cc4d73a6 (patch) | |
| tree | 257fa07398d8e0f105d56a355ca11e2ac92d411c | |
| parent | 5dea1d1c6e03102e5a42c03e50a7ad8107b20411 (diff) | |
| download | rust-f705d646738ea8b1238e1c9a58c16532cc4d73a6.tar.gz rust-f705d646738ea8b1238e1c9a58c16532cc4d73a6.zip | |
Remove instantiate_type_scheme
| -rw-r--r-- | compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs | 35 | ||||
| -rw-r--r-- | compiler/rustc_hir_typeck/src/method/mod.rs | 6 | ||||
| -rw-r--r-- | compiler/rustc_middle/src/ty/util.rs | 6 |
3 files changed, 13 insertions, 34 deletions
diff --git a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs index 5ca986f23ff..bbb2a9d6412 100644 --- a/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs +++ b/compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs @@ -22,7 +22,7 @@ use rustc_middle::ty::error::TypeError; use rustc_middle::ty::fold::TypeFoldable; use rustc_middle::ty::visit::TypeVisitable; use rustc_middle::ty::{ - self, AdtKind, CanonicalUserType, DefIdTree, EarlyBinder, GenericParamDefKind, Ty, UserType, + self, AdtKind, CanonicalUserType, DefIdTree, GenericParamDefKind, Ty, UserType, }; use rustc_middle::ty::{GenericArgKind, InternalSubsts, SubstsRef, UserSelfTy, UserSubsts}; use rustc_session::lint; @@ -333,23 +333,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { } } - /// Basically whenever we are converting from a type scheme into - /// the fn body space, we always want to normalize associated - /// types as well. This function combines the two. - // FIXME(compiler-errors): Remove this. - fn instantiate_type_scheme<T>(&self, span: Span, substs: SubstsRef<'tcx>, value: T) -> T - where - T: TypeFoldable<'tcx>, - { - debug!("instantiate_type_scheme(value={:?}, substs={:?})", value, substs); - let value = EarlyBinder(value).subst(self.tcx, substs); - let result = self.normalize(span, value); - debug!("instantiate_type_scheme = {:?}", result); - result - } - - /// As `instantiate_type_scheme`, but for the bounds found in a - /// generic type scheme. + /// Instantiates and normalizes the bounds for a given item pub(in super::super) fn instantiate_bounds( &self, span: Span, @@ -1161,10 +1145,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }; let def_id = res.def_id(); - // The things we are substituting into the type should not contain - // escaping late-bound regions, and nor should the base type scheme. - let ty = tcx.type_of(def_id); - let arg_count = GenericArgCountResult { explicit_late_bound, correct: if infer_args_for_err.is_empty() { @@ -1287,8 +1267,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { }, ) }); - assert!(!substs.has_escaping_bound_vars()); - assert!(!ty.has_escaping_bound_vars()); // First, store the "user substs" for later. self.write_user_type_annotation_from_substs(hir_id, def_id, substs, user_self_ty); @@ -1297,7 +1275,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Substitute the values for the type parameters into the type of // the referenced item. - let ty_substituted = self.instantiate_type_scheme(span, &substs, ty); + let ty = tcx.bound_type_of(def_id); + assert!(!substs.has_escaping_bound_vars()); + assert!(!ty.0.has_escaping_bound_vars()); + let ty_substituted = self.normalize(span, ty.subst(tcx, substs)); if let Some(UserSelfTy { impl_def_id, self_ty }) = user_self_ty { // In the case of `Foo<T>::method` and `<Foo<T>>::method`, if `method` @@ -1305,9 +1286,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // type parameters, which we can infer by unifying the provided `Self` // with the substituted impl type. // This also occurs for an enum variant on a type alias. - let ty = tcx.type_of(impl_def_id); - - let impl_ty = self.instantiate_type_scheme(span, &substs, ty); + let impl_ty = self.normalize(span, tcx.bound_type_of(impl_def_id).subst(tcx, substs)); match self.at(&self.misc(span), self.param_env).eq(impl_ty, self_ty) { Ok(ok) => self.register_infer_ok_obligations(ok), Err(_) => { diff --git a/compiler/rustc_hir_typeck/src/method/mod.rs b/compiler/rustc_hir_typeck/src/method/mod.rs index b15c086ffad..274abf8177f 100644 --- a/compiler/rustc_hir_typeck/src/method/mod.rs +++ b/compiler/rustc_hir_typeck/src/method/mod.rs @@ -456,9 +456,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { // Instantiate late-bound regions and substitute the trait // parameters into the method type to get the actual method type. // - // N.B., instantiate late-bound regions first so that - // `instantiate_type_scheme` can normalize associated types that - // may reference those regions. + // N.B., instantiate late-bound regions before normalizing the + // function signature so that normalization does not need to deal + // with bound regions. let fn_sig = tcx.bound_fn_sig(def_id); let fn_sig = fn_sig.subst(self.tcx, substs); let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig); diff --git a/compiler/rustc_middle/src/ty/util.rs b/compiler/rustc_middle/src/ty/util.rs index ce2519787ec..54804d6a40d 100644 --- a/compiler/rustc_middle/src/ty/util.rs +++ b/compiler/rustc_middle/src/ty/util.rs @@ -3,11 +3,11 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags; use crate::mir; use crate::ty::layout::IntegerExt; +use crate::ty::query::TyCtxtAt; use crate::ty::{ - self, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, - TypeSuperFoldable, TypeVisitable, + self, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, + TypeVisitable, }; -use crate::ty::query::TyCtxtAt; use crate::ty::{GenericArgKind, SubstsRef}; use rustc_apfloat::Float as _; use rustc_data_structures::fx::{FxHashMap, FxHashSet}; |
