pub trait AstConv<'tcx> {
Show 13 methods // Required methods fn tcx(&self) -> TyCtxt<'tcx>; fn item_def_id(&self) -> DefId; fn get_type_parameter_bounds( &self, span: Span, def_id: LocalDefId, assoc_name: Ident ) -> GenericPredicates<'tcx>; fn re_infer( &self, param: Option<&GenericParamDef>, span: Span ) -> Option<Region<'tcx>>; fn ty_infer(&self, param: Option<&GenericParamDef>, span: Span) -> Ty<'tcx>; fn allow_ty_infer(&self) -> bool; fn ct_infer( &self, ty: Ty<'tcx>, param: Option<&GenericParamDef>, span: Span ) -> Const<'tcx>; fn projected_ty_from_poly_trait_ref( &self, span: Span, item_def_id: DefId, item_segment: &PathSegment<'tcx>, poly_trait_ref: PolyTraitRef<'tcx> ) -> Ty<'tcx>; fn probe_adt(&self, span: Span, ty: Ty<'tcx>) -> Option<AdtDef<'tcx>>; fn set_tainted_by_errors(&self, e: ErrorGuaranteed); fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span); fn infcx(&self) -> Option<&InferCtxt<'tcx>>; // Provided method fn astconv(&self) -> &dyn AstConv<'tcx> where Self: Sized { ... }
}

Required Methods§

source

fn tcx(&self) -> TyCtxt<'tcx>

source

fn item_def_id(&self) -> DefId

source

fn get_type_parameter_bounds( &self, span: Span, def_id: LocalDefId, assoc_name: Ident ) -> GenericPredicates<'tcx>

Returns predicates in scope of the form X: Foo<T>, where X is a type parameter X with the given id def_id and T matches assoc_name. This is a subset of the full set of predicates.

This is used for one specific purpose: resolving “short-hand” associated type references like T::Item. 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”.

source

fn re_infer( &self, param: Option<&GenericParamDef>, span: Span ) -> Option<Region<'tcx>>

Returns the lifetime to use when a lifetime is omitted (and not elided).

source

fn ty_infer(&self, param: Option<&GenericParamDef>, span: Span) -> Ty<'tcx>

Returns the type to use when a type is omitted.

source

fn allow_ty_infer(&self) -> bool

Returns true if _ is allowed in type signatures in the current context.

source

fn ct_infer( &self, ty: Ty<'tcx>, param: Option<&GenericParamDef>, span: Span ) -> Const<'tcx>

Returns the const to use when a const is omitted.

source

fn projected_ty_from_poly_trait_ref( &self, span: Span, item_def_id: DefId, item_segment: &PathSegment<'tcx>, poly_trait_ref: PolyTraitRef<'tcx> ) -> Ty<'tcx>

Projecting an associated type from a (potentially) higher-ranked trait reference is more complicated, because of the possibility of late-bound regions appearing in the associated type binding. This is not legal in function signatures for that reason. In a function body, we can always handle it because we can use inference variables to remove the late-bound regions.

source

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 projection 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.

source

fn set_tainted_by_errors(&self, e: ErrorGuaranteed)

Invoked when we encounter an error from some prior pass (e.g., resolve) that is translated into a ty-error. This is used to help suppress derived errors typeck might otherwise report.

source

fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span)

source

fn infcx(&self) -> Option<&InferCtxt<'tcx>>

Provided Methods§

source

fn astconv(&self) -> &dyn AstConv<'tcx>
where Self: Sized,

Implementations§

source§

impl<'tcx> dyn AstConv<'tcx> + '_

source

pub(crate) fn add_implicitly_sized( &self, bounds: &mut Bounds<'tcx>, self_ty: Ty<'tcx>, ast_bounds: &'tcx [GenericBound<'tcx>], self_ty_where_predicates: Option<(LocalDefId, &'tcx [WherePredicate<'tcx>])>, span: Span )

Sets implicitly_sized to true on Bounds if necessary

source

pub(crate) fn add_bounds<'hir, I: Iterator<Item = &'hir GenericBound<'tcx>>>( &self, param_ty: Ty<'tcx>, ast_bounds: I, bounds: &mut Bounds<'tcx>, bound_vars: &'tcx List<BoundVariableKind>, only_self_bounds: OnlySelfBounds )
where 'tcx: 'hir,

This helper takes a converted parameter type (param_ty) and an unconverted list of bounds:

fn foo<T: Debug>
       ^  ^^^^^ `ast_bounds` parameter, in HIR form
       |
       `param_ty`, in ty form

It adds these ast_bounds into the bounds structure.

A note on binders: there is an implied binder around param_ty and ast_bounds. See instantiate_poly_trait_ref for more details.

source

pub(crate) fn compute_bounds( &self, param_ty: Ty<'tcx>, ast_bounds: &[GenericBound<'tcx>], filter: PredicateFilter ) -> Bounds<'tcx>

Translates a list of bounds from the HIR into the Bounds data structure. The self-type for the bounds is given by param_ty.

Example:

fn foo<T: Bar + Baz>() { }
//     ^  ^^^^^^^^^ ast_bounds
//     param_ty

The sized_by_default parameter indicates if, in this context, the param_ty should be considered Sized unless there is an explicit ?Sized bound. This would be true in the example above, but is not true in supertrait listings like trait Foo: Bar + Baz.

span should be the declaration size of the parameter.

source

pub(super) fn add_predicates_for_ast_type_binding( &self, hir_ref_id: HirId, trait_ref: PolyTraitRef<'tcx>, binding: &TypeBinding<'tcx>, bounds: &mut Bounds<'tcx>, speculative: bool, dup_bindings: &mut FxIndexMap<DefId, Span>, path_span: Span, only_self_bounds: OnlySelfBounds ) -> Result<(), ErrorGuaranteed>

Given an HIR binding like Item = Foo or Item: Foo, pushes the corresponding predicates onto 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 binding data however is from inside the binder (e.g., &'a u32) and hence may reference bound regions.

source§

impl<'tcx> dyn AstConv<'tcx> + '_

source

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.

source

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.

source

pub(super) fn complain_about_assoc_item_not_found<I>( &self, all_candidates: impl Fn() -> I, ty_param_name: &str, ty_param_def_id: Option<LocalDefId>, assoc_kind: AssocKind, assoc_name: Ident, span: Span, binding: Option<&TypeBinding<'tcx>> ) -> ErrorGuaranteed
where I: Iterator<Item = PolyTraitRef<'tcx>>,

source

fn complain_about_assoc_kind_mismatch( &self, assoc_item: &AssocItem, assoc_kind: AssocKind, ident: Ident, span: Span, binding: Option<&TypeBinding<'tcx>> ) -> ErrorGuaranteed

source

pub(super) fn report_ambiguous_associated_type( &self, span: Span, types: &[String], traits: &[String], name: Symbol ) -> ErrorGuaranteed

source

pub(crate) fn complain_about_ambiguous_inherent_assoc_type( &self, name: Ident, candidates: Vec<DefId>, span: Span ) -> ErrorGuaranteed

source

fn note_ambiguous_inherent_assoc_type( &self, err: &mut Diag<'_>, candidates: Vec<DefId>, span: Span )

source

pub(crate) fn complain_about_inherent_assoc_type_not_found( &self, name: Ident, self_ty: Ty<'tcx>, candidates: Vec<(DefId, (DefId, DefId))>, fulfillment_errors: Vec<FulfillmentError<'tcx>>, span: Span ) -> ErrorGuaranteed

source

pub(crate) fn complain_about_missing_associated_types( &self, associated_types: FxIndexMap<Span, FxIndexSet<DefId>>, potential_assoc_types: Vec<Span>, trait_bounds: &[PolyTraitRef<'_>] )

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.

source

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)

source§

impl<'tcx> dyn AstConv<'tcx> + '_

source

pub(super) fn maybe_lint_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.

source

fn add_generic_param_suggestion( &self, generics: &Generics<'_>, self_ty_span: Span, impl_trait_name: &str ) -> Vec<(Span, String)>

source

fn maybe_lint_impl_trait(&self, self_ty: &Ty<'_>, diag: &mut Diag<'_>) -> bool

Make sure that we are in the condition to suggest impl Trait.

source

pub(super) fn maybe_lint_bare_trait(&self, self_ty: &Ty<'_>, in_path: bool)

source§

impl<'tcx> dyn AstConv<'tcx> + '_

source

pub(super) fn conv_object_ty_poly_trait_ref( &self, span: Span, hir_id: HirId, hir_trait_bounds: &[PolyTraitRef<'tcx>], lifetime: &Lifetime, borrowed: bool, representation: DynKind ) -> Ty<'tcx>

source§

impl<'tcx> dyn AstConv<'tcx> + '_

source

pub fn ast_region_to_region( &self, lifetime: &Lifetime, def: Option<&GenericParamDef> ) -> Region<'tcx>

source

pub fn ast_path_args_for_ty( &self, span: Span, def_id: DefId, item_segment: &PathSegment<'tcx> ) -> GenericArgsRef<'tcx>

Given a path path that refers to an item I with the declared generics decl_generics, returns an appropriate set of generic arguments for this particular reference to I.

source

fn create_args_for_ast_path( &self, span: Span, def_id: DefId, parent_args: &[GenericArg<'tcx>], segment: &PathSegment<'tcx>, self_ty: Option<Ty<'tcx>>, constness: BoundConstness ) -> (GenericArgsRef<'tcx>, GenericArgCountResult)

Given the type/lifetime/const arguments provided to some path (along with an implicit Self, if this is a trait reference), returns the complete set of generic arguments. This may involve applying defaulted type parameters.

Constraints on associated types are not converted here but separately in add_predicates_for_ast_type_binding.

Example:

   T: std::ops::Index<usize, Output = u32>
// ^1 ^^^^^^^^^^^^^^2 ^^^^3  ^^^^^^^^^^^4
  1. The self_ty here would refer to the type T.
  2. The path in question is the path to the trait std::ops::Index, which will have been resolved to a def_id
  3. The generic_args contains info on the <...> contents. The usize type parameters are returned in the GenericArgsRef
  4. Associated type bindings like Output = u32 are contained in generic_args.bindings.

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].

source

pub fn create_args_for_associated_item( &self, span: Span, item_def_id: DefId, item_segment: &PathSegment<'tcx>, parent_args: GenericArgsRef<'tcx> ) -> GenericArgsRef<'tcx>

source

pub fn instantiate_mono_trait_ref( &self, trait_ref: &TraitRef<'tcx>, self_ty: Ty<'tcx> ) -> TraitRef<'tcx>

Instantiates the path for the given trait reference, assuming that it’s bound to a valid trait type. Returns the DefId of the defining trait. The type cannot be a type other than a trait type.

If the projections argument is None, then assoc type bindings like Foo<T = X> are disallowed. Otherwise, they are pushed onto the vector given.

source

pub(crate) fn instantiate_poly_trait_ref( &self, trait_ref: &TraitRef<'tcx>, span: Span, constness: BoundConstness, polarity: ImplPolarity, self_ty: Ty<'tcx>, bounds: &mut Bounds<'tcx>, speculative: bool, only_self_bounds: OnlySelfBounds ) -> GenericArgCountResult

Given a trait bound like Debug, applies that trait bound the given self-type to construct a full trait reference. The resulting trait reference is returned. This may also generate auxiliary bounds, which are added to bounds.

Example:

poly_trait_ref = Iterator<Item = u32>
self_ty = Foo

this would return Foo: Iterator and add <Foo as Iterator>::Item = u32 into bounds.

A note on binders: against our usual convention, there is an implied binder around the self_ty and poly_trait_ref parameters here. So they may reference bound regions. 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 poly_trait_ref would be Bar<'a>. The returned poly-trait-ref will have this binder instantiated explicitly, however.

source

fn ast_path_to_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>

source

fn trait_defines_associated_item_named( &self, trait_def_id: DefId, assoc_kind: AssocKind, assoc_name: Ident ) -> bool

source

fn ast_path_to_ty( &self, span: Span, did: DefId, item_segment: &PathSegment<'tcx> ) -> Ty<'tcx>

source

fn find_bound_for_assoc_item( &self, ty_param_def_id: LocalDefId, assoc_name: Ident, span: Span ) -> Result<PolyTraitRef<'tcx>, ErrorGuaranteed>

source

fn one_bound_for_assoc_item<I>( &self, all_candidates: impl Fn() -> I, ty_param_name: impl Display, ty_param_def_id: Option<LocalDefId>, assoc_kind: AssocKind, assoc_name: Ident, span: Span, binding: Option<&TypeBinding<'tcx>> ) -> Result<PolyTraitRef<'tcx>, ErrorGuaranteed>
where I: Iterator<Item = PolyTraitRef<'tcx>>,

source

pub fn associated_path_to_ty( &self, hir_ref_id: HirId, span: Span, qself_ty: Ty<'tcx>, qself: &Ty<'_>, assoc_segment: &PathSegment<'tcx>, permit_variants: bool ) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorGuaranteed>

source

fn lookup_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>

source

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>

source

fn lookup_assoc_ty( &self, name: Ident, block: HirId, span: Span, scope: DefId ) -> Option<DefId>

source

fn lookup_assoc_ty_unchecked( &self, name: Ident, block: HirId, scope: DefId ) -> Option<(DefId, DefId)>

source

fn check_assoc_ty( &self, item: DefId, name: Ident, def_scope: DefId, block: HirId, span: Span )

source

fn probe_traits_that_match_assoc_ty( &self, qself_ty: Ty<'tcx>, assoc_ident: Ident ) -> Vec<String>

source

fn qpath_to_ty( &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>

source

pub fn prohibit_generics<'a>( &self, segments: impl Iterator<Item = &'a PathSegment<'a>> + Clone, extend: impl Fn(&mut Diag<'_>) ) -> bool

source

pub fn def_ids_for_value_path_segments( &self, segments: &[PathSegment<'_>], self_ty: Option<Ty<'tcx>>, kind: DefKind, def_id: DefId, span: Span ) -> Vec<PathSeg>

source

pub fn res_to_ty( &self, opt_self_ty: Option<Ty<'tcx>>, path: &Path<'tcx>, hir_id: HirId, permit_variants: bool ) -> Ty<'tcx>

Check a type Path and convert it to a Ty.

source

pub(crate) fn hir_id_to_bound_ty(&self, hir_id: HirId) -> Ty<'tcx>

source

pub(crate) fn hir_id_to_bound_const( &self, hir_id: HirId, param_ty: Ty<'tcx> ) -> Const<'tcx>

source

pub fn ast_ty_to_ty(&self, ast_ty: &Ty<'tcx>) -> Ty<'tcx>

Parses the programmer’s textual representation of a type into our internal notion of a type.

source

pub fn ast_ty_to_ty_in_path(&self, ast_ty: &Ty<'tcx>) -> Ty<'tcx>

Parses the programmer’s textual representation of a type into our internal notion of a type. This is meant to be used within a path.

source

fn check_delegation_constraints( &self, sig_id: DefId, span: Span, emit: bool ) -> bool

source

fn ty_from_delegation( &self, sig_id: DefId, idx: InferDelegationKind, span: Span ) -> Ty<'tcx>

source

fn ast_ty_to_ty_inner( &self, ast_ty: &Ty<'tcx>, borrowed: bool, in_path: bool ) -> Ty<'tcx>

Turns a hir::Ty into a Ty. For diagnostics’ purposes we keep track of whether trait objects are borrowed like &dyn Trait to avoid emitting redundant errors.

source

fn impl_trait_ty_to_ty( &self, def_id: DefId, lifetimes: &[GenericArg<'_>], in_trait: bool ) -> Ty<'tcx>

source

pub fn ty_of_arg( &self, ty: &Ty<'tcx>, expected_ty: Option<Ty<'tcx>> ) -> Ty<'tcx>

source

pub fn ty_of_fn( &self, hir_id: HirId, unsafety: Unsafety, abi: Abi, decl: &FnDecl<'tcx>, generics: Option<&Generics<'_>>, hir_ty: Option<&Ty<'_>> ) -> PolyFnSig<'tcx>

source

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.

source

fn validate_late_bound_regions( &self, constrained_regions: FxHashSet<BoundRegionKind>, referenced_regions: FxHashSet<BoundRegionKind>, generate_err: impl Fn(&str) -> Diag<'tcx> )

source

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.

Implementors§

source§

impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx>