EarlyBinder nits

This commit is contained in:
Michael Goulet 2022-10-26 21:50:25 +00:00
parent b96d9e0e20
commit 5dea1d1c6e
4 changed files with 20 additions and 17 deletions

View file

@ -26,11 +26,9 @@ use rustc_hir::intravisit::{walk_generics, Visitor as _};
use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin}; use rustc_hir::{GenericArg, GenericArgs, OpaqueTyOrigin};
use rustc_middle::middle::stability::AllowUnstable; use rustc_middle::middle::stability::AllowUnstable;
use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef}; use rustc_middle::ty::subst::{self, GenericArgKind, InternalSubsts, SubstsRef};
use rustc_middle::ty::DynKind;
use rustc_middle::ty::GenericParamDefKind; use rustc_middle::ty::GenericParamDefKind;
use rustc_middle::ty::{ use rustc_middle::ty::{self, Const, DefIdTree, IsSuggestable, Ty, TyCtxt, TypeVisitable};
self, Const, DefIdTree, EarlyBinder, IsSuggestable, Ty, TyCtxt, TypeVisitable, use rustc_middle::ty::{DynKind, EarlyBinder};
};
use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS}; use rustc_session::lint::builtin::{AMBIGUOUS_ASSOCIATED_ITEMS, BARE_TRAIT_OBJECTS};
use rustc_span::edition::Edition; use rustc_span::edition::Edition;
use rustc_span::lev_distance::find_best_match_for_name; use rustc_span::lev_distance::find_best_match_for_name;
@ -490,7 +488,8 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
self.astconv self.astconv
.normalize_ty( .normalize_ty(
self.span, self.span,
EarlyBinder(tcx.at(self.span).type_of(param.def_id)) tcx.at(self.span)
.bound_type_of(param.def_id)
.subst(tcx, substs), .subst(tcx, substs),
) )
.into() .into()
@ -1258,10 +1257,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
item_segment: &hir::PathSegment<'_>, item_segment: &hir::PathSegment<'_>,
) -> Ty<'tcx> { ) -> Ty<'tcx> {
let substs = self.ast_path_substs_for_ty(span, did, item_segment); let substs = self.ast_path_substs_for_ty(span, did, item_segment);
self.normalize_ty( self.normalize_ty(span, self.tcx().at(span).bound_type_of(did).subst(self.tcx(), substs))
span,
EarlyBinder(self.tcx().at(span).type_of(did)).subst(self.tcx(), substs),
)
} }
fn conv_object_ty_poly_trait_ref( fn conv_object_ty_poly_trait_ref(

View file

@ -336,6 +336,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
/// Basically whenever we are converting from a type scheme into /// Basically whenever we are converting from a type scheme into
/// the fn body space, we always want to normalize associated /// the fn body space, we always want to normalize associated
/// types as well. This function combines the two. /// 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 fn instantiate_type_scheme<T>(&self, span: Span, substs: SubstsRef<'tcx>, value: T) -> T
where where
T: TypeFoldable<'tcx>, T: TypeFoldable<'tcx>,

View file

@ -5,7 +5,7 @@ use crate::infer::{GenericKind, VerifyBound};
use rustc_data_structures::sso::SsoHashSet; use rustc_data_structures::sso::SsoHashSet;
use rustc_hir::def_id::DefId; use rustc_hir::def_id::DefId;
use rustc_middle::ty::GenericArg; use rustc_middle::ty::GenericArg;
use rustc_middle::ty::{self, EarlyBinder, OutlivesPredicate, SubstsRef, Ty, TyCtxt}; use rustc_middle::ty::{self, OutlivesPredicate, SubstsRef, Ty, TyCtxt};
use smallvec::smallvec; use smallvec::smallvec;
@ -304,14 +304,13 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
substs: SubstsRef<'tcx>, substs: SubstsRef<'tcx>,
) -> impl Iterator<Item = ty::Region<'tcx>> { ) -> impl Iterator<Item = ty::Region<'tcx>> {
let tcx = self.tcx; let tcx = self.tcx;
let bounds = tcx.item_bounds(def_id); let bounds = tcx.bound_item_bounds(def_id);
trace!("{:#?}", bounds); trace!("{:#?}", bounds.0);
bounds bounds
.into_iter() .subst_iter(tcx, substs)
.filter_map(|p| p.to_opt_type_outlives()) .filter_map(|p| p.to_opt_type_outlives())
.filter_map(|p| p.no_bound_vars()) .filter_map(|p| p.no_bound_vars())
.map(|b| b.1) .map(|OutlivesPredicate(_, r)| r)
.map(move |r| EarlyBinder(r).subst(tcx, substs))
} }
/// Searches through a predicate list for a predicate `T: 'a`. /// Searches through a predicate list for a predicate `T: 'a`.

View file

@ -4,9 +4,10 @@ use crate::middle::codegen_fn_attrs::CodegenFnAttrFlags;
use crate::mir; use crate::mir;
use crate::ty::layout::IntegerExt; use crate::ty::layout::IntegerExt;
use crate::ty::{ use crate::ty::{
self, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder, TypeSuperFoldable, self, DefIdTree, FallibleTypeFolder, Ty, TyCtxt, TypeFoldable, TypeFolder,
TypeVisitable, TypeSuperFoldable, TypeVisitable,
}; };
use crate::ty::query::TyCtxtAt;
use crate::ty::{GenericArgKind, SubstsRef}; use crate::ty::{GenericArgKind, SubstsRef};
use rustc_apfloat::Float as _; use rustc_apfloat::Float as _;
use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_data_structures::fx::{FxHashMap, FxHashSet};
@ -770,6 +771,12 @@ impl<'tcx> TyCtxt<'tcx> {
} }
} }
impl<'tcx> TyCtxtAt<'tcx> {
pub fn bound_type_of(self, def_id: DefId) -> ty::EarlyBinder<Ty<'tcx>> {
ty::EarlyBinder(self.type_of(def_id))
}
}
struct OpaqueTypeExpander<'tcx> { struct OpaqueTypeExpander<'tcx> {
// Contains the DefIds of the opaque types that are currently being // Contains the DefIds of the opaque types that are currently being
// expanded. When we expand an opaque type we insert the DefId of // expanded. When we expand an opaque type we insert the DefId of