pub trait HirTyLowerer<'tcx> {
Show 13 methods
// Required methods
fn tcx(&self) -> TyCtxt<'tcx>;
fn dcx(&self) -> DiagCtxtHandle<'_>;
fn item_def_id(&self) -> LocalDefId;
fn re_infer(
&self,
span: Span,
reason: RegionInferReason<'_>,
) -> Region<'tcx>;
fn ty_infer(&self, param: Option<&GenericParamDef>, span: Span) -> Ty<'tcx>;
fn ct_infer(
&self,
param: Option<&GenericParamDef>,
span: Span,
) -> Const<'tcx>;
fn probe_ty_param_bounds(
&self,
span: Span,
def_id: LocalDefId,
assoc_name: Ident,
) -> EarlyBinder<'tcx, &'tcx [(Clause<'tcx>, Span)]>;
fn lower_assoc_ty(
&self,
span: Span,
item_def_id: DefId,
item_segment: &PathSegment<'tcx>,
poly_trait_ref: PolyTraitRef<'tcx>,
) -> Ty<'tcx>;
fn lower_fn_sig(
&self,
decl: &FnDecl<'tcx>,
generics: Option<&Generics<'_>>,
hir_id: HirId,
hir_ty: Option<&Ty<'_>>,
) -> (Vec<Ty<'tcx>>, Ty<'tcx>);
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<AdtDef<'tcx>>;
fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span);
fn infcx(&self) -> Option<&InferCtxt<'tcx>>;
// Provided method
fn lowerer(&self) -> &dyn HirTyLowerer<'tcx>
where Self: Sized { ... }
}
Expand description
A context which can lower type-system entities from the HIR to
the rustc_middle::ty
representation.
This trait used to be called AstConv
.
Required Methods§
fn tcx(&self) -> TyCtxt<'tcx>
fn dcx(&self) -> DiagCtxtHandle<'_>
sourcefn item_def_id(&self) -> LocalDefId
fn item_def_id(&self) -> LocalDefId
Returns the LocalDefId
of the overarching item whose constituents get lowered.
sourcefn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> Region<'tcx>
fn re_infer(&self, span: Span, reason: RegionInferReason<'_>) -> Region<'tcx>
Returns the region to use when a lifetime is omitted (and not elided).
sourcefn ty_infer(&self, param: Option<&GenericParamDef>, span: Span) -> Ty<'tcx>
fn ty_infer(&self, param: Option<&GenericParamDef>, span: Span) -> Ty<'tcx>
Returns the type to use when a type is omitted.
sourcefn ct_infer(&self, param: Option<&GenericParamDef>, span: Span) -> Const<'tcx>
fn ct_infer(&self, param: Option<&GenericParamDef>, span: Span) -> Const<'tcx>
Returns the const to use when a const is omitted.
sourcefn probe_ty_param_bounds(
&self,
span: Span,
def_id: LocalDefId,
assoc_name: Ident,
) -> EarlyBinder<'tcx, &'tcx [(Clause<'tcx>, Span)]>
fn probe_ty_param_bounds( &self, span: Span, def_id: LocalDefId, assoc_name: Ident, ) -> EarlyBinder<'tcx, &'tcx [(Clause<'tcx>, Span)]>
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
with the given def_id
. This is a subset of the full set of bounds.
This method may use the given assoc_name
to disregard bounds whose trait reference
doesn’t define an associated item with the provided name.
This is used for one specific purpose: Resolving “short-hand” associated type references
like T::Item
where T
is a type parameter. In principle, we would do that by first
getting the full set of predicates in scope and then filtering down to find those that
apply to T
, but this can lead to cycle errors. The problem is that we have to do this
resolution in order to create the predicates in the first place.
Hence, we have this “special pass”.
sourcefn lower_assoc_ty(
&self,
span: Span,
item_def_id: DefId,
item_segment: &PathSegment<'tcx>,
poly_trait_ref: PolyTraitRef<'tcx>,
) -> Ty<'tcx>
fn lower_assoc_ty( &self, span: Span, item_def_id: DefId, item_segment: &PathSegment<'tcx>, poly_trait_ref: PolyTraitRef<'tcx>, ) -> Ty<'tcx>
Lower an associated type to a projection.
This method has to be defined by the concrete lowering context because dealing with higher-ranked trait references depends on its capabilities:
If the context can make use of type inference, it can simply instantiate any late-bound vars bound by the trait reference with inference variables. If it doesn’t support type inference, there is nothing reasonable it can do except reject the associated type.
The canonical example of this is associated type T::P
where T
is a type
param constrained by T: for<'a> Trait<'a>
and where Trait
defines P
.
fn lower_fn_sig( &self, decl: &FnDecl<'tcx>, generics: Option<&Generics<'_>>, hir_id: HirId, hir_ty: Option<&Ty<'_>>, ) -> (Vec<Ty<'tcx>>, Ty<'tcx>)
sourcefn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<AdtDef<'tcx>>
fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<AdtDef<'tcx>>
Returns AdtDef
if ty
is an ADT.
Note that ty
might be a alias type that needs normalization.
This used to get the enum variants in scope of the type.
For example, Self::A
could refer to an associated type
or to an enum variant depending on the result of this function.
Provided Methods§
sourcefn lowerer(&self) -> &dyn HirTyLowerer<'tcx>where
Self: Sized,
fn lowerer(&self) -> &dyn HirTyLowerer<'tcx>where
Self: Sized,
Convenience method for coercing the lowering context into a trait object type.
Most lowering routines are defined on the trait object type directly necessitating a coercion step from the concrete lowering context.
Implementations§
source§impl<'tcx> dyn HirTyLowerer<'tcx> + '_
impl<'tcx> dyn HirTyLowerer<'tcx> + '_
sourcepub(crate) fn add_sized_bound(
&self,
bounds: &mut Bounds<'tcx>,
self_ty: Ty<'tcx>,
hir_bounds: &'tcx [GenericBound<'tcx>],
self_ty_where_predicates: Option<(LocalDefId, &'tcx [WherePredicate<'tcx>])>,
span: Span,
)
pub(crate) fn add_sized_bound( &self, bounds: &mut Bounds<'tcx>, self_ty: Ty<'tcx>, hir_bounds: &'tcx [GenericBound<'tcx>], self_ty_where_predicates: Option<(LocalDefId, &'tcx [WherePredicate<'tcx>])>, span: Span, )
Add a Sized
bound to the bounds
if appropriate.
Doesn’t add the bound if the HIR bounds contain any of Sized
, ?Sized
or !Sized
.
sourcepub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir GenericBound<'tcx>>>(
&self,
param_ty: Ty<'tcx>,
hir_bounds: I,
bounds: &mut Bounds<'tcx>,
bound_vars: &'tcx List<BoundVariableKind>,
only_self_bounds: OnlySelfBounds,
)where
'tcx: 'hir,
pub(crate) fn lower_poly_bounds<'hir, I: Iterator<Item = &'hir GenericBound<'tcx>>>(
&self,
param_ty: Ty<'tcx>,
hir_bounds: I,
bounds: &mut Bounds<'tcx>,
bound_vars: &'tcx List<BoundVariableKind>,
only_self_bounds: OnlySelfBounds,
)where
'tcx: 'hir,
Lower HIR bounds into bounds
given the self type param_ty
and the overarching late-bound vars if any.
§Examples
fn foo<T>() where for<'a> T: Trait<'a> + Copy {}
// ^^^^^^^ ^ ^^^^^^^^^^^^^^^^ `hir_bounds`, in HIR form
// | |
// | `param_ty`, in ty form
// `bound_vars`, in ty form
fn bar<T>() where T: for<'a> Trait<'a> + Copy {} // no overarching `bound_vars` here!
// ^ ^^^^^^^^^^^^^^^^^^^^^^^^ `hir_bounds`, in HIR form
// |
// `param_ty`, in ty form
§A Note on Binders
There is an implied binder around param_ty
and hir_bounds
.
See lower_poly_trait_ref
for more details.
sourcepub(crate) fn lower_mono_bounds(
&self,
param_ty: Ty<'tcx>,
hir_bounds: &[GenericBound<'tcx>],
filter: PredicateFilter,
) -> Bounds<'tcx>
pub(crate) fn lower_mono_bounds( &self, param_ty: Ty<'tcx>, hir_bounds: &[GenericBound<'tcx>], filter: PredicateFilter, ) -> Bounds<'tcx>
sourcepub(super) fn lower_assoc_item_constraint(
&self,
hir_ref_id: HirId,
trait_ref: PolyTraitRef<'tcx>,
constraint: &AssocItemConstraint<'tcx>,
bounds: &mut Bounds<'tcx>,
duplicates: &mut FxIndexMap<DefId, Span>,
path_span: Span,
only_self_bounds: OnlySelfBounds,
) -> Result<(), ErrorGuaranteed>
pub(super) fn lower_assoc_item_constraint( &self, hir_ref_id: HirId, trait_ref: PolyTraitRef<'tcx>, constraint: &AssocItemConstraint<'tcx>, bounds: &mut Bounds<'tcx>, duplicates: &mut FxIndexMap<DefId, Span>, path_span: Span, only_self_bounds: OnlySelfBounds, ) -> Result<(), ErrorGuaranteed>
Lower an associated item constraint from the HIR into bounds
.
§A Note on Binders
Given something like T: for<'a> Iterator<Item = &'a u32>
,
the trait_ref
here will be for<'a> T: Iterator
.
The constraint
data however is from inside the binder
(e.g., &'a u32
) and hence may reference bound regions.
source§impl<'tcx> dyn HirTyLowerer<'tcx> + '_
impl<'tcx> dyn HirTyLowerer<'tcx> + '_
sourcepub(crate) fn complain_about_missing_type_params(
&self,
missing_type_params: Vec<Symbol>,
def_id: DefId,
span: Span,
empty_generic_args: bool,
)
pub(crate) fn complain_about_missing_type_params( &self, missing_type_params: Vec<Symbol>, def_id: DefId, span: Span, empty_generic_args: bool, )
On missing type parameters, emit an E0393 error and provide a structured suggestion using the type parameter’s name as a placeholder.
sourcepub(crate) fn complain_about_internal_fn_trait(
&self,
span: Span,
trait_def_id: DefId,
trait_segment: &PathSegment<'_>,
is_impl: bool,
)
pub(crate) fn complain_about_internal_fn_trait( &self, span: Span, trait_def_id: DefId, trait_segment: &PathSegment<'_>, is_impl: bool, )
When the code is using the Fn
traits directly, instead of the Fn(A) -> B
syntax, emit
an error and attempt to build a reasonable structured suggestion.
pub(super) fn complain_about_assoc_item_not_found<I>(
&self,
all_candidates: impl Fn() -> I,
qself: AssocItemQSelf,
assoc_kind: AssocKind,
assoc_name: Ident,
span: Span,
constraint: Option<&AssocItemConstraint<'tcx>>,
) -> ErrorGuaranteedwhere
I: Iterator<Item = PolyTraitRef<'tcx>>,
fn complain_about_assoc_kind_mismatch( &self, assoc_item: &AssocItem, assoc_kind: AssocKind, ident: Ident, span: Span, constraint: Option<&AssocItemConstraint<'tcx>>, ) -> ErrorGuaranteed
pub(super) fn report_ambiguous_assoc_ty( &self, span: Span, types: &[String], traits: &[String], name: Symbol, ) -> ErrorGuaranteed
pub(crate) fn complain_about_ambiguous_inherent_assoc_ty( &self, name: Ident, candidates: Vec<DefId>, span: Span, ) -> ErrorGuaranteed
fn note_ambiguous_inherent_assoc_ty( &self, err: &mut Diag<'_>, candidates: Vec<DefId>, span: Span, )
pub(crate) fn complain_about_inherent_assoc_ty_not_found( &self, name: Ident, self_ty: Ty<'tcx>, candidates: Vec<(DefId, (DefId, DefId))>, fulfillment_errors: Vec<FulfillmentError<'tcx>>, span: Span, ) -> ErrorGuaranteed
sourcepub(crate) fn complain_about_missing_assoc_tys(
&self,
associated_types: FxIndexMap<Span, FxIndexSet<DefId>>,
potential_assoc_types: Vec<usize>,
trait_bounds: &[(PolyTraitRef<'_>, TraitBoundModifier)],
)
pub(crate) fn complain_about_missing_assoc_tys( &self, associated_types: FxIndexMap<Span, FxIndexSet<DefId>>, potential_assoc_types: Vec<usize>, trait_bounds: &[(PolyTraitRef<'_>, TraitBoundModifier)], )
When there are any missing associated types, emit an E0191 error and attempt to supply a
reasonable suggestion on how to write it. For the case of multiple associated types in the
same trait bound have the same name (as they come from different supertraits), we instead
emit a generic note suggesting using a where
clause to constraint instead.
sourcepub(crate) fn maybe_report_similar_assoc_fn(
&self,
span: Span,
qself_ty: Ty<'tcx>,
qself: &Ty<'_>,
) -> Result<(), ErrorGuaranteed>
pub(crate) fn maybe_report_similar_assoc_fn( &self, span: Span, qself_ty: Ty<'tcx>, qself: &Ty<'_>, ) -> Result<(), ErrorGuaranteed>
On ambiguous associated type, look for an associated function whose name matches the
extended path and, if found, emit an E0223 error with a structured suggestion.
e.g. for String::from::utf8
, suggest String::from_utf8
(#109195)
pub fn report_prohibit_generics_error<'a>( &self, segments: impl Iterator<Item = &'a PathSegment<'a>> + Clone, args_visitors: impl Iterator<Item = &'a GenericArg<'a>> + Clone, err_extend: GenericsArgsErrExtend<'_>, ) -> ErrorGuaranteed
pub fn report_trait_object_addition_traits_error( &self, regular_traits: &Vec<TraitAliasExpansionInfo<'_>>, ) -> ErrorGuaranteed
pub fn report_trait_object_with_no_traits_error( &self, span: Span, trait_bounds: &Vec<(Binder<'tcx, TraitRef<'tcx>>, Span)>, ) -> ErrorGuaranteed
source§impl<'tcx> dyn HirTyLowerer<'tcx> + '_
impl<'tcx> dyn HirTyLowerer<'tcx> + '_
sourcepub(super) fn prohibit_or_lint_bare_trait_object_ty(&self, self_ty: &Ty<'_>)
pub(super) fn prohibit_or_lint_bare_trait_object_ty(&self, self_ty: &Ty<'_>)
Prohibit or lint against bare trait object types depending on the edition.
Bare trait object types are ones that aren’t preceded by the keyword dyn
.
In edition 2021 and onward we emit a hard error for them.
sourcefn maybe_suggest_blanket_trait_impl<G: EmissionGuarantee>(
&self,
self_ty: &Ty<'_>,
diag: &mut Diag<'_, G>,
)
fn maybe_suggest_blanket_trait_impl<G: EmissionGuarantee>( &self, self_ty: &Ty<'_>, diag: &mut Diag<'_, G>, )
Make sure that we are in the condition to suggest the blanket implementation.
fn add_generic_param_suggestion( &self, generics: &Generics<'_>, self_ty_span: Span, impl_trait_name: &str, ) -> Vec<(Span, String)>
sourcefn maybe_suggest_impl_trait(
&self,
self_ty: &Ty<'_>,
diag: &mut Diag<'_>,
) -> bool
fn maybe_suggest_impl_trait( &self, self_ty: &Ty<'_>, diag: &mut Diag<'_>, ) -> bool
Make sure that we are in the condition to suggest impl Trait
.
fn maybe_suggest_assoc_ty_bound(&self, self_ty: &Ty<'_>, diag: &mut Diag<'_>)
source§impl<'tcx> dyn HirTyLowerer<'tcx> + '_
impl<'tcx> dyn HirTyLowerer<'tcx> + '_
sourcepub(super) fn lower_trait_object_ty(
&self,
span: Span,
hir_id: HirId,
hir_trait_bounds: &[(PolyTraitRef<'tcx>, TraitBoundModifier)],
lifetime: &Lifetime,
representation: DynKind,
) -> Ty<'tcx>
pub(super) fn lower_trait_object_ty( &self, span: Span, hir_id: HirId, hir_trait_bounds: &[(PolyTraitRef<'tcx>, TraitBoundModifier)], lifetime: &Lifetime, representation: DynKind, ) -> Ty<'tcx>
Lower a trait object type from the HIR to our internal notion of a type.
source§impl<'tcx> dyn HirTyLowerer<'tcx> + '_
impl<'tcx> dyn HirTyLowerer<'tcx> + '_
sourcepub fn lower_lifetime(
&self,
lifetime: &Lifetime,
reason: RegionInferReason<'_>,
) -> Region<'tcx>
pub fn lower_lifetime( &self, lifetime: &Lifetime, reason: RegionInferReason<'_>, ) -> Region<'tcx>
Lower a lifetime from the HIR to our internal notion of a lifetime called a region.
pub fn lower_generic_args_of_path_segment( &self, span: Span, def_id: DefId, item_segment: &PathSegment<'tcx>, ) -> GenericArgsRef<'tcx>
sourcefn lower_generic_args_of_path(
&self,
span: Span,
def_id: DefId,
parent_args: &[GenericArg<'tcx>],
segment: &PathSegment<'tcx>,
self_ty: Option<Ty<'tcx>>,
constness: BoundConstness,
) -> (GenericArgsRef<'tcx>, GenericArgCountResult)
fn lower_generic_args_of_path( &self, span: Span, def_id: DefId, parent_args: &[GenericArg<'tcx>], segment: &PathSegment<'tcx>, self_ty: Option<Ty<'tcx>>, constness: BoundConstness, ) -> (GenericArgsRef<'tcx>, GenericArgCountResult)
Lower the generic arguments provided to some path.
If this is a trait reference, you also need to pass the self type self_ty
.
The lowering process may involve applying defaulted type parameters.
Associated item constraints are not handled here! They are either lowered via
lower_assoc_item_constraint
or rejected via prohibit_assoc_item_constraint
.
§Example
T: std::ops::Index<usize, Output = u32>
// ^1 ^^^^^^^^^^^^^^2 ^^^^3 ^^^^^^^^^^^4
- The
self_ty
here would refer to the typeT
. - The path in question is the path to the trait
std::ops::Index
, which will have been resolved to adef_id
- The
generic_args
contains info on the<...>
contents. Theusize
type parameters are returned in theGenericArgsRef
- Associated item constraints like
Output = u32
are contained ingeneric_args.constraints
.
Note that the type listing given here is exactly what the user provided.
For (generic) associated types
<Vec<u8> as Iterable<u8>>::Iter::<'a>
We have the parent args are the args for the parent trait:
[Vec<u8>, u8]
and generic_args
are the arguments for the associated
type itself: ['a]
. The returned GenericArgsRef
concatenates these two
lists: [Vec<u8>, u8, 'a]
.
pub fn lower_generic_args_of_assoc_item( &self, span: Span, item_def_id: DefId, item_segment: &PathSegment<'tcx>, parent_args: GenericArgsRef<'tcx>, ) -> GenericArgsRef<'tcx>
sourcepub fn lower_impl_trait_ref(
&self,
trait_ref: &TraitRef<'tcx>,
self_ty: Ty<'tcx>,
) -> TraitRef<'tcx>
pub fn lower_impl_trait_ref( &self, trait_ref: &TraitRef<'tcx>, self_ty: Ty<'tcx>, ) -> TraitRef<'tcx>
Lower a trait reference as found in an impl header as the implementee.
The self type self_ty
is the implementer of the trait.
sourcepub(crate) fn lower_poly_trait_ref(
&self,
trait_ref: &TraitRef<'tcx>,
span: Span,
constness: BoundConstness,
polarity: PredicatePolarity,
self_ty: Ty<'tcx>,
bounds: &mut Bounds<'tcx>,
only_self_bounds: OnlySelfBounds,
) -> GenericArgCountResult
pub(crate) fn lower_poly_trait_ref( &self, trait_ref: &TraitRef<'tcx>, span: Span, constness: BoundConstness, polarity: PredicatePolarity, self_ty: Ty<'tcx>, bounds: &mut Bounds<'tcx>, only_self_bounds: OnlySelfBounds, ) -> GenericArgCountResult
Lower a polymorphic trait reference given a self type into bounds
.
Polymorphic in the sense that it may bind late-bound vars.
This may generate auxiliary bounds iff the trait reference contains associated item constraints.
§Example
Given the trait ref Iterator<Item = u32>
and the self type Ty
, this will add the
- trait predicate
<Ty as Iterator>
(known asTy: Iterator
in the surface syntax) and the - projection predicate
<Ty as Iterator>::Item = u32
to bounds
.
§A Note on Binders
Against our usual convention, there is an implied binder around the self_ty
and the
trait_ref
here. So they may reference late-bound vars.
If for example you had for<'a> Foo<'a>: Bar<'a>
, then the self_ty
would be Foo<'a>
where 'a
is a bound region at depth 0. Similarly, the trait_ref
would be Bar<'a>
.
The lowered poly-trait-ref will track this binder explicitly, however.
sourcefn lower_mono_trait_ref(
&self,
span: Span,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
trait_segment: &PathSegment<'tcx>,
is_impl: bool,
constness: BoundConstness,
) -> TraitRef<'tcx>
fn lower_mono_trait_ref( &self, span: Span, trait_def_id: DefId, self_ty: Ty<'tcx>, trait_segment: &PathSegment<'tcx>, is_impl: bool, constness: BoundConstness, ) -> TraitRef<'tcx>
Lower a monomorphic trait reference given a self type while prohibiting associated item bindings.
Monomorphic in the sense that it doesn’t bind any late-bound vars.
fn probe_trait_that_defines_assoc_item( &self, trait_def_id: DefId, assoc_kind: AssocKind, assoc_name: Ident, ) -> bool
fn lower_path_segment( &self, span: Span, did: DefId, item_segment: &PathSegment<'tcx>, ) -> Ty<'tcx>
sourcefn probe_single_ty_param_bound_for_assoc_ty(
&self,
ty_param_def_id: LocalDefId,
ty_param_span: Span,
assoc_name: Ident,
span: Span,
) -> Result<PolyTraitRef<'tcx>, ErrorGuaranteed>
fn probe_single_ty_param_bound_for_assoc_ty( &self, ty_param_def_id: LocalDefId, ty_param_span: Span, assoc_name: Ident, span: Span, ) -> Result<PolyTraitRef<'tcx>, ErrorGuaranteed>
Search for a trait bound on a type parameter whose trait defines the associated type given by assoc_name
.
This fails if there is no such bound in the list of candidates or if there are multiple candidates in which case it reports ambiguity.
ty_param_def_id
is the LocalDefId
of the type parameter.
sourcefn probe_single_bound_for_assoc_item<I>(
&self,
all_candidates: impl Fn() -> I,
qself: AssocItemQSelf,
assoc_kind: AssocKind,
assoc_name: Ident,
span: Span,
constraint: Option<&AssocItemConstraint<'tcx>>,
) -> Result<PolyTraitRef<'tcx>, ErrorGuaranteed>where
I: Iterator<Item = PolyTraitRef<'tcx>>,
fn probe_single_bound_for_assoc_item<I>(
&self,
all_candidates: impl Fn() -> I,
qself: AssocItemQSelf,
assoc_kind: AssocKind,
assoc_name: Ident,
span: Span,
constraint: Option<&AssocItemConstraint<'tcx>>,
) -> Result<PolyTraitRef<'tcx>, ErrorGuaranteed>where
I: Iterator<Item = PolyTraitRef<'tcx>>,
Search for a single trait bound whose trait defines the associated item given by assoc_name
.
This fails if there is no such bound in the list of candidates or if there are multiple candidates in which case it reports ambiguity.
sourcepub fn lower_assoc_path(
&self,
hir_ref_id: HirId,
span: Span,
qself_ty: Ty<'tcx>,
qself: &'tcx Ty<'tcx>,
assoc_segment: &'tcx PathSegment<'tcx>,
permit_variants: bool,
) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed>
pub fn lower_assoc_path( &self, hir_ref_id: HirId, span: Span, qself_ty: Ty<'tcx>, qself: &'tcx Ty<'tcx>, assoc_segment: &'tcx PathSegment<'tcx>, permit_variants: bool, ) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed>
Lower a type-relative path referring to an associated type or to an enum variant.
If the path refers to an enum variant and permit_variants
holds,
the returned type is simply the provided self type qself_ty
.
A path like A::B::C::D
is understood as <A::B::C>::D
. I.e.,
qself_ty
/ qself
is A::B::C
and assoc_segment
is D
.
We return the lowered type and the DefId
for the whole path.
We only support associated type paths whose self type is a type parameter or a Self
type alias (in a trait impl) like T::Ty
(where T
is a ty param) or Self::Ty
.
We don’t support paths whose self type is an arbitrary type like Struct::Ty
where
struct Struct
impls an in-scope trait that defines an associated type called Ty
.
For the latter case, we report ambiguity.
While desirable to support, the implemention would be non-trivial. Tracked in #22519.
At the time of writing, inherent associated types are also resolved here. This however is problematic. A proper implementation would be as non-trivial as the one described in the previous paragraph and their modeling of projections would likely be very similar in nature.
fn probe_inherent_assoc_ty( &self, name: Ident, segment: &PathSegment<'tcx>, adt_did: DefId, self_ty: Ty<'tcx>, block: HirId, span: Span, ) -> Result<Option<(Ty<'tcx>, DefId)>, ErrorGuaranteed>
fn select_inherent_assoc_type_candidates( &self, infcx: &InferCtxt<'tcx>, name: Ident, span: Span, self_ty: Ty<'tcx>, param_env: ParamEnv<'tcx>, candidates: Vec<(DefId, (DefId, DefId))>, ) -> Result<(DefId, (DefId, DefId)), ErrorGuaranteed>
sourcefn probe_assoc_item(
&self,
ident: Ident,
kind: AssocKind,
block: HirId,
span: Span,
scope: DefId,
) -> Option<AssocItem>
fn probe_assoc_item( &self, ident: Ident, kind: AssocKind, block: HirId, span: Span, scope: DefId, ) -> Option<AssocItem>
sourcefn probe_assoc_item_unchecked(
&self,
ident: Ident,
kind: AssocKind,
block: HirId,
scope: DefId,
) -> Option<(AssocItem, DefId)>
fn probe_assoc_item_unchecked( &self, ident: Ident, kind: AssocKind, block: HirId, scope: DefId, ) -> Option<(AssocItem, DefId)>
sourcefn check_assoc_item(
&self,
item_def_id: DefId,
ident: Ident,
scope: DefId,
block: HirId,
span: Span,
)
fn check_assoc_item( &self, item_def_id: DefId, ident: Ident, scope: DefId, block: HirId, span: Span, )
Check if the given assoc item is accessible in the provided scope wrt. visibility and stability.
fn probe_traits_that_match_assoc_ty( &self, qself_ty: Ty<'tcx>, assoc_ident: Ident, ) -> Vec<String>
sourcefn lower_qpath(
&self,
span: Span,
opt_self_ty: Option<Ty<'tcx>>,
item_def_id: DefId,
trait_segment: &PathSegment<'tcx>,
item_segment: &PathSegment<'tcx>,
constness: BoundConstness,
) -> Ty<'tcx>
fn lower_qpath( &self, span: Span, opt_self_ty: Option<Ty<'tcx>>, item_def_id: DefId, trait_segment: &PathSegment<'tcx>, item_segment: &PathSegment<'tcx>, constness: BoundConstness, ) -> Ty<'tcx>
Lower a qualified path to a type.
pub fn prohibit_generic_args<'a>( &self, segments: impl Iterator<Item = &'a PathSegment<'a>> + Clone, err_extend: GenericsArgsErrExtend<'_>, ) -> Result<(), ErrorGuaranteed>
sourcepub fn probe_generic_path_segments(
&self,
segments: &[PathSegment<'_>],
self_ty: Option<Ty<'tcx>>,
kind: DefKind,
def_id: DefId,
span: Span,
) -> Vec<GenericPathSegment>
pub fn probe_generic_path_segments( &self, segments: &[PathSegment<'_>], self_ty: Option<Ty<'tcx>>, kind: DefKind, def_id: DefId, span: Span, ) -> Vec<GenericPathSegment>
Probe path segments that are semantically allowed to have generic arguments.
§Example
Option::None::<()>
// ^^^^ permitted to have generic args
// ==> [GenericPathSegment(Option_def_id, 1)]
Option::<()>::None
// ^^^^^^ ^^^^ *not* permitted to have generic args
// permitted to have generic args
// ==> [GenericPathSegment(Option_def_id, 0)]
sourcepub fn lower_path(
&self,
opt_self_ty: Option<Ty<'tcx>>,
path: &Path<'tcx>,
hir_id: HirId,
permit_variants: bool,
) -> Ty<'tcx>
pub fn lower_path( &self, opt_self_ty: Option<Ty<'tcx>>, path: &Path<'tcx>, hir_id: HirId, permit_variants: bool, ) -> Ty<'tcx>
Lower a type Path
to a type.
sourcepub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx>
pub(crate) fn lower_ty_param(&self, hir_id: HirId) -> Ty<'tcx>
sourcepub(crate) fn lower_const_param(&self, hir_id: HirId) -> Const<'tcx>
pub(crate) fn lower_const_param(&self, hir_id: HirId) -> Const<'tcx>
Lower a const parameter from the HIR to our internal notion of a constant.
Early-bound const parameters get lowered to ty::ConstKind::Param
and late-bound ones to ty::ConstKind::Bound
.
fn lower_delegation_ty(&self, idx: InferDelegationKind) -> Ty<'tcx>
sourcepub fn lower_ty(&self, hir_ty: &Ty<'tcx>) -> Ty<'tcx>
pub fn lower_ty(&self, hir_ty: &Ty<'tcx>) -> Ty<'tcx>
Lower a type from the HIR to our internal notion of a type given some extra data for diagnostics.
Extra diagnostic data:
borrowed
: Whether trait object types are borrowed like in&dyn Trait
. Used to avoid emitting redundant errors.in_path
: Whether the type appears inside of a path. Used to provide correct diagnostics for bare trait object types.
sourcefn lower_opaque_ty(
&self,
def_id: DefId,
lifetimes: &[GenericArg<'_>],
in_trait: bool,
) -> Ty<'tcx>
fn lower_opaque_ty( &self, def_id: DefId, lifetimes: &[GenericArg<'_>], in_trait: bool, ) -> Ty<'tcx>
Lower an opaque type (i.e., an existential impl-Trait type) from the HIR.
pub fn lower_arg_ty( &self, ty: &Ty<'tcx>, expected_ty: Option<Ty<'tcx>>, ) -> Ty<'tcx>
sourcepub fn lower_fn_ty(
&self,
hir_id: HirId,
safety: Safety,
abi: Abi,
decl: &FnDecl<'tcx>,
generics: Option<&Generics<'_>>,
hir_ty: Option<&Ty<'_>>,
) -> PolyFnSig<'tcx>
pub fn lower_fn_ty( &self, hir_id: HirId, safety: Safety, abi: Abi, decl: &FnDecl<'tcx>, generics: Option<&Generics<'_>>, hir_ty: Option<&Ty<'_>>, ) -> PolyFnSig<'tcx>
Lower a function type from the HIR to our internal notion of a function signature.
sourcepub(crate) fn suggest_trait_fn_ty_for_impl_fn_infer(
&self,
fn_hir_id: HirId,
arg_idx: Option<usize>,
) -> Option<Ty<'tcx>>
pub(crate) fn suggest_trait_fn_ty_for_impl_fn_infer( &self, fn_hir_id: HirId, arg_idx: Option<usize>, ) -> Option<Ty<'tcx>>
Given a fn_hir_id for a impl function, suggest the type that is found on the corresponding function in the trait that the impl implements, if it exists. If arg_idx is Some, then it corresponds to an input type index, otherwise it corresponds to the return type.
fn validate_late_bound_regions<'cx>( &'cx self, constrained_regions: FxHashSet<BoundRegionKind>, referenced_regions: FxHashSet<BoundRegionKind>, generate_err: impl Fn(&str) -> Diag<'cx>, )
sourcefn compute_object_lifetime_bound(
&self,
span: Span,
existential_predicates: &'tcx List<PolyExistentialPredicate<'tcx>>,
) -> Option<Region<'tcx>>
fn compute_object_lifetime_bound( &self, span: Span, existential_predicates: &'tcx List<PolyExistentialPredicate<'tcx>>, ) -> Option<Region<'tcx>>
Given the bounds on an object, determines what single region bound (if any) we can use to summarize this type.
The basic idea is that we will use the bound the user
provided, if they provided one, and otherwise search the supertypes of trait bounds
for region bounds. It may be that we can derive no bound at all, in which case
we return None
.