[][src]Trait rustc_typeck::astconv::AstConv

pub trait AstConv<'tcx> {
    fn tcx<'a>(&'a self) -> TyCtxt<'tcx>;
fn item_def_id(&self) -> Option<DefId>;
fn default_constness_for_trait_bounds(&self) -> Constness;
fn get_type_parameter_bounds(
        &self,
        span: Span,
        def_id: DefId
    ) -> 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
    ) -> &'tcx Const<'tcx>;
fn projected_ty_from_poly_trait_ref(
        &self,
        span: Span,
        item_def_id: DefId,
        item_segment: &PathSegment,
        poly_trait_ref: PolyTraitRef<'tcx>
    ) -> Ty<'tcx>;
fn normalize_ty(&self, span: Span, ty: Ty<'tcx>) -> Ty<'tcx>;
fn set_tainted_by_errors(&self);
fn record_ty(&self, hir_id: HirId, ty: Ty<'tcx>, span: Span); }

Required methods

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

fn item_def_id(&self) -> Option<DefId>

fn default_constness_for_trait_bounds(&self) -> Constness

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

Returns predicates in scope of the form X: Foo, where X is a type parameter X with the given id def_id. 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".

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

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

Returns the type to use when a type is omitted.

fn allow_ty_infer(&self) -> bool

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

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

Returns the const to use when a const is omitted.

fn projected_ty_from_poly_trait_ref(
    &self,
    span: Span,
    item_def_id: DefId,
    item_segment: &PathSegment,
    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.

fn normalize_ty(&self, span: Span, ty: Ty<'tcx>) -> Ty<'tcx>

Normalize an associated type coming from the user.

fn set_tainted_by_errors(&self)

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.

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

Loading content...

Implementations

impl<'o, 'tcx> dyn AstConv<'tcx> + 'o[src]

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

pub fn ast_path_substs_for_ty(
    &self,
    span: Span,
    def_id: DefId,
    item_segment: &PathSegment
) -> SubstsRef<'tcx>
[src]

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

fn check_impl_trait(tcx: TyCtxt, seg: &PathSegment, generics: &Generics) -> bool[src]

Report error if there is an explicit type parameter when using impl Trait.

pub fn check_generic_arg_count_for_call(
    tcx: TyCtxt,
    span: Span,
    def: &Generics,
    seg: &PathSegment,
    is_method_call: bool
) -> GenericArgCountResult
[src]

Checks that the correct number of generic arguments have been provided. Used specifically for function calls.

fn check_generic_arg_count(
    tcx: TyCtxt,
    span: Span,
    def: &Generics,
    args: &GenericArgs,
    position: GenericArgPosition,
    has_self: bool,
    infer_args: bool
) -> GenericArgCountResult
[src]

Checks that the correct number of generic arguments have been provided. This is used both for datatypes and function calls.

fn generic_arg_mismatch_err(
    sess: &Session,
    arg: &GenericArg,
    kind: &'static str,
    help: Option<&str>
)
[src]

Report an error that a generic argument did not match the generic parameter that was expected.

pub fn create_substs_for_generic_args<'b>(
    tcx: TyCtxt<'tcx>,
    def_id: DefId,
    parent_substs: &[GenericArg<'tcx>],
    has_self: bool,
    self_ty: Option<Ty<'tcx>>,
    arg_count: GenericArgCountResult,
    args_for_def_id: impl Fn(DefId) -> (Option<&'b GenericArgs<'b>>, bool),
    provided_kind: impl FnMut(&GenericParamDef, &GenericArg) -> GenericArg<'tcx>,
    inferred_kind: impl FnMut(Option<&[GenericArg<'tcx>]>, &GenericParamDef, bool) -> GenericArg<'tcx>
) -> SubstsRef<'tcx>
[src]

Creates the relevant generic argument substitutions corresponding to a set of generic parameters. This is a rather complex function. Let us try to explain the role of each of its parameters:

To start, we are given the def_id of the thing we are creating the substitutions for, and a partial set of substitutions parent_substs. In general, the substitutions for an item begin with substitutions for all the "parents" of that item -- e.g., for a method it might include the parameters from the impl.

Therefore, the method begins by walking down these parents, starting with the outermost parent and proceed inwards until it reaches def_id. For each parent P, it will check parent_substs first to see if the parent's substitutions are listed in there. If so, we can append those and move on. Otherwise, it invokes the three callback functions:

  • args_for_def_id: given the DefId P, supplies back the generic arguments that were given to that parent from within the path; so e.g., if you have <T as Foo>::Bar, the DefId might refer to the trait Foo, and the arguments might be [T]. The boolean value indicates whether to infer values for arguments whose values were not explicitly provided.
  • provided_kind: given the generic parameter and the value from args_for_def_id, instantiate a GenericArg.
  • inferred_kind: if no parameter was provided, and inference is enabled, then creates a suitable inference variable.

fn create_substs_for_ast_path<'a>(
    &self,
    span: Span,
    def_id: DefId,
    parent_substs: &[GenericArg<'tcx>],
    generic_args: &'a GenericArgs,
    infer_args: bool,
    self_ty: Option<Ty<'tcx>>
) -> (SubstsRef<'tcx>, Vec<ConvertedBinding<'a, 'tcx>>, GenericArgCountResult)
[src]

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 substitutions. This may involve applying defaulted type parameters. Also returns back constraints on associated types.

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 SubstsRef, the associated type bindings like Output = u32 are returned in the Vec<ConvertedBinding...> result.

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 substs are the substs for the parent trait: [Vec<u8>, u8] and generic_args are the arguments for the associated type itself: ['a]. The returned SubstsRef concatenates these two lists: [Vec<u8>, u8, 'a].

pub(crate) fn create_substs_for_associated_item(
    &self,
    tcx: TyCtxt<'tcx>,
    span: Span,
    item_def_id: DefId,
    item_segment: &PathSegment,
    parent_substs: SubstsRef<'tcx>
) -> SubstsRef<'tcx>
[src]

fn complain_about_missing_type_params(
    &self,
    missing_type_params: Vec<String>,
    def_id: DefId,
    span: Span,
    empty_generic_args: bool
)
[src]

On missing type parameters, emit an E0393 error and provide a structured suggestion using the type parameter's name as a placeholder.

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

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.

pub(super) fn instantiate_poly_trait_ref_inner(
    &self,
    trait_ref: &TraitRef,
    span: Span,
    constness: Constness,
    self_ty: Ty<'tcx>,
    bounds: &mut Bounds<'tcx>,
    speculative: bool
) -> GenericArgCountResult
[src]

The given trait-ref must actually be a trait.

pub fn instantiate_poly_trait_ref(
    &self,
    poly_trait_ref: &PolyTraitRef,
    constness: Constness,
    self_ty: Ty<'tcx>,
    bounds: &mut Bounds<'tcx>
) -> GenericArgCountResult
[src]

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

fn ast_path_to_mono_trait_ref(
    &self,
    span: Span,
    trait_def_id: DefId,
    self_ty: Ty<'tcx>,
    trait_segment: &PathSegment
) -> TraitRef<'tcx>
[src]

fn complain_about_internal_fn_trait<'a>(
    &self,
    span: Span,
    trait_def_id: DefId,
    trait_segment: &'a PathSegment<'a>
)
[src]

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.

fn create_substs_for_ast_trait_ref<'a>(
    &self,
    span: Span,
    trait_def_id: DefId,
    self_ty: Ty<'tcx>,
    trait_segment: &'a PathSegment<'a>
) -> (SubstsRef<'tcx>, Vec<ConvertedBinding<'a, 'tcx>>, GenericArgCountResult)
[src]

fn trait_defines_associated_type_named(
    &self,
    trait_def_id: DefId,
    assoc_name: Ident
) -> bool
[src]

pub fn is_unsized(&self, ast_bounds: &[GenericBound], span: Span) -> bool[src]

fn add_bounds(
    &self,
    param_ty: Ty<'tcx>,
    ast_bounds: &[GenericBound],
    bounds: &mut Bounds<'tcx>
)
[src]

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.

pub fn compute_bounds(
    &self,
    param_ty: Ty<'tcx>,
    ast_bounds: &[GenericBound],
    sized_by_default: SizedByDefault,
    span: Span
) -> Bounds<'tcx>
[src]

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.

fn add_predicates_for_ast_type_binding(
    &self,
    hir_ref_id: HirId,
    trait_ref: PolyTraitRef<'tcx>,
    binding: &ConvertedBinding<'_, 'tcx>,
    bounds: &mut Bounds<'tcx>,
    speculative: bool,
    dup_bindings: &mut FxHashMap<DefId, Span>,
    path_span: Span
) -> Result<(), ErrorReported>
[src]

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.

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

fn conv_object_ty_poly_trait_ref(
    &self,
    span: Span,
    trait_bounds: &[PolyTraitRef],
    lifetime: &Lifetime
) -> Ty<'tcx>
[src]

fn complain_about_missing_associated_types(
    &self,
    associated_types: FxHashMap<Span, BTreeSet<DefId>>,
    potential_assoc_types: Vec<Span>,
    trait_bounds: &[PolyTraitRef]
)
[src]

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 super-traits), we instead emit a generic note suggesting using a where clause to constraint instead.

fn report_ambiguous_associated_type(
    &self,
    span: Span,
    type_str: &str,
    trait_str: &str,
    name: Symbol
)
[src]

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

fn one_bound_for_assoc_type<I>(
    &self,
    all_candidates: impl Fn() -> I,
    ty_param_name: impl Fn() -> String,
    assoc_name: Ident,
    span: Span,
    is_equality: impl Fn() -> Option<String>
) -> Result<PolyTraitRef<'tcx>, ErrorReported> where
    I: Iterator<Item = PolyTraitRef<'tcx>>, 
[src]

fn complain_about_assoc_type_not_found<I>(
    &self,
    all_candidates: impl Fn() -> I,
    ty_param_name: &str,
    assoc_name: Ident,
    span: Span
) where
    I: Iterator<Item = PolyTraitRef<'tcx>>, 
[src]

pub fn associated_path_to_ty(
    &self,
    hir_ref_id: HirId,
    span: Span,
    qself_ty: Ty<'tcx>,
    qself_res: Res,
    assoc_segment: &PathSegment,
    permit_variants: bool
) -> Result<(Ty<'tcx>, DefKind, DefId), ErrorReported>
[src]

fn qpath_to_ty(
    &self,
    span: Span,
    opt_self_ty: Option<Ty<'tcx>>,
    item_def_id: DefId,
    trait_segment: &PathSegment,
    item_segment: &PathSegment
) -> Ty<'tcx>
[src]

pub fn prohibit_generics<'a, T: IntoIterator<Item = &'a PathSegment<'a>>>(
    &self,
    segments: T
) -> bool
[src]

pub fn prohibit_assoc_ty_binding(tcx: TyCtxt, span: Span)[src]

fn prohibit_explicit_late_bound_lifetimes(
    tcx: TyCtxt,
    def: &Generics,
    args: &GenericArgs,
    position: GenericArgPosition
) -> ExplicitLateBound
[src]

Prohibits explicit lifetime arguments if late-bound lifetime parameters are present. This is used both for datatypes and function calls.

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

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

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

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

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

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

pub fn ty_of_fn(
    &self,
    unsafety: Unsafety,
    abi: Abi,
    decl: &FnDecl,
    generics: &Generics,
    ident_span: Option<Span>
) -> PolyFnSig<'tcx>
[src]

fn validate_late_bound_regions(
    &self,
    constrained_regions: FxHashSet<BoundRegion>,
    referenced_regions: FxHashSet<BoundRegion>,
    generate_err: impl Fn(&str) -> DiagnosticBuilder<'tcx>
)
[src]

fn compute_object_lifetime_bound(
    &self,
    span: Span,
    existential_predicates: Binder<&'tcx List<ExistentialPredicate<'tcx>>>
) -> Option<Region<'tcx>>
[src]

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

impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx>[src]

impl<'tcx> AstConv<'tcx> for ItemCtxt<'tcx>[src]

Loading content...