Struct rustc_typeck::check::FnCtxt
[−]
[src]
pub struct FnCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> { /* fields omitted */ }
rustc_private
)Methods
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn autoderef(&'a self,
span: Span,
base_ty: Ty<'tcx>)
-> Autoderef<'a, 'gcx, 'tcx>
span: Span,
base_ty: Ty<'tcx>)
-> Autoderef<'a, 'gcx, 'tcx>
rustc_private
)fn try_overloaded_deref(&self,
span: Span,
base_expr: Option<&Expr>,
base_ty: Ty<'tcx>,
lvalue_pref: LvaluePreference)
-> Option<MethodCallee<'tcx>>
span: Span,
base_expr: Option<&Expr>,
base_ty: Ty<'tcx>,
lvalue_pref: LvaluePreference)
-> Option<MethodCallee<'tcx>>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn check_pat(&self, pat: &'gcx Pat, expected: Ty<'tcx>)
rustc_private
)fn check_pat_arg(&self, pat: &'gcx Pat, expected: Ty<'tcx>, is_arg: bool)
rustc_private
)The is_arg
argument indicates whether this pattern is the
outermost pattern in an argument (e.g., in fn foo(&x: &u32)
, it is true for the &x
pattern but not x
). This is
used to tailor error reporting.
fn check_dereferencable(&self,
span: Span,
expected: Ty<'tcx>,
inner: &Pat)
-> bool
span: Span,
expected: Ty<'tcx>,
inner: &Pat)
-> bool
rustc_private
)fn check_match(&self,
expr: &'gcx Expr,
discrim: &'gcx Expr,
arms: &'gcx [Arm],
expected: Expectation<'tcx>,
match_src: MatchSource)
-> Ty<'tcx>
expr: &'gcx Expr,
discrim: &'gcx Expr,
arms: &'gcx [Arm],
expected: Expectation<'tcx>,
match_src: MatchSource)
-> Ty<'tcx>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn resolve_type_vars_in_body(&self,
body: &'gcx Body)
-> &'gcx TypeckTables<'gcx>
body: &'gcx Body)
-> &'gcx TypeckTables<'gcx>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn regionck_expr(&self, body: &'gcx Body)
rustc_private
)fn regionck_item(&self, item_id: NodeId, span: Span, wf_tys: &[Ty<'tcx>])
rustc_private
)Region checking during the WF phase for items. wf_tys
are the
types from which we should derive implied bounds, if any.
fn regionck_fn(&self, fn_id: NodeId, body: &'gcx Body)
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn try_coerce(&self,
expr: &Expr,
expr_ty: Ty<'tcx>,
target: Ty<'tcx>)
-> RelateResult<'tcx, Ty<'tcx>>
expr: &Expr,
expr_ty: Ty<'tcx>,
target: Ty<'tcx>)
-> RelateResult<'tcx, Ty<'tcx>>
rustc_private
)Attempt to coerce an expression to a type, and return the adjusted type of the expression, if successful. Adjustments are only recorded if the coercion succeeded. The expressions must not have any pre-existing adjustments.
fn try_find_coercion_lub<'b, E, I>(&self,
cause: &ObligationCause<'tcx>,
exprs: E,
prev_ty: Ty<'tcx>,
new: &'b Expr,
new_ty: Ty<'tcx>)
-> RelateResult<'tcx, Ty<'tcx>> where E: Fn() -> I, I: IntoIterator<Item=&'b Expr>
cause: &ObligationCause<'tcx>,
exprs: E,
prev_ty: Ty<'tcx>,
new: &'b Expr,
new_ty: Ty<'tcx>)
-> RelateResult<'tcx, Ty<'tcx>> where E: Fn() -> I, I: IntoIterator<Item=&'b Expr>
rustc_private
)Given some expressions, their known unified type and another expression, tries to unify the types, potentially inserting coercions on any of the provided expressions and returns their LUB (aka "common supertype").
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>)
rustc_private
)fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>)
rustc_private
)fn demand_eqtype_diag(&self,
sp: Span,
expected: Ty<'tcx>,
actual: Ty<'tcx>)
-> Option<DiagnosticBuilder<'tcx>>
sp: Span,
expected: Ty<'tcx>,
actual: Ty<'tcx>)
-> Option<DiagnosticBuilder<'tcx>>
rustc_private
)fn demand_eqtype_with_origin(&self,
cause: &ObligationCause<'tcx>,
expected: Ty<'tcx>,
actual: Ty<'tcx>)
-> Option<DiagnosticBuilder<'tcx>>
cause: &ObligationCause<'tcx>,
expected: Ty<'tcx>,
actual: Ty<'tcx>)
-> Option<DiagnosticBuilder<'tcx>>
rustc_private
)fn demand_coerce(&self, expr: &Expr, checked_ty: Ty<'tcx>, expected: Ty<'tcx>)
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn confirm_method(&self,
span: Span,
self_expr: &'gcx Expr,
call_expr: &'gcx Expr,
unadjusted_self_ty: Ty<'tcx>,
pick: Pick<'tcx>,
supplied_method_types: Vec<Ty<'tcx>>)
-> MethodCallee<'tcx>
span: Span,
self_expr: &'gcx Expr,
call_expr: &'gcx Expr,
unadjusted_self_ty: Ty<'tcx>,
pick: Pick<'tcx>,
supplied_method_types: Vec<Ty<'tcx>>)
-> MethodCallee<'tcx>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn probe_for_return_type(&self,
span: Span,
mode: Mode,
return_type: Ty<'tcx>,
self_ty: Ty<'tcx>,
scope_expr_id: NodeId)
-> Vec<AssociatedItem>
span: Span,
mode: Mode,
return_type: Ty<'tcx>,
self_ty: Ty<'tcx>,
scope_expr_id: NodeId)
-> Vec<AssociatedItem>
rustc_private
)This is used to offer suggestions to users. It returns methods that could have been called which have the desired return type. Some effort is made to rule out methods that, if called, would result in an error (basically, the same criteria we would use to decide if a method is a plausible fit for ambiguity purposes).
fn probe_for_name(&self,
span: Span,
mode: Mode,
item_name: Name,
is_suggestion: IsSuggestion,
self_ty: Ty<'tcx>,
scope_expr_id: NodeId)
-> PickResult<'tcx>
span: Span,
mode: Mode,
item_name: Name,
is_suggestion: IsSuggestion,
self_ty: Ty<'tcx>,
scope_expr_id: NodeId)
-> PickResult<'tcx>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn report_method_error(&self,
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: Name,
rcvr_expr: Option<&Expr>,
error: MethodError<'tcx>,
args: Option<&'gcx [Expr]>)
span: Span,
rcvr_ty: Ty<'tcx>,
item_name: Name,
rcvr_expr: Option<&Expr>,
error: MethodError<'tcx>,
args: Option<&'gcx [Expr]>)
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn method_exists(&self,
span: Span,
method_name: Name,
self_ty: Ty<'tcx>,
call_expr_id: NodeId,
allow_private: bool)
-> bool
span: Span,
method_name: Name,
self_ty: Ty<'tcx>,
call_expr_id: NodeId,
allow_private: bool)
-> bool
rustc_private
)Determines whether the type self_ty
supports a method name method_name
or not.
fn lookup_method(&self,
span: Span,
method_name: Name,
self_ty: Ty<'tcx>,
supplied_method_types: Vec<Ty<'tcx>>,
call_expr: &'gcx Expr,
self_expr: &'gcx Expr)
-> Result<MethodCallee<'tcx>, MethodError<'tcx>>
span: Span,
method_name: Name,
self_ty: Ty<'tcx>,
supplied_method_types: Vec<Ty<'tcx>>,
call_expr: &'gcx Expr,
self_expr: &'gcx Expr)
-> Result<MethodCallee<'tcx>, MethodError<'tcx>>
rustc_private
)Performs method lookup. If lookup is successful, it will return the callee
and store an appropriate adjustment for the self-expr. In some cases it may
report an error (e.g., invoking the drop
method).
Arguments
Given a method call like foo.bar::<T1,...Tn>(...)
:
fcx
: the surroundingFnCtxt
(!)span
: the span for the method callmethod_name
: the name of the method being called (bar
)self_ty
: the (unadjusted) type of the self expression (foo
)supplied_method_types
: the explicit method type parameters, if any (T1..Tn
)self_expr
: the self expression (foo
)
fn lookup_method_in_trait(&self,
span: Span,
self_expr: Option<&Expr>,
m_name: Name,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
opt_input_types: Option<Vec<Ty<'tcx>>>)
-> Option<MethodCallee<'tcx>>
span: Span,
self_expr: Option<&Expr>,
m_name: Name,
trait_def_id: DefId,
self_ty: Ty<'tcx>,
opt_input_types: Option<Vec<Ty<'tcx>>>)
-> Option<MethodCallee<'tcx>>
rustc_private
)fn lookup_method_in_trait_adjusted(&self,
span: Span,
self_expr: Option<&Expr>,
m_name: Name,
trait_def_id: DefId,
autoderefs: usize,
unsize: bool,
self_ty: Ty<'tcx>,
opt_input_types: Option<Vec<Ty<'tcx>>>)
-> Option<MethodCallee<'tcx>>
span: Span,
self_expr: Option<&Expr>,
m_name: Name,
trait_def_id: DefId,
autoderefs: usize,
unsize: bool,
self_ty: Ty<'tcx>,
opt_input_types: Option<Vec<Ty<'tcx>>>)
-> Option<MethodCallee<'tcx>>
rustc_private
)lookup_in_trait_adjusted
is used for overloaded operators.
It does a very narrow slice of what the normal probe/confirm path does.
In particular, it doesn't really do any probing: it simply constructs
an obligation for aparticular trait with the given self-type and checks
whether that trait is implemented.
FIXME(#18741) -- It seems likely that we can consolidate some of this code with the other method-lookup code. In particular, autoderef on index is basically identical to autoderef with normal probes, except that the test also looks for built-in indexing. Also, the second half of this method is basically the same as confirmation.
fn resolve_ufcs(&self,
span: Span,
method_name: Name,
self_ty: Ty<'tcx>,
expr_id: NodeId)
-> Result<Def, MethodError<'tcx>>
span: Span,
method_name: Name,
self_ty: Ty<'tcx>,
expr_id: NodeId)
-> Result<Def, MethodError<'tcx>>
rustc_private
)fn associated_item(&self,
def_id: DefId,
item_name: Name)
-> Option<AssociatedItem>
def_id: DefId,
item_name: Name)
-> Option<AssociatedItem>
rustc_private
)Find item with name item_name
defined in impl/trait def_id
and return it, or None
, if no such item was defined there.
impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn closure_analyze(&self, body: &'gcx Body)
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn check_expr_closure(&self,
expr: &Expr,
_capture: CaptureClause,
decl: &'gcx FnDecl,
body_id: BodyId,
expected: Expectation<'tcx>)
-> Ty<'tcx>
expr: &Expr,
_capture: CaptureClause,
decl: &'gcx FnDecl,
body_id: BodyId,
expected: Expectation<'tcx>)
-> Ty<'tcx>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn check_call(&self,
call_expr: &'gcx Expr,
callee_expr: &'gcx Expr,
arg_exprs: &'gcx [Expr],
expected: Expectation<'tcx>)
-> Ty<'tcx>
call_expr: &'gcx Expr,
callee_expr: &'gcx Expr,
arg_exprs: &'gcx [Expr],
expected: Expectation<'tcx>)
-> Ty<'tcx>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn check_binop_assign(&self,
expr: &'gcx Expr,
op: BinOp,
lhs_expr: &'gcx Expr,
rhs_expr: &'gcx Expr)
-> Ty<'tcx>
expr: &'gcx Expr,
op: BinOp,
lhs_expr: &'gcx Expr,
rhs_expr: &'gcx Expr)
-> Ty<'tcx>
rustc_private
)Check a a <op>= b
fn check_binop(&self,
expr: &'gcx Expr,
op: BinOp,
lhs_expr: &'gcx Expr,
rhs_expr: &'gcx Expr)
-> Ty<'tcx>
expr: &'gcx Expr,
op: BinOp,
lhs_expr: &'gcx Expr,
rhs_expr: &'gcx Expr)
-> Ty<'tcx>
rustc_private
)Check a potentially overloaded binary operator.
fn check_user_unop(&self,
op_str: &str,
mname: &str,
trait_did: Option<DefId>,
ex: &'gcx Expr,
operand_expr: &'gcx Expr,
operand_ty: Ty<'tcx>,
op: UnOp)
-> Ty<'tcx>
op_str: &str,
mname: &str,
trait_did: Option<DefId>,
ex: &'gcx Expr,
operand_expr: &'gcx Expr,
operand_ty: Ty<'tcx>,
op: UnOp)
-> Ty<'tcx>
rustc_private
)impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx>
[src]
fn new(inh: &'a Inherited<'a, 'gcx, 'tcx>,
rty: Option<Ty<'tcx>>,
body_id: NodeId)
-> FnCtxt<'a, 'gcx, 'tcx>
rty: Option<Ty<'tcx>>,
body_id: NodeId)
-> FnCtxt<'a, 'gcx, 'tcx>
rustc_private
)fn sess(&self) -> &Session
rustc_private
)fn err_count_since_creation(&self) -> usize
rustc_private
)fn cause(&self,
span: Span,
code: ObligationCauseCode<'tcx>)
-> ObligationCause<'tcx>
span: Span,
code: ObligationCauseCode<'tcx>)
-> ObligationCause<'tcx>
rustc_private
)fn misc(&self, span: Span) -> ObligationCause<'tcx>
rustc_private
)fn tag(&self) -> String
rustc_private
)fn local_ty(&self, span: Span, nid: NodeId) -> Ty<'tcx>
rustc_private
)fn write_ty(&self, node_id: NodeId, ty: Ty<'tcx>)
rustc_private
)fn write_substs(&self, node_id: NodeId, substs: ItemSubsts<'tcx>)
rustc_private
)fn write_autoderef_adjustment(&self,
node_id: NodeId,
derefs: usize,
adjusted_ty: Ty<'tcx>)
node_id: NodeId,
derefs: usize,
adjusted_ty: Ty<'tcx>)
rustc_private
)fn write_adjustment(&self, node_id: NodeId, adj: Adjustment<'tcx>)
rustc_private
)fn write_nil(&self, node_id: NodeId)
rustc_private
)fn write_error(&self, node_id: NodeId)
rustc_private
)fn require_type_meets(&self,
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>,
def_id: DefId)
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>,
def_id: DefId)
rustc_private
)fn require_type_is_sized(&self,
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>)
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>)
rustc_private
)fn register_bound(&self,
ty: Ty<'tcx>,
def_id: DefId,
cause: ObligationCause<'tcx>)
ty: Ty<'tcx>,
def_id: DefId,
cause: ObligationCause<'tcx>)
rustc_private
)fn register_predicate(&self, obligation: PredicateObligation<'tcx>)
rustc_private
)fn register_predicates(&self, obligations: Vec<PredicateObligation<'tcx>>)
rustc_private
)fn register_infer_ok_obligations<T>(&self, infer_ok: InferOk<'tcx, T>) -> T
rustc_private
)fn to_ty(&self, ast_t: &Ty) -> Ty<'tcx>
rustc_private
)fn node_ty(&self, id: NodeId) -> Ty<'tcx>
rustc_private
)fn opt_node_ty_substs<F>(&self, id: NodeId, f: F) where F: FnOnce(&ItemSubsts<'tcx>)
rustc_private
)fn register_region_obligation(&self,
ty: Ty<'tcx>,
region: &'tcx Region,
cause: ObligationCause<'tcx>)
ty: Ty<'tcx>,
region: &'tcx Region,
cause: ObligationCause<'tcx>)
rustc_private
)Registers an obligation for checking later, during regionck, that the type ty
must
outlive the region r
.
fn register_wf_obligation(&self,
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>)
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>)
rustc_private
)Registers an obligation for checking later, during regionck, that the type ty
must
outlive the region r
.
fn register_old_wf_obligation(&self,
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>)
ty: Ty<'tcx>,
span: Span,
code: ObligationCauseCode<'tcx>)
rustc_private
)fn add_wf_bounds(&self, substs: &Substs<'tcx>, expr: &Expr)
rustc_private
)Registers obligations that all types appearing in substs
are well-formed.
fn add_obligations_for_parameters(&self,
cause: ObligationCause<'tcx>,
predicates: &InstantiatedPredicates<'tcx>)
cause: ObligationCause<'tcx>,
predicates: &InstantiatedPredicates<'tcx>)
rustc_private
)Given a fully substituted set of bounds (generic_bounds
), and the values with which each
type/region parameter was instantiated (substs
), creates and registers suitable
trait/region obligations.
For example, if there is a function:
fn foo<'a,T:'a>(...)
and a reference:
let f = foo;
Then we will create a fresh region variable '$0
and a fresh type variable $1
for 'a
and T
. This routine will add a region obligation $1:'$0
and register it locally.
fn field_ty(&self,
span: Span,
field: &'tcx FieldDef,
substs: &Substs<'tcx>)
-> Ty<'tcx>
span: Span,
field: &'tcx FieldDef,
substs: &Substs<'tcx>)
-> Ty<'tcx>
rustc_private
)fn check_expr_has_type(&self, expr: &'gcx Expr, expected: Ty<'tcx>) -> Ty<'tcx>
rustc_private
)fn impl_self_ty(&self, span: Span, did: DefId) -> TypeAndSubsts<'tcx>
rustc_private
)fn check_struct_path(&self,
qpath: &QPath,
node_id: NodeId)
-> Option<(&'tcx VariantDef, Ty<'tcx>)>
qpath: &QPath,
node_id: NodeId)
-> Option<(&'tcx VariantDef, Ty<'tcx>)>
rustc_private
)fn resolve_ty_and_def_ufcs<'b>(&self,
qpath: &'b QPath,
node_id: NodeId,
span: Span)
-> (Def, Option<Ty<'tcx>>, &'b [PathSegment])
qpath: &'b QPath,
node_id: NodeId,
span: Span)
-> (Def, Option<Ty<'tcx>>, &'b [PathSegment])
rustc_private
)fn check_decl_initializer(&self,
local: &'gcx Local,
init: &'gcx Expr)
-> Ty<'tcx>
local: &'gcx Local,
init: &'gcx Expr)
-> Ty<'tcx>
rustc_private
)fn check_decl_local(&self, local: &'gcx Local)
rustc_private
)fn check_stmt(&self, stmt: &'gcx Stmt)
rustc_private
)fn check_block_no_value(&self, blk: &'gcx Block)
rustc_private
)fn instantiate_value_path(&self,
segments: &[PathSegment],
opt_self_ty: Option<Ty<'tcx>>,
def: Def,
span: Span,
node_id: NodeId)
-> Ty<'tcx>
segments: &[PathSegment],
opt_self_ty: Option<Ty<'tcx>>,
def: Def,
span: Span,
node_id: NodeId)
-> Ty<'tcx>
rustc_private
)fn structurally_resolved_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx>
rustc_private
)Methods from Deref<Target=Inherited<'a, 'gcx, 'tcx>>
Trait Implementations
impl<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> Clone for FnCtxt<'a, 'gcx, 'tcx>
[src]
fn clone(&self) -> FnCtxt<'a, 'gcx, 'tcx>
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0
Performs copy-assignment from source
. Read more