Module rustc_trans::middle::typeck::astconvExperimental [-]  [+] [src]

Conversion from AST representation of types to the ty.rs representation. The main routine here is ast_ty_to_ty(): each use is parameterized by an instance of AstConv and a RegionScope.

The parameterization of ast_ty_to_ty() is because it behaves somewhat differently during the collect and check phases, particularly with respect to looking up the types of top-level items. In the collect phase, the crate context is used as the AstConv instance; in this phase, the get_item_ty() function triggers a recursive call to ty_of_item() (note that ast_ty_to_ty() will detect recursive types and report an error). In the check phase, when the FnCtxt is used as the AstConv, get_item_ty() just looks up the item type in tcx.tcache.

The RegionScope trait controls what happens when the user does not specify a region in some location where a region is required (e.g., if the user writes &Foo as a type rather than &'a Foo). See the rscope module for more details.

Unlike the AstConv trait, the region scope can change as we descend the type. This is to accommodate the fact that (a) fn types are binding scopes and (b) the default region may change. To understand case (a), consider something like:

type foo = { x: &a.int, y: |&a.int| }

The type of x is an error because there is no region a in scope. In the type of y, however, region a is considered a bound region as it does not already appear in scope.

Case (b) says that if you have a type: type foo<'a> = ...; type bar = fn(&foo, &a.foo) The fully expanded version of type bar is: type bar = fn(&'foo &, &a.foo<'a>) Note that the self region for the foo defaulted to & in the first case but &a in the second. Basically, defaults that appear inside an rptr (&r.T) use the region r that appears in the rptr.

Structs

PartitionedBounds

Traits

AstConv

Functions

ast_path_to_ty
ast_path_to_ty_relaxed

Returns the type that this AST path refers to. If the path has no type parameters and the corresponding type has type parameters, fresh type and/or region variables are substituted.

ast_region_to_region
ast_ty_to_builtin_ty

Converts the given AST type to a built-in type. A "built-in type" is, at present, either a core numeric type, a string, or Box.

ast_ty_to_prim_ty
ast_ty_to_ty
compute_opt_region_bound

Given the bounds on a type parameter / existential type, 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.

conv_existential_bounds

Given an existential type like Foo+'a+Bar, this routine converts the 'a and Bar intos an ExistentialBounds struct. The main_trait_refs argument specifies the Foo -- it is absent for closures. Eventually this should all be normalized, I think, so that there is no "main trait ref" and instead we just have a flat list of bounds as the existential type.

conv_existential_bounds_from_partitioned_bounds
instantiate_poly_trait_ref
instantiate_trait_ref

Instantiates the path for the given trait reference, assuming that it's bound to a valid trait type. Returns the def_id for the defining trait. Fails if the type is a type other than a trait type.

opt_ast_region_to_region
partition_bounds

Divides a list of bounds from the AST into three groups: builtin bounds (Copy, Sized etc), general trait bounds, and region bounds.

ty_of_arg
ty_of_bare_fn
ty_of_closure
ty_of_method