Arrange methods on HirTyLowerer more logically
This makes it easier to read the trait definition for newcomers: Sorted from least “complex” to most “complex” followed by trivial “plumbing” and grouped by area. * Move `allow_infer` above all `*_infer` methods * It's the least complex method of those * Allows the `*_infer` to be placed right next to each other * Move `probe_ty_param_bounds` further down right next to `lower_assoc_ty` and `probe_adt` * It's more complex than the `infer` methods, it should come “later” * Now all required lowering functions are grouped together * Move the “plumbing” function `set_tainted_by_errors` further down below any actual lowering methods. * Provided method should come last
This commit is contained in:
parent
6d5a93949a
commit
72472c831c
3 changed files with 72 additions and 72 deletions
|
@ -372,23 +372,14 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||
self.item_def_id.to_def_id()
|
||||
}
|
||||
|
||||
fn probe_ty_param_bounds(
|
||||
&self,
|
||||
span: Span,
|
||||
def_id: LocalDefId,
|
||||
assoc_name: Ident,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name))
|
||||
fn allow_infer(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn re_infer(&self, _: Option<&ty::GenericParamDef>, _: Span) -> Option<ty::Region<'tcx>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn allow_infer(&self) -> bool {
|
||||
false
|
||||
}
|
||||
|
||||
fn ty_infer(&self, _: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
||||
Ty::new_error_with_message(self.tcx(), span, "bad placeholder type")
|
||||
}
|
||||
|
@ -403,6 +394,15 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||
ty::Const::new_error_with_message(self.tcx(), ty, span, "bad placeholder constant")
|
||||
}
|
||||
|
||||
fn probe_ty_param_bounds(
|
||||
&self,
|
||||
span: Span,
|
||||
def_id: LocalDefId,
|
||||
assoc_name: Ident,
|
||||
) -> ty::GenericPredicates<'tcx> {
|
||||
self.tcx.at(span).type_param_predicates((self.item_def_id, def_id, assoc_name))
|
||||
}
|
||||
|
||||
fn lower_assoc_ty(
|
||||
&self,
|
||||
span: Span,
|
||||
|
@ -496,10 +496,6 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||
ty.ty_adt_def()
|
||||
}
|
||||
|
||||
fn set_tainted_by_errors(&self, err: ErrorGuaranteed) {
|
||||
self.tainted_by_errors.set(Some(err));
|
||||
}
|
||||
|
||||
fn record_ty(&self, _hir_id: hir::HirId, _ty: Ty<'tcx>, _span: Span) {
|
||||
// There's no place to record types from signatures?
|
||||
}
|
||||
|
@ -507,6 +503,10 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
|
|||
fn infcx(&self) -> Option<&InferCtxt<'tcx>> {
|
||||
None
|
||||
}
|
||||
|
||||
fn set_tainted_by_errors(&self, err: ErrorGuaranteed) {
|
||||
self.tainted_by_errors.set(Some(err));
|
||||
}
|
||||
}
|
||||
|
||||
/// Synthesize a new lifetime name that doesn't clash with any of the lifetimes already present.
|
||||
|
|
|
@ -89,6 +89,24 @@ pub trait HirTyLowerer<'tcx> {
|
|||
/// Returns the [`DefId`] of the overarching item whose constituents get lowered.
|
||||
fn item_def_id(&self) -> DefId;
|
||||
|
||||
/// Returns `true` if the current context allows the use of inference variables.
|
||||
fn allow_infer(&self) -> bool;
|
||||
|
||||
/// Returns the region to use when a lifetime is omitted (and not elided).
|
||||
fn re_infer(&self, param: Option<&ty::GenericParamDef>, span: Span)
|
||||
-> Option<ty::Region<'tcx>>;
|
||||
|
||||
/// Returns the type to use when a type is omitted.
|
||||
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
|
||||
|
||||
/// Returns the const to use when a const is omitted.
|
||||
fn ct_infer(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
param: Option<&ty::GenericParamDef>,
|
||||
span: Span,
|
||||
) -> Const<'tcx>;
|
||||
|
||||
/// Probe bounds in scope where the bounded type coincides with the given type parameter.
|
||||
///
|
||||
/// Rephrased, this returns bounds of the form `T: Trait`, where `T` is a type parameter
|
||||
|
@ -110,24 +128,6 @@ pub trait HirTyLowerer<'tcx> {
|
|||
assoc_name: Ident,
|
||||
) -> ty::GenericPredicates<'tcx>;
|
||||
|
||||
/// Returns the region to use when a lifetime is omitted (and not elided).
|
||||
fn re_infer(&self, param: Option<&ty::GenericParamDef>, span: Span)
|
||||
-> Option<ty::Region<'tcx>>;
|
||||
|
||||
/// Returns the type to use when a type is omitted.
|
||||
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx>;
|
||||
|
||||
/// Returns `true` if the current context allows the use of inference variables.
|
||||
fn allow_infer(&self) -> bool;
|
||||
|
||||
/// Returns the const to use when a const is omitted.
|
||||
fn ct_infer(
|
||||
&self,
|
||||
ty: Ty<'tcx>,
|
||||
param: Option<&ty::GenericParamDef>,
|
||||
span: Span,
|
||||
) -> Const<'tcx>;
|
||||
|
||||
/// Lower an associated type to a projection.
|
||||
///
|
||||
/// This method has to be defined by the concrete lowering context because
|
||||
|
@ -156,15 +156,18 @@ pub trait HirTyLowerer<'tcx> {
|
|||
/// or to an enum variant depending on the result of this function.
|
||||
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<ty::AdtDef<'tcx>>;
|
||||
|
||||
/// Record the lowered type of a HIR node in this context.
|
||||
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
|
||||
|
||||
/// The inference context of the lowering context if applicable.
|
||||
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
|
||||
|
||||
/// Taint the context with errors.
|
||||
///
|
||||
/// Invoke this when you encounter an error from some prior pass like name resolution.
|
||||
/// This is used to help suppress derived errors typeck might otherwise report.
|
||||
fn set_tainted_by_errors(&self, e: ErrorGuaranteed);
|
||||
|
||||
/// Record the lowered type of a HIR node in this context.
|
||||
fn record_ty(&self, hir_id: hir::HirId, ty: Ty<'tcx>, span: Span);
|
||||
|
||||
/// Convenience method for coercing the lowering context into a trait object type.
|
||||
///
|
||||
/// Most lowering routines are defined on the trait object type directly
|
||||
|
@ -175,9 +178,6 @@ pub trait HirTyLowerer<'tcx> {
|
|||
{
|
||||
self
|
||||
}
|
||||
|
||||
/// The inference context of the lowering context if applicable.
|
||||
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
|
||||
}
|
||||
|
||||
/// New-typed boolean indicating whether explicit late-bound lifetimes
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue