[−][src]Struct rustc_typeck::check::fn_ctxt::FnCtxt

pub struct FnCtxt<'a, 'tcx> {
    pub(in check) body_id: HirId,
    pub(in check) param_env: ParamEnv<'tcx>,
    err_count_on_creation: usize,
    pub(in check) ret_coercion: Option<RefCell<DynamicCoerceMany<'tcx>>>,
    pub(in check) ret_coercion_impl_trait: Option<Ty<'tcx>>,
    pub(in check) ret_type_span: Option<Span>,
    pub(in check) in_tail_expr: bool,
    pub(in check) ret_coercion_span: RefCell<Option<Span>>,
    pub(in check) resume_yield_tys: Option<(Ty<'tcx>, Ty<'tcx>)>,
    pub(in check) ps: RefCell<UnsafetyState>,
    pub(in check) diverges: Cell<Diverges>,
    pub(in check) has_errors: Cell<bool>,
    pub(in check) enclosing_breakables: RefCell<EnclosingBreakables<'tcx>>,
    pub(in check) inh: &'a Inherited<'a, 'tcx>,
}

Fields

body_id: HirIdparam_env: ParamEnv<'tcx>

The parameter environment used for proving trait obligations in this function. This can change when we descend into closures (as they bring new things into scope), hence it is not part of Inherited (as of the time of this writing, closures do not yet change the environment, but they will eventually).

err_count_on_creation: usize

Number of errors that had been reported when we started checking this function. On exit, if we find that more errors have been reported, we will skip regionck and other work that expects the types within the function to be consistent.

ret_coercion: Option<RefCell<DynamicCoerceMany<'tcx>>>

If Some, this stores coercion information for returned expressions. If None, this is in a context where return is inappropriate, such as a const expression.

This is a RefCell<DynamicCoerceMany>, which means that we can track all the return expressions and then use them to compute a useful coercion from the set, similar to a match expression or other branching context. You can use methods like expected_ty to access the declared return type (if any).

ret_coercion_impl_trait: Option<Ty<'tcx>>ret_type_span: Option<Span>in_tail_expr: bool

Used exclusively to reduce cost of advanced evaluation used for more helpful diagnostics.

ret_coercion_span: RefCell<Option<Span>>

First span of a return site that we find. Used in error messages.

resume_yield_tys: Option<(Ty<'tcx>, Ty<'tcx>)>ps: RefCell<UnsafetyState>diverges: Cell<Diverges>

Whether the last checked node generates a divergence (e.g., return will set this to Always). In general, when entering an expression or other node in the tree, the initial value indicates whether prior parts of the containing expression may have diverged. It is then typically set to Maybe (and the old value remembered) for processing the subparts of the current expression. As each subpart is processed, they may set the flag to Always, etc. Finally, at the end, we take the result and "union" it with the original value, so that when we return the flag indicates if any subpart of the parent expression (up to and including this part) has diverged. So, if you read it after evaluating a subexpression X, the value you get indicates whether any subexpression that was evaluating up to and including X diverged.

We currently use this flag only for diagnostic purposes:

An expression represents dead code if, after checking it, the diverges flag is set to something other than Maybe.

has_errors: Cell<bool>

Whether any child nodes have any type errors.

enclosing_breakables: RefCell<EnclosingBreakables<'tcx>>inh: &'a Inherited<'a, 'tcx>

Implementations

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

pub fn check_match(
    &self,
    expr: &'tcx Expr<'tcx>,
    scrut: &'tcx Expr<'tcx>,
    arms: &'tcx [Arm<'tcx>],
    orig_expected: Expectation<'tcx>,
    match_src: MatchSource
) -> Ty<'tcx>
[src]

pub(in check::_match) fn get_appropriate_arm_semicolon_removal_span(
    &self,
    arms: &'tcx [Arm<'tcx>],
    i: usize,
    prior_arm_ty: Option<Ty<'tcx>>,
    arm_ty: Ty<'tcx>
) -> (Span, Option<(Span, StatementAsExpression)>)
[src]

pub(in check::_match) fn warn_arms_when_scrutinee_diverges(
    &self,
    arms: &'tcx [Arm<'tcx>],
    source: MatchSource
)
[src]

When the previously checked expression (the scrutinee) diverges, warn the user about the match arms being unreachable.

pub(in check::_match) fn if_fallback_coercion(
    &self,
    span: Span,
    then_expr: &'tcx Expr<'tcx>,
    coercion: &mut CoerceMany<'tcx, '_, Arm<'tcx>>
) -> bool
[src]

Handle the fallback arm of a desugared if(-let) like a missing else.

Returns true if there was an error forcing the coercion to the () type.

pub(in check::_match) fn maybe_get_coercion_reason(
    &self,
    hir_id: HirId,
    span: Span
) -> Option<(Span, String)>
[src]

pub(in check::_match) fn if_cause(
    &self,
    span: Span,
    then_expr: &'tcx Expr<'tcx>,
    else_expr: &'tcx Expr<'tcx>,
    then_ty: Ty<'tcx>,
    else_ty: Ty<'tcx>,
    opt_suggest_box_span: Option<Span>
) -> ObligationCause<'tcx>
[src]

pub(in check::_match) fn demand_scrutinee_type(
    &self,
    arms: &'tcx [Arm<'tcx>],
    scrut: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::_match) fn find_block_span(
    &self,
    block: &'tcx Block<'tcx>,
    expected_ty: Option<Ty<'tcx>>
) -> (Span, Option<(Span, StatementAsExpression)>)
[src]

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

pub fn autoderef(&'a self, span: Span, base_ty: Ty<'tcx>) -> Autoderef<'a, 'tcx>[src]

pub fn autoderef_overloaded_span(
    &'a self,
    span: Span,
    base_ty: Ty<'tcx>,
    overloaded_span: Span
) -> Autoderef<'a, 'tcx>
[src]

Like autoderef, but provides a custom Span to use for calls to an overloaded Deref operator

pub fn try_overloaded_deref(
    &self,
    span: Span,
    base_ty: Ty<'tcx>
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>>
[src]

pub fn adjust_steps(
    &self,
    autoderef: &Autoderef<'a, 'tcx>
) -> Vec<Adjustment<'tcx>>
[src]

Returns the adjustment steps.

pub fn adjust_steps_as_infer_ok(
    &self,
    autoderef: &Autoderef<'a, 'tcx>
) -> InferOk<'tcx, Vec<Adjustment<'tcx>>>
[src]

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

pub fn check_call(
    &self,
    call_expr: &'tcx Expr<'tcx>,
    callee_expr: &'tcx Expr<'tcx>,
    arg_exprs: &'tcx [Expr<'tcx>],
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::callee) fn try_overloaded_call_step(
    &self,
    call_expr: &'tcx Expr<'tcx>,
    callee_expr: &'tcx Expr<'tcx>,
    arg_exprs: &'tcx [Expr<'tcx>],
    autoderef: &Autoderef<'a, 'tcx>
) -> Option<CallStep<'tcx>>
[src]

pub(in check::callee) fn try_overloaded_call_traits(
    &self,
    call_expr: &Expr<'_>,
    adjusted_ty: Ty<'tcx>,
    opt_arg_exprs: Option<&'tcx [Expr<'tcx>]>
) -> Option<(Option<Adjustment<'tcx>>, MethodCallee<'tcx>)>
[src]

pub(in check::callee) fn identify_bad_closure_def_and_call(
    &self,
    err: &mut DiagnosticBuilder<'a>,
    hir_id: HirId,
    callee_node: &ExprKind<'_>,
    callee_span: Span
)
[src]

Give appropriate suggestion when encountering ||{/* not callable */}(), where the likely intention is to call the closure, suggest (||{})(). (#55851)

pub(in check::callee) fn confirm_builtin_call(
    &self,
    call_expr: &'tcx Expr<'tcx>,
    callee_ty: Ty<'tcx>,
    arg_exprs: &'tcx [Expr<'tcx>],
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::callee) fn confirm_deferred_closure_call(
    &self,
    call_expr: &'tcx Expr<'tcx>,
    arg_exprs: &'tcx [Expr<'tcx>],
    expected: Expectation<'tcx>,
    fn_sig: FnSig<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::callee) fn confirm_overloaded_call(
    &self,
    call_expr: &'tcx Expr<'tcx>,
    arg_exprs: &'tcx [Expr<'tcx>],
    expected: Expectation<'tcx>,
    method_callee: MethodCallee<'tcx>
) -> Ty<'tcx>
[src]

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

pub(in check::cast) fn pointer_kind(
    &self,
    t: Ty<'tcx>,
    span: Span
) -> Result<Option<PointerKind<'tcx>>, ErrorReported>
[src]

Returns the kind of unsize information of t, or None if t is unknown.

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

pub(in check::cast) fn type_is_known_to_be_sized_modulo_regions(
    &self,
    ty: Ty<'tcx>,
    span: Span
) -> bool
[src]

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

pub fn check_expr_closure(
    &self,
    expr: &Expr<'_>,
    _capture: CaptureBy,
    decl: &'tcx FnDecl<'tcx>,
    body_id: BodyId,
    gen: Option<Movability>,
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::closure) fn check_closure(
    &self,
    expr: &Expr<'_>,
    opt_kind: Option<ClosureKind>,
    decl: &'tcx FnDecl<'tcx>,
    body: &'tcx Body<'tcx>,
    gen: Option<Movability>,
    expected_sig: Option<ExpectedSig<'tcx>>
) -> Ty<'tcx>
[src]

pub(in check::closure) fn deduce_expectations_from_expected_type(
    &self,
    expected_ty: Ty<'tcx>
) -> (Option<ExpectedSig<'tcx>>, Option<ClosureKind>)
[src]

Given the expected type, figures out what it can about this closure we are about to type check:

pub(in check::closure) fn deduce_expectations_from_obligations(
    &self,
    expected_vid: TyVid
) -> (Option<ExpectedSig<'tcx>>, Option<ClosureKind>)
[src]

pub(in check::closure) fn deduce_sig_from_projection(
    &self,
    cause_span: Option<Span>,
    projection: PolyProjectionPredicate<'tcx>
) -> Option<ExpectedSig<'tcx>>
[src]

Given a projection like "<F as Fn(X)>::Result == Y", we can deduce everything we need to know about a closure or generator.

The cause_span should be the span that caused us to have this expected signature, or None if we can't readily know that.

pub(in check::closure) fn sig_of_closure(
    &self,
    expr_def_id: DefId,
    decl: &FnDecl<'_>,
    body: &Body<'_>,
    expected_sig: Option<ExpectedSig<'tcx>>
) -> ClosureSignatures<'tcx>
[src]

pub(in check::closure) fn sig_of_closure_no_expectation(
    &self,
    expr_def_id: DefId,
    decl: &FnDecl<'_>,
    body: &Body<'_>
) -> ClosureSignatures<'tcx>
[src]

If there is no expected signature, then we will convert the types that the user gave into a signature.

pub(in check::closure) fn sig_of_closure_with_expectation(
    &self,
    expr_def_id: DefId,
    decl: &FnDecl<'_>,
    body: &Body<'_>,
    expected_sig: ExpectedSig<'tcx>
) -> ClosureSignatures<'tcx>
[src]

Invoked to compute the signature of a closure expression. This combines any user-provided type annotations (e.g., |x: u32| -> u32 { .. }) with the expected signature.

The approach is as follows:

  • Let S be the (higher-ranked) signature that we derive from the user's annotations.
  • Let E be the (higher-ranked) signature that we derive from the expectations, if any.
    • If we have no expectation E, then the signature of the closure is S.
    • Otherwise, the signature of the closure is E. Moreover:
      • Skolemize the late-bound regions in E, yielding E'.
      • Instantiate all the late-bound regions bound in the closure within S with fresh (existential) variables, yielding S'
      • Require that E' = S'
        • We could use some kind of subtyping relationship here, I imagine, but equality is easier and works fine for our purposes.

The key intuition here is that the user's types must be valid from "the inside" of the closure, but the expectation ultimately drives the overall signature.

Examples

fn with_closure<F>(_: F)
  where F: Fn(&u32) -> &u32 { .. }

with_closure(|x: &u32| { ... })

Here:

  • E would be fn(&u32) -> &u32.
  • S would be `fn(&u32) ->
  • E' is &'!0 u32 -> &'!0 u32
  • S' is &'?0 u32 -> ?T

S' can be unified with E' with ['?0 = '!0, ?T = &'!10 u32].

Arguments

  • expr_def_id: the DefId of the closure expression
  • decl: the HIR declaration of the closure
  • body: the body of the closure
  • expected_sig: the expected signature (if any). Note that this is missing a binder: that is, there may be late-bound regions with depth 1, which are bound then by the closure.

pub(in check::closure) fn sig_of_closure_with_mismatched_number_of_arguments(
    &self,
    expr_def_id: DefId,
    decl: &FnDecl<'_>,
    body: &Body<'_>,
    expected_sig: ExpectedSig<'tcx>
) -> ClosureSignatures<'tcx>
[src]

pub(in check::closure) fn check_supplied_sig_against_expectation(
    &self,
    expr_def_id: DefId,
    decl: &FnDecl<'_>,
    body: &Body<'_>,
    expected_sigs: &ClosureSignatures<'tcx>
) -> InferResult<'tcx, ()>
[src]

Enforce the user's types against the expectation. See sig_of_closure_with_expectation for details on the overall strategy.

pub(in check::closure) fn supplied_sig_of_closure(
    &self,
    expr_def_id: DefId,
    decl: &FnDecl<'_>,
    body: &Body<'_>
) -> PolyFnSig<'tcx>
[src]

If there is no expected signature, then we will convert the types that the user gave into a signature.

Also, record this closure signature for later.

pub(in check::closure) fn deduce_future_output_from_obligations(
    &self,
    expr_def_id: DefId
) -> Option<Ty<'tcx>>
[src]

Invoked when we are translating the generator that results from desugaring an async fn. Returns the "sugared" return type of the async fn -- that is, the return type that the user specified. The "desugared" return type is a impl Future<Output = T>, so we do this by searching through the obligations to extract the T.

pub(in check::closure) fn deduce_future_output_from_projection(
    &self,
    cause_span: Span,
    predicate: PolyProjectionPredicate<'tcx>
) -> Option<Ty<'tcx>>
[src]

Given a projection like

<X as Future>::Output = T

where X is some type that has no late-bound regions, returns Some(T). If the projection is for some other trait, returns None.

pub(in check::closure) fn error_sig_of_closure(
    &self,
    decl: &FnDecl<'_>
) -> PolyFnSig<'tcx>
[src]

Converts the types that the user supplied, in case that doing so should yield an error, but returns back a signature where all parameters are of type TyErr.

pub(in check::closure) fn closure_sigs(
    &self,
    expr_def_id: DefId,
    body: &Body<'_>,
    bound_sig: PolyFnSig<'tcx>
) -> ClosureSignatures<'tcx>
[src]

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

pub fn try_coerce(
    &self,
    expr: &Expr<'_>,
    expr_ty: Ty<'tcx>,
    target: Ty<'tcx>,
    allow_two_phase: AllowTwoPhase
) -> RelateResult<'tcx, Ty<'tcx>>
[src]

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.

pub fn can_coerce(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> bool[src]

Same as try_coerce(), but without side-effects.

pub fn deref_steps(&self, expr_ty: Ty<'tcx>, target: Ty<'tcx>) -> Option<usize>[src]

Given a type and a target type, this function will calculate and return how many dereference steps needed to achieve expr_ty <: target. If it's not possible, return None.

pub(in check::coercion) fn try_find_coercion_lub<E>(
    &self,
    cause: &ObligationCause<'tcx>,
    exprs: &[E],
    prev_ty: Ty<'tcx>,
    new: &Expr<'_>,
    new_ty: Ty<'tcx>
) -> RelateResult<'tcx, Ty<'tcx>> where
    E: AsCoercionSite, 
[src]

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

This is really an internal helper. From outside the coercion module, you should instantiate a CoerceMany instance.

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

pub fn emit_coerce_suggestions(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    expr_ty: Ty<'tcx>,
    expected: Ty<'tcx>,
    expected_ty_expr: Option<&'tcx Expr<'tcx>>
)
[src]

pub fn demand_suptype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>)[src]

pub fn demand_suptype_diag(
    &self,
    sp: Span,
    expected: Ty<'tcx>,
    actual: Ty<'tcx>
) -> Option<DiagnosticBuilder<'tcx>>
[src]

pub fn demand_suptype_with_origin(
    &self,
    cause: &ObligationCause<'tcx>,
    expected: Ty<'tcx>,
    actual: Ty<'tcx>
) -> Option<DiagnosticBuilder<'tcx>>
[src]

pub fn demand_eqtype(&self, sp: Span, expected: Ty<'tcx>, actual: Ty<'tcx>)[src]

pub fn demand_eqtype_diag(
    &self,
    sp: Span,
    expected: Ty<'tcx>,
    actual: Ty<'tcx>
) -> Option<DiagnosticBuilder<'tcx>>
[src]

pub fn demand_eqtype_with_origin(
    &self,
    cause: &ObligationCause<'tcx>,
    expected: Ty<'tcx>,
    actual: Ty<'tcx>
) -> Option<DiagnosticBuilder<'tcx>>
[src]

pub fn demand_coerce(
    &self,
    expr: &Expr<'_>,
    checked_ty: Ty<'tcx>,
    expected: Ty<'tcx>,
    expected_ty_expr: Option<&'tcx Expr<'tcx>>,
    allow_two_phase: AllowTwoPhase
) -> Ty<'tcx>
[src]

pub fn demand_coerce_diag(
    &self,
    expr: &Expr<'_>,
    checked_ty: Ty<'tcx>,
    expected: Ty<'tcx>,
    expected_ty_expr: Option<&'tcx Expr<'tcx>>,
    allow_two_phase: AllowTwoPhase
) -> (Ty<'tcx>, Option<DiagnosticBuilder<'tcx>>)
[src]

Checks that the type of expr can be coerced to expected.

N.B., this code relies on self.diverges to be accurate. In particular, assignments to ! will be permitted if the diverges flag is currently "always".

pub(in check::demand) fn annotate_expected_due_to_let_ty(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>
)
[src]

pub fn is_assign_to_bool(&self, expr: &Expr<'_>, expected: Ty<'tcx>) -> bool[src]

Returns whether the expected type is bool and the expression is x = y.

pub(in check::demand) fn suggest_compatible_variants(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    expected: Ty<'tcx>,
    expr_ty: Ty<'tcx>
)
[src]

If the expected type is an enum (Issue #55250) with any variants whose sole field is of the found type, suggest such variants. (Issue #42764)

pub fn get_conversion_methods(
    &self,
    span: Span,
    expected: Ty<'tcx>,
    checked_ty: Ty<'tcx>,
    hir_id: HirId
) -> Vec<AssocItem>
[src]

pub(in check::demand) fn has_only_self_parameter(
    &self,
    method: &AssocItem
) -> bool
[src]

This function checks whether the method is not static and does not accept other parameters than self.

pub(in check::demand) fn can_use_as_ref(
    &self,
    expr: &Expr<'_>
) -> Option<(Span, &'static str, String)>
[src]

Identify some cases where as_ref() would be appropriate and suggest it.

Given the following code:

struct Foo;
fn takes_ref(_: &Foo) {}
let ref opt = Some(Foo);

opt.map(|param| takes_ref(param));

Suggest using opt.as_ref().map(|param| takes_ref(param)); instead.

It only checks for Option and Result and won't work with

opt.map(|param| { takes_ref(param) });

pub(crate) fn is_hir_id_from_struct_pattern_shorthand_field(
    &self,
    hir_id: HirId,
    sp: Span
) -> bool
[src]

pub(in check::demand) fn replace_prefix(
    &self,
    s: &str,
    old: &str,
    new: &str
) -> Option<String>
[src]

pub fn check_ref(
    &self,
    expr: &Expr<'_>,
    checked_ty: Ty<'tcx>,
    expected: Ty<'tcx>
) -> Option<(Span, &'static str, String, Applicability)>
[src]

This function is used to determine potential "simple" improvements or users' errors and provide them useful help. For example:

fn some_fn(s: &str) {}

let x = "hey!".to_owned();
some_fn(x); // error

No need to find every potential function which could make a coercion to transform a String into a &str since a & would do the trick!

In addition of this check, it also checks between references mutability state. If the expected is mutable but the provided isn't, maybe we could just say "Hey, try with &mut!".

pub fn check_for_cast(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    checked_ty: Ty<'tcx>,
    expected_ty: Ty<'tcx>,
    expected_ty_expr: Option<&'tcx Expr<'tcx>>
) -> bool
[src]

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

pub(in check::expr) fn check_expr_eq_type(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Ty<'tcx>
)
[src]

pub fn check_expr_has_type_or_error(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Ty<'tcx>,
    extend_err: impl Fn(&mut DiagnosticBuilder<'_>)
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_meets_expectation_or_error(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>,
    extend_err: impl Fn(&mut DiagnosticBuilder<'_>)
) -> Ty<'tcx>
[src]

pub(in check) fn check_expr_coercable_to_type(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Ty<'tcx>,
    expected_ty_expr: Option<&'tcx Expr<'tcx>>
) -> Ty<'tcx>
[src]

pub(in check) fn check_expr_with_hint(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Ty<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_with_expectation_and_needs(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>,
    needs: Needs
) -> Ty<'tcx>
[src]

pub(in check) fn check_expr(
    &self,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check) fn check_expr_with_needs(
    &self,
    expr: &'tcx Expr<'tcx>,
    needs: Needs
) -> Ty<'tcx>
[src]

pub(in check) fn check_expr_with_expectation(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

Invariant: If an expression has any sub-expressions that result in a type error, inspecting that expression's type with ty.references_error() will return true. Likewise, if an expression is known to diverge, inspecting its type with ty::type_is_bot will return true (n.b.: since Rust is strict, | can appear in the type of an expression that does not, itself, diverge: for example, fn() -> |.) Note that inspecting a type's structure directly may expose the fact that there are actually multiple representations for Error, so avoid that when err needs to be handled differently.

pub(in check::expr) fn check_expr_kind(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_box(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_unary(
    &self,
    unop: UnOp,
    oprnd: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_addr_of(
    &self,
    kind: BorrowKind,
    mutbl: Mutability,
    oprnd: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_named_place_expr(
    &self,
    oprnd: &'tcx Expr<'tcx>
)
[src]

Does this expression refer to a place that either:

  • Is based on a local or static.
  • Contains a dereference Note that the adjustments for the children of expr should already have been resolved.

pub(in check::expr) fn check_lang_item_path(
    &self,
    lang_item: LangItem,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_path(
    &self,
    qpath: &QPath<'_>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_break(
    &self,
    destination: Destination,
    expr_opt: Option<&'tcx Expr<'tcx>>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_return(
    &self,
    expr_opt: Option<&'tcx Expr<'tcx>>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check) fn check_return_expr(
    &self,
    return_expr: &'tcx Expr<'tcx>
)
[src]

pub(crate) fn check_lhs_assignable(
    &self,
    lhs: &'tcx Expr<'tcx>,
    err_code: &'static str,
    expr_span: &Span
)
[src]

pub(in check::expr) fn check_expr_assign(
    &self,
    expr: &'tcx Expr<'tcx>,
    expected: Expectation<'tcx>,
    lhs: &'tcx Expr<'tcx>,
    rhs: &'tcx Expr<'tcx>,
    span: &Span
) -> Ty<'tcx>
[src]

Type check assignment expression expr of form lhs = rhs. The expected type is () and is passsed to the function for the purposes of diagnostics.

pub(in check::expr) fn check_expr_loop(
    &self,
    body: &'tcx Block<'tcx>,
    source: LoopSource,
    expected: Expectation<'tcx>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_method_call(
    &self,
    expr: &'tcx Expr<'tcx>,
    segment: &PathSegment<'_>,
    span: Span,
    args: &'tcx [Expr<'tcx>],
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

Checks a method call.

pub(in check::expr) fn report_extended_method_error(
    &self,
    segment: &PathSegment<'_>,
    span: Span,
    args: &'tcx [Expr<'tcx>],
    rcvr_t: Ty<'tcx>,
    error: MethodError<'tcx>
)
[src]

pub(in check::expr) fn check_expr_cast(
    &self,
    e: &'tcx Expr<'tcx>,
    t: &'tcx Ty<'tcx>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_array(
    &self,
    args: &'tcx [Expr<'tcx>],
    expected: Expectation<'tcx>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_repeat(
    &self,
    element: &'tcx Expr<'tcx>,
    count: &'tcx AnonConst,
    expected: Expectation<'tcx>,
    _expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_tuple(
    &self,
    elts: &'tcx [Expr<'tcx>],
    expected: Expectation<'tcx>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_struct(
    &self,
    expr: &Expr<'_>,
    expected: Expectation<'tcx>,
    qpath: &QPath<'_>,
    fields: &'tcx [Field<'tcx>],
    base_expr: &'tcx Option<&'tcx Expr<'tcx>>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_struct_fields(
    &self,
    adt_ty: Ty<'tcx>,
    expected: Expectation<'tcx>,
    expr_id: HirId,
    span: Span,
    variant: &'tcx VariantDef,
    ast_fields: &'tcx [Field<'tcx>],
    check_completeness: bool
) -> bool
[src]

pub(in check::expr) fn check_struct_fields_on_error(
    &self,
    fields: &'tcx [Field<'tcx>],
    base_expr: &'tcx Option<&'tcx Expr<'tcx>>
)
[src]

pub(in check::expr) fn report_missing_field(
    &self,
    adt_ty: Ty<'tcx>,
    span: Span,
    remaining_fields: FxHashMap<Ident, (usize, &FieldDef)>
)
[src]

Report an error for a struct field expression when there are fields which aren't provided.

error: missing field `you_can_use_this_field` in initializer of `foo::Foo`
 --> src/main.rs:8:5
  |
8 |     foo::Foo {};
  |     ^^^^^^^^ missing `you_can_use_this_field`

error: aborting due to previous error

pub(in check::expr) fn report_no_accessible_fields(
    &self,
    adt_ty: Ty<'tcx>,
    span: Span
)
[src]

Report an error for a struct field expression when there are no visible fields.

error: cannot construct `Foo` with struct literal syntax due to inaccessible fields
 --> src/main.rs:8:5
  |
8 |     foo::Foo {};
  |     ^^^^^^^^

error: aborting due to previous error

pub(in check::expr) fn report_unknown_field(
    &self,
    ty: Ty<'tcx>,
    variant: &'tcx VariantDef,
    field: &Field<'_>,
    skip_fields: &[Field<'_>],
    kind_name: &str,
    ty_span: Span
)
[src]

pub(in check::expr) fn suggest_field_name(
    variant: &'tcx VariantDef,
    field: Symbol,
    skip: Vec<Symbol>
) -> Option<Symbol>
[src]

pub(in check::expr) fn available_field_names(
    &self,
    variant: &'tcx VariantDef
) -> Vec<Symbol>
[src]

pub(in check::expr) fn name_series_display(
    &self,
    names: Vec<Symbol>
) -> String
[src]

pub(in check::expr) fn check_field(
    &self,
    expr: &'tcx Expr<'tcx>,
    base: &'tcx Expr<'tcx>,
    field: Ident
) -> Ty<'tcx>
[src]

pub(in check::expr) fn suggest_await_on_field_access(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    field_ident: Ident,
    base: &'tcx Expr<'tcx>,
    ty: Ty<'tcx>
)
[src]

pub(in check::expr) fn ban_nonexisting_field(
    &self,
    field: Ident,
    base: &'tcx Expr<'tcx>,
    expr: &'tcx Expr<'tcx>,
    expr_t: Ty<'tcx>
)
[src]

pub(in check::expr) fn ban_private_field_access(
    &self,
    expr: &Expr<'_>,
    expr_t: Ty<'tcx>,
    field: Ident,
    base_did: DefId
)
[src]

pub(in check::expr) fn ban_take_value_of_method(
    &self,
    expr: &Expr<'_>,
    expr_t: Ty<'tcx>,
    field: Ident
)
[src]

pub(in check::expr) fn point_at_param_definition(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    param: ParamTy
)
[src]

pub(in check::expr) fn suggest_fields_on_recordish(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    def: &'tcx AdtDef,
    field: Ident
)
[src]

pub(in check::expr) fn maybe_suggest_array_indexing(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    base: &Expr<'_>,
    field: Ident,
    len: &Const<'tcx>
)
[src]

pub(in check::expr) fn suggest_first_deref_field(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    base: &Expr<'_>,
    field: Ident
)
[src]

pub(in check::expr) fn no_such_field_err<T: Display>(
    &self,
    span: Span,
    field: T,
    expr_t: &TyS<'_>
) -> DiagnosticBuilder<'_>
[src]

pub(in check::expr) fn check_expr_index(
    &self,
    base: &'tcx Expr<'tcx>,
    idx: &'tcx Expr<'tcx>,
    expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_yield(
    &self,
    value: &'tcx Expr<'tcx>,
    expr: &'tcx Expr<'tcx>,
    src: &'tcx YieldSource
) -> Ty<'tcx>
[src]

pub(in check::expr) fn check_expr_asm_operand(
    &self,
    expr: &'tcx Expr<'tcx>,
    is_input: bool
)
[src]

pub(in check::expr) fn check_expr_asm(
    &self,
    asm: &'tcx InlineAsm<'tcx>
) -> Ty<'tcx>
[src]

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

pub(in check) fn warn_if_unreachable(
    &self,
    id: HirId,
    span: Span,
    kind: &str
)
[src]

Produces warning on the given node, if the current point in the function is unreachable, and there hasn't been another warning.

pub(in check) fn resolve_vars_with_obligations(
    &self,
    ty: Ty<'tcx>
) -> Ty<'tcx>
[src]

Resolves type and const variables in ty if possible. Unlike the infcx version (resolve_vars_if_possible), this version will also select obligations if it seems useful, in an effort to get more type information.

pub(in check) fn record_deferred_call_resolution(
    &self,
    closure_def_id: DefId,
    r: DeferredCallResolution<'tcx>
)
[src]

pub(in check) fn remove_deferred_call_resolutions(
    &self,
    closure_def_id: DefId
) -> Vec<DeferredCallResolution<'tcx>>
[src]

pub fn tag(&self) -> String[src]

pub fn local_ty(&self, span: Span, nid: HirId) -> LocalTy<'tcx>[src]

pub fn write_ty(&self, id: HirId, ty: Ty<'tcx>)[src]

pub fn write_field_index(&self, hir_id: HirId, index: usize)[src]

pub(in check) fn write_resolution(
    &self,
    hir_id: HirId,
    r: Result<(DefKind, DefId), ErrorReported>
)
[src]

pub fn write_method_call(&self, hir_id: HirId, method: MethodCallee<'tcx>)[src]

pub fn write_substs(&self, node_id: HirId, substs: SubstsRef<'tcx>)[src]

pub fn write_user_type_annotation_from_substs(
    &self,
    hir_id: HirId,
    def_id: DefId,
    substs: SubstsRef<'tcx>,
    user_self_ty: Option<UserSelfTy<'tcx>>
)
[src]

Given the substs that we just converted from the HIR, try to canonicalize them and store them as user-given substitutions (i.e., substitutions that must be respected by the NLL check).

This should be invoked before any unifications have occurred, so that annotations like Vec<_> are preserved properly.

pub fn write_user_type_annotation(
    &self,
    hir_id: HirId,
    canonical_user_type_annotation: CanonicalUserType<'tcx>
)
[src]

pub fn apply_adjustments(&self, expr: &Expr<'_>, adj: Vec<Adjustment<'tcx>>)[src]

pub(in check::fn_ctxt::_impl) fn instantiate_type_scheme<T>(
    &self,
    span: Span,
    substs: SubstsRef<'tcx>,
    value: T
) -> T where
    T: TypeFoldable<'tcx>, 
[src]

Basically whenever we are converting from a type scheme into the fn body space, we always want to normalize associated types as well. This function combines the two.

pub(in check) fn instantiate_bounds(
    &self,
    span: Span,
    def_id: DefId,
    substs: SubstsRef<'tcx>
) -> (InstantiatedPredicates<'tcx>, Vec<Span>)
[src]

As instantiate_type_scheme, but for the bounds found in a generic type scheme.

pub(in check) fn instantiate_opaque_types_from_value<T: TypeFoldable<'tcx>>(
    &self,
    parent_id: HirId,
    value: T,
    value_span: Span
) -> T
[src]

Replaces the opaque types from the given value with type variables, and records the OpaqueTypeMap for later use during writeback. See InferCtxt::instantiate_opaque_types for more details.

pub(in check) fn normalize_associated_types_in<T>(
    &self,
    span: Span,
    value: T
) -> T where
    T: TypeFoldable<'tcx>, 
[src]

pub(in check) fn normalize_associated_types_in_as_infer_ok<T>(
    &self,
    span: Span,
    value: T
) -> InferOk<'tcx, T> where
    T: TypeFoldable<'tcx>, 
[src]

pub fn require_type_meets(
    &self,
    ty: Ty<'tcx>,
    span: Span,
    code: ObligationCauseCode<'tcx>,
    def_id: DefId
)
[src]

pub fn require_type_is_sized(
    &self,
    ty: Ty<'tcx>,
    span: Span,
    code: ObligationCauseCode<'tcx>
)
[src]

pub fn require_type_is_sized_deferred(
    &self,
    ty: Ty<'tcx>,
    span: Span,
    code: ObligationCauseCode<'tcx>
)
[src]

pub fn register_bound(
    &self,
    ty: Ty<'tcx>,
    def_id: DefId,
    cause: ObligationCause<'tcx>
)
[src]

pub fn to_ty(&self, ast_t: &Ty<'_>) -> Ty<'tcx>[src]

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

pub fn to_const(&self, ast_c: &AnonConst) -> &'tcx Const<'tcx>[src]

pub fn const_arg_to_const(
    &self,
    ast_c: &AnonConst,
    param_def_id: DefId
) -> &'tcx Const<'tcx>
[src]

pub(in check::fn_ctxt::_impl) fn can_contain_user_lifetime_bounds<T>(
    t: T
) -> bool where
    T: TypeFoldable<'tcx>, 
[src]

pub fn node_ty(&self, id: HirId) -> Ty<'tcx>[src]

pub fn register_wf_obligation(
    &self,
    arg: GenericArg<'tcx>,
    span: Span,
    code: ObligationCauseCode<'tcx>
)
[src]

Registers an obligation for checking later, during regionck, that arg is well-formed.

pub fn add_wf_bounds(&self, substs: SubstsRef<'tcx>, expr: &Expr<'_>)[src]

Registers obligations that all substs are well-formed.

pub fn add_obligations_for_parameters(
    &self,
    cause: ObligationCause<'tcx>,
    predicates: InstantiatedPredicates<'tcx>
)
[src]

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.

pub fn field_ty(
    &self,
    span: Span,
    field: &'tcx FieldDef,
    substs: SubstsRef<'tcx>
) -> Ty<'tcx>
[src]

pub(in check) fn resolve_generator_interiors(
    &self,
    def_id: DefId
)
[src]

pub(in check) fn fallback_if_possible(
    &self,
    ty: Ty<'tcx>,
    mode: FallbackMode
) -> bool
[src]

pub(in check) fn select_all_obligations_or_error(
    &self
)
[src]

pub(in check) fn select_obligations_where_possible(
    &self,
    fallback_has_occurred: bool,
    mutate_fullfillment_errors: impl Fn(&mut Vec<FulfillmentError<'tcx>>)
)
[src]

Select as many obligations as we can at present.

pub(in check) fn make_overloaded_place_return_type(
    &self,
    method: MethodCallee<'tcx>
) -> TypeAndMut<'tcx>
[src]

For the overloaded place expressions (*x, x[3]), the trait returns a type of &T, but the actual type we assign to the expression is T. So this function just peels off the return type by one layer to yield T.

pub(in check::fn_ctxt::_impl) fn self_type_matches_expected_vid(
    &self,
    trait_ref: PolyTraitRef<'tcx>,
    expected_vid: TyVid
) -> bool
[src]

pub(in check) fn obligations_for_self_ty<'b>(
    &'b self,
    self_ty: TyVid
) -> impl Iterator<Item = (PolyTraitRef<'tcx>, PredicateObligation<'tcx>)> + Captures<'tcx> + 'b
[src]

pub(in check) fn type_var_is_sized(
    &self,
    self_ty: TyVid
) -> bool
[src]

pub(in check) fn err_args(
    &self,
    len: usize
) -> Vec<Ty<'tcx>>
[src]

pub(in check) fn expected_inputs_for_expected_output(
    &self,
    call_span: Span,
    expected_ret: Expectation<'tcx>,
    formal_ret: Ty<'tcx>,
    formal_args: &[Ty<'tcx>]
) -> Vec<Ty<'tcx>>
[src]

Unifies the output type with the expected type early, for more coercions and forward type information on the input expressions.

pub(in check) fn resolve_lang_item_path(
    &self,
    lang_item: LangItem,
    span: Span,
    hir_id: HirId
) -> (Res, Ty<'tcx>)
[src]

pub fn resolve_ty_and_res_ufcs<'b>(
    &self,
    qpath: &'b QPath<'b>,
    hir_id: HirId,
    span: Span
) -> (Res, Option<Ty<'tcx>>, &'b [PathSegment<'b>])
[src]

Resolves an associated value path into a base type and associated constant, or method resolution. The newly resolved definition is written into type_dependent_defs.

pub(in check) fn get_node_fn_decl(
    &self,
    node: Node<'tcx>
) -> Option<(&'tcx FnDecl<'tcx>, Ident, bool)>
[src]

Given a function Node, return its FnDecl if it exists, or None otherwise.

pub fn get_fn_decl(&self, blk_id: HirId) -> Option<(&'tcx FnDecl<'tcx>, bool)>[src]

Given a HirId, return the FnDecl of the method it is enclosed by and whether a suggestion can be made, None otherwise.

pub(in check) fn note_internal_mutation_in_method(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>
)
[src]

pub(in check) fn note_need_for_fn_pointer(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>
)
[src]

pub(in check) fn could_remove_semicolon(
    &self,
    blk: &'tcx Block<'tcx>,
    expected_ty: Ty<'tcx>
) -> Option<(Span, StatementAsExpression)>
[src]

pub fn instantiate_value_path(
    &self,
    segments: &[PathSegment<'_>],
    self_ty: Option<Ty<'tcx>>,
    res: Res,
    span: Span,
    hir_id: HirId
) -> (Ty<'tcx>, Res)
[src]

pub(in check::fn_ctxt::_impl) fn add_required_obligations(
    &self,
    span: Span,
    def_id: DefId,
    substs: &SubstsRef<'tcx>
)
[src]

Add all the obligations that are required, substituting and normalized appropriately.

pub fn structurally_resolved_type(&self, sp: Span, ty: Ty<'tcx>) -> Ty<'tcx>[src]

Resolves typ by a single level if typ is a type variable. If no resolution is possible, then an error is reported. Numeric inference variables may be left unresolved.

pub(in check) fn with_breakable_ctxt<F: FnOnce() -> R, R>(
    &self,
    id: HirId,
    ctxt: BreakableCtxt<'tcx>,
    f: F
) -> (BreakableCtxt<'tcx>, R)
[src]

pub(in check) fn probe_instantiate_query_response(
    &self,
    span: Span,
    original_values: &OriginalQueryValues<'tcx>,
    query_result: &Canonical<'tcx, QueryResponse<'tcx, Ty<'tcx>>>
) -> InferResult<'tcx, Ty<'tcx>>
[src]

Instantiate a QueryResponse in a probe context, without a good ObligationCause.

pub(in check) fn expr_in_place(
    &self,
    expr_id: HirId
) -> bool
[src]

Returns true if an expression is contained inside the LHS of an assignment expression.

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

pub(in check) fn check_casts(
    &self
)
[src]

pub(in check) fn check_method_argument_types(
    &self,
    sp: Span,
    expr: &'tcx Expr<'tcx>,
    method: Result<MethodCallee<'tcx>, ()>,
    args_no_rcvr: &'tcx [Expr<'tcx>],
    tuple_arguments: TupleArgumentsFlag,
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub(in check) fn check_argument_types(
    &self,
    sp: Span,
    expr: &'tcx Expr<'tcx>,
    fn_inputs: &[Ty<'tcx>],
    expected_arg_tys: &[Ty<'tcx>],
    args: &'tcx [Expr<'tcx>],
    c_variadic: bool,
    tuple_arguments: TupleArgumentsFlag,
    def_id: Option<DefId>
)
[src]

Generic function that factors out common logic from function calls, method calls and overloaded operators.

pub(in check) fn check_lit(
    &self,
    lit: &Lit,
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub fn check_struct_path(
    &self,
    qpath: &QPath<'_>,
    hir_id: HirId
) -> Option<(&'tcx VariantDef, Ty<'tcx>)>
[src]

pub fn check_decl_initializer(
    &self,
    local: &'tcx Local<'tcx>,
    init: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

pub fn check_decl_local(&self, local: &'tcx Local<'tcx>)[src]

Type check a let statement.

pub fn check_stmt(&self, stmt: &'tcx Stmt<'tcx>)[src]

pub fn check_block_no_value(&self, blk: &'tcx Block<'tcx>)[src]

pub(in check) fn check_block_with_expected(
    &self,
    blk: &'tcx Block<'tcx>,
    expected: Expectation<'tcx>
) -> Ty<'tcx>
[src]

pub(in check) fn check_rustc_args_require_const(
    &self,
    def_id: DefId,
    hir_id: HirId,
    span: Span
)
[src]

pub(in check::fn_ctxt::checks) fn consider_hint_about_removing_semicolon(
    &self,
    blk: &'tcx Block<'tcx>,
    expected_ty: Ty<'tcx>,
    err: &mut DiagnosticBuilder<'_>
)
[src]

A common error is to add an extra semicolon:

fn foo() -> usize {
    22;
}

This routine checks if the final statement in a block is an expression with an explicit semicolon whose type is compatible with expected_ty. If so, it suggests removing the semicolon.

pub(in check::fn_ctxt::checks) fn parent_item_span(
    &self,
    id: HirId
) -> Option<Span>
[src]

pub(in check::fn_ctxt::checks) fn get_parent_fn_decl(
    &self,
    blk_id: HirId
) -> Option<(&'tcx FnDecl<'tcx>, Ident)>
[src]

Given a function block's HirId, returns its FnDecl if it exists, or None otherwise.

pub(in check::fn_ctxt::checks) fn get_expr_coercion_span(
    &self,
    expr: &Expr<'_>
) -> Span
[src]

If expr is a match expression that has only one non-! arm, use that arm's tail expression's Span, otherwise return expr.span. This is done to give better errors when given code like the following:

if false { return 0i32; } else { 1u32 }
//                               ^^^^ point at this instead of the whole `if` expression

pub(in check::fn_ctxt::checks) fn overwrite_local_ty_if_err(
    &self,
    local: &'tcx Local<'tcx>,
    decl_ty: Ty<'tcx>,
    ty: Ty<'tcx>
)
[src]

pub(in check::fn_ctxt::checks) fn finish_resolving_struct_path(
    &self,
    qpath: &QPath<'_>,
    path_span: Span,
    hir_id: HirId
) -> (Res, Ty<'tcx>)
[src]

pub(in check::fn_ctxt::checks) fn point_at_arg_instead_of_call_if_possible(
    &self,
    errors: &mut Vec<FulfillmentError<'tcx>>,
    final_arg_types: &[(usize, Ty<'tcx>, Ty<'tcx>)],
    call_sp: Span,
    args: &'tcx [Expr<'tcx>]
)
[src]

Given a vec of evaluated FulfillmentErrors and an fn call argument expressions, we walk the checked and coerced types for each argument to see if any of the FulfillmentErrors reference a type argument. The reason to walk also the checked type is that the coerced type can be not easily comparable with predicate type (because of coercion). If the types match for either checked or coerced type, and there's only one argument that does, we point at the corresponding argument's expression span instead of the fn call path span.

pub(in check::fn_ctxt::checks) fn point_at_type_arg_instead_of_call_if_possible(
    &self,
    errors: &mut Vec<FulfillmentError<'tcx>>,
    call_expr: &'tcx Expr<'tcx>
)
[src]

Given a vec of evaluated FulfillmentErrors and an fn call expression, we walk the PathSegments and resolve their type parameters to see if any of the FulfillmentErrors were caused by them. If they were, we point at the corresponding type argument's span instead of the fn call path span.

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

pub(in check) fn suggest_semicolon_at_end(
    &self,
    span: Span,
    err: &mut DiagnosticBuilder<'_>
)
[src]

pub fn suggest_mismatched_types_on_tail(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &'tcx Expr<'tcx>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>,
    cause_span: Span,
    blk_id: HirId
) -> bool
[src]

On implicit return expressions with mismatched types, provides the following suggestions:

  • Points out the method's return type as the reason for the expected type.
  • Possible missing semicolon.
  • Possible missing return type if the return type is the default, and not fn main().

pub(in check::fn_ctxt::suggestions) fn suggest_fn_call(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>
) -> bool
[src]

When encountering an fn-like ctor that needs to unify with a value, check whether calling the ctor would successfully solve the type mismatch and if so, suggest it:

fn foo(x: usize) -> usize { x }
let x: usize = foo;  // suggest calling the `foo` function: `foo(42)`

pub fn suggest_deref_ref_or_into(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>,
    expected_ty_expr: Option<&'tcx Expr<'tcx>>
)
[src]

pub(in check) fn suggest_boxing_when_appropriate(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>
)
[src]

When encountering the expected boxed value allocated in the stack, suggest allocating it in the heap by calling Box::new().

pub(in check) fn suggest_calling_boxed_future_when_appropriate(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>
) -> bool
[src]

When encountering an impl Future where BoxFuture is expected, suggest Box::pin.

pub(in check::fn_ctxt::suggestions) fn suggest_missing_semicolon(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expression: &'tcx Expr<'tcx>,
    expected: Ty<'tcx>,
    cause_span: Span
)
[src]

A common error is to forget to add a semicolon at the end of a block, e.g.,

fn foo() {
    bar_that_returns_u32()
}

This routine checks if the return expression in a block would make sense on its own as a statement and the return type has been left as default or has been specified as (). If so, it suggests adding a semicolon.

pub(in check) fn suggest_missing_return_type(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    fn_decl: &FnDecl<'_>,
    expected: Ty<'tcx>,
    found: Ty<'tcx>,
    can_suggest: bool
) -> bool
[src]

A possible error is to forget to add a return type that is needed:

fn foo() {
    bar_that_returns_u32()
}

This routine checks if the return type is left as default, the method is not part of an impl block and that it isn't the main method. If so, it suggests setting the return type.

pub(in check) fn suggest_missing_parentheses(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    expr: &Expr<'_>
)
[src]

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

pub fn new(
    inh: &'a Inherited<'a, 'tcx>,
    param_env: ParamEnv<'tcx>,
    body_id: HirId
) -> FnCtxt<'a, 'tcx>
[src]

pub fn cause(
    &self,
    span: Span,
    code: ObligationCauseCode<'tcx>
) -> ObligationCause<'tcx>
[src]

pub fn misc(&self, span: Span) -> ObligationCause<'tcx>[src]

pub fn sess(&self) -> &Session[src]

pub fn errors_reported_since_creation(&self) -> bool[src]

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

pub fn confirm_method(
    &self,
    span: Span,
    self_expr: &'tcx Expr<'tcx>,
    call_expr: &'tcx Expr<'tcx>,
    unadjusted_self_ty: Ty<'tcx>,
    pick: Pick<'tcx>,
    segment: &PathSegment<'_>
) -> ConfirmResult<'tcx>
[src]

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

pub fn probe_for_return_type(
    &self,
    span: Span,
    mode: Mode,
    return_type: Ty<'tcx>,
    self_ty: Ty<'tcx>,
    scope_expr_id: HirId
) -> Vec<AssocItem>
[src]

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

pub fn probe_for_name(
    &self,
    span: Span,
    mode: Mode,
    item_name: Ident,
    is_suggestion: IsSuggestion,
    self_ty: Ty<'tcx>,
    scope_expr_id: HirId,
    scope: ProbeScope
) -> PickResult<'tcx>
[src]

pub(in check::method::probe) fn probe_op<OP, R>(
    &'a self,
    span: Span,
    mode: Mode,
    method_name: Option<Ident>,
    return_type: Option<Ty<'tcx>>,
    is_suggestion: IsSuggestion,
    self_ty: Ty<'tcx>,
    scope_expr_id: HirId,
    scope: ProbeScope,
    op: OP
) -> Result<R, MethodError<'tcx>> where
    OP: FnOnce(ProbeContext<'a, 'tcx>) -> Result<R, MethodError<'tcx>>, 
[src]

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

pub(in check::method::suggest) fn is_fn_ty(
    &self,
    ty: Ty<'tcx>,
    span: Span
) -> bool
[src]

pub fn report_method_error<'b>(
    &self,
    span: Span,
    rcvr_ty: Ty<'tcx>,
    item_name: Ident,
    source: SelfSource<'b>,
    error: MethodError<'tcx>,
    args: Option<&'tcx [Expr<'tcx>]>
) -> Option<DiagnosticBuilder<'_>>
[src]

pub(in check::method::suggest) fn ty_to_value_string(
    &self,
    ty: Ty<'tcx>
) -> String
[src]

Print out the type for use in value namespace.

pub(in check::method::suggest) fn suggest_await_before_method(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    item_name: Ident,
    ty: Ty<'tcx>,
    call: &Expr<'_>,
    span: Span
)
[src]

pub(in check::method::suggest) fn suggest_use_candidates(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    msg: String,
    candidates: Vec<DefId>
)
[src]

pub(in check::method::suggest) fn suggest_valid_traits(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    valid_out_of_scope_traits: Vec<DefId>
) -> bool
[src]

pub(in check::method::suggest) fn suggest_traits_to_import<'b>(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    span: Span,
    rcvr_ty: Ty<'tcx>,
    item_name: Ident,
    source: SelfSource<'b>,
    valid_out_of_scope_traits: Vec<DefId>,
    unsatisfied_predicates: &[(Predicate<'tcx>, Option<Predicate<'tcx>>)]
)
[src]

pub(in check::method::suggest) fn type_derefs_to_local(
    &self,
    span: Span,
    rcvr_ty: Ty<'tcx>,
    source: SelfSource<'_>
) -> bool
[src]

Checks whether there is a local type somewhere in the chain of autoderefs of rcvr_ty.

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

pub fn method_exists(
    &self,
    method_name: Ident,
    self_ty: Ty<'tcx>,
    call_expr_id: HirId,
    allow_private: bool
) -> bool
[src]

Determines whether the type self_ty supports a method name method_name or not.

pub(crate) fn suggest_method_call(
    &self,
    err: &mut DiagnosticBuilder<'a>,
    msg: &str,
    method_name: Ident,
    self_ty: Ty<'tcx>,
    call_expr: &Expr<'_>
)
[src]

Adds a suggestion to call the given method to the provided diagnostic.

pub fn lookup_method(
    &self,
    self_ty: Ty<'tcx>,
    segment: &PathSegment<'_>,
    span: Span,
    call_expr: &'tcx Expr<'tcx>,
    self_expr: &'tcx Expr<'tcx>
) -> Result<MethodCallee<'tcx>, MethodError<'tcx>>
[src]

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

  • self: the surrounding FnCtxt (!)
  • self_ty: the (unadjusted) type of the self expression (foo)
  • segment: the name and generic arguments of the method (bar::<T1, ...Tn>)
  • span: the span for the method call
  • call_expr: the complete method call: (foo.bar::<T1,...Tn>(...))
  • self_expr: the self expression (foo)

pub fn lookup_probe(
    &self,
    span: Span,
    method_name: Ident,
    self_ty: Ty<'tcx>,
    call_expr: &'tcx Expr<'tcx>,
    scope: ProbeScope
) -> PickResult<'tcx>
[src]

pub fn lookup_method_in_trait(
    &self,
    span: Span,
    m_name: Ident,
    trait_def_id: DefId,
    self_ty: Ty<'tcx>,
    opt_input_types: Option<&[Ty<'tcx>]>
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>>
[src]

lookup_method_in_trait 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 a particular trait with the given self type and checks whether that trait is implemented.

pub fn resolve_ufcs(
    &self,
    span: Span,
    method_name: Ident,
    self_ty: Ty<'tcx>,
    expr_id: HirId
) -> Result<(DefKind, DefId), MethodError<'tcx>>
[src]

pub fn associated_item(
    &self,
    def_id: DefId,
    item_name: Ident,
    ns: Namespace
) -> Option<AssocItem>
[src]

Finds 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, 'tcx> FnCtxt<'a, 'tcx>[src]

pub fn check_binop_assign(
    &self,
    expr: &'tcx Expr<'tcx>,
    op: BinOp,
    lhs: &'tcx Expr<'tcx>,
    rhs: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

Checks a a <op>= b

pub fn check_binop(
    &self,
    expr: &'tcx Expr<'tcx>,
    op: BinOp,
    lhs_expr: &'tcx Expr<'tcx>,
    rhs_expr: &'tcx Expr<'tcx>
) -> Ty<'tcx>
[src]

Checks a potentially overloaded binary operator.

pub(in check::op) fn enforce_builtin_binop_types(
    &self,
    lhs_span: &Span,
    lhs_ty: Ty<'tcx>,
    rhs_span: &Span,
    rhs_ty: Ty<'tcx>,
    op: BinOp
) -> Ty<'tcx>
[src]

pub(in check::op) fn check_overloaded_binop(
    &self,
    expr: &'tcx Expr<'tcx>,
    lhs_expr: &'tcx Expr<'tcx>,
    rhs_expr: &'tcx Expr<'tcx>,
    op: BinOp,
    is_assign: IsAssign
) -> (Ty<'tcx>, Ty<'tcx>, Ty<'tcx>)
[src]

pub(in check::op) fn add_type_neq_err_label(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    span: Span,
    ty: Ty<'tcx>,
    other_ty: Ty<'tcx>,
    op: BinOp,
    is_assign: IsAssign
) -> bool
[src]

If one of the types is an uncalled function and calling it would yield the other type, suggest calling the function. Returns true if suggestion would apply (even if not given).

pub(in check::op) fn check_str_addition(
    &self,
    lhs_expr: &'tcx Expr<'tcx>,
    rhs_expr: &'tcx Expr<'tcx>,
    lhs_ty: Ty<'tcx>,
    rhs_ty: Ty<'tcx>,
    err: &mut DiagnosticBuilder<'_>,
    is_assign: IsAssign,
    op: BinOp
) -> bool
[src]

Provide actionable suggestions when trying to add two strings with incorrect types, like &str + &str, String + String and &str + &String.

If this function returns true it means a note was printed, so we don't need to print the normal "implementation of std::ops::Add might be missing" note

pub fn check_user_unop(
    &self,
    ex: &'tcx Expr<'tcx>,
    operand_ty: Ty<'tcx>,
    op: UnOp
) -> Ty<'tcx>
[src]

pub(in check::op) fn lookup_op_method(
    &self,
    lhs_ty: Ty<'tcx>,
    other_tys: &[Ty<'tcx>],
    op: Op
) -> Result<MethodCallee<'tcx>, ()>
[src]

impl<'tcx, '_> FnCtxt<'_, 'tcx>[src]

pub(in check::pat) fn pattern_cause(
    &self,
    ti: TopInfo<'tcx>,
    cause_span: Span
) -> ObligationCause<'tcx>
[src]

pub(in check::pat) fn demand_eqtype_pat_diag(
    &self,
    cause_span: Span,
    expected: Ty<'tcx>,
    actual: Ty<'tcx>,
    ti: TopInfo<'tcx>
) -> Option<DiagnosticBuilder<'tcx>>
[src]

pub(in check::pat) fn demand_eqtype_pat(
    &self,
    cause_span: Span,
    expected: Ty<'tcx>,
    actual: Ty<'tcx>,
    ti: TopInfo<'tcx>
)
[src]

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

pub fn check_pat_top(
    &self,
    pat: &'tcx Pat<'tcx>,
    expected: Ty<'tcx>,
    span: Option<Span>,
    origin_expr: bool
)
[src]

Type check the given top level pattern against the expected type.

If a Some(span) is provided and origin_expr holds, then the span represents the scrutinee's span. The scrutinee is found in e.g. match scrutinee { ... } and let pat = scrutinee;.

Otherwise, Some(span) represents the span of a type expression which originated the expected type.

pub(in check::pat) fn check_pat(
    &self,
    pat: &'tcx Pat<'tcx>,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
)
[src]

Type check the given pat against the expected type with the provided def_bm (default binding mode).

Outside of this module, check_pat_top should always be used. Conversely, inside this module, check_pat_top should never be used.

pub(in check::pat) fn calc_default_binding_mode(
    &self,
    pat: &'tcx Pat<'tcx>,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    adjust_mode: AdjustMode
) -> (Ty<'tcx>, BindingMode)
[src]

Compute the new expected type and default binding mode from the old ones as well as the pattern form we are currently checking.

pub(in check::pat) fn calc_adjust_mode(
    &self,
    pat: &'tcx Pat<'tcx>,
    opt_path_res: Option<Res>
) -> AdjustMode
[src]

How should the binding mode and expected type be adjusted?

When the pattern is a path pattern, opt_path_res must be Some(res).

pub(in check::pat) fn peel_off_references(
    &self,
    pat: &'tcx Pat<'tcx>,
    expected: Ty<'tcx>,
    def_bm: BindingMode
) -> (Ty<'tcx>, BindingMode)
[src]

Peel off as many immediately nested & mut? from the expected type as possible and return the new expected type and binding default binding mode. The adjustments vector, if non-empty is stored in a table.

pub(in check::pat) fn check_pat_lit(
    &self,
    span: Span,
    lt: &Expr<'tcx>,
    expected: Ty<'tcx>,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn check_pat_range(
    &self,
    span: Span,
    lhs: Option<&'tcx Expr<'tcx>>,
    rhs: Option<&'tcx Expr<'tcx>>,
    expected: Ty<'tcx>,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn endpoint_has_type(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    span: Span,
    ty: Ty<'_>
)
[src]

pub(in check::pat) fn emit_err_pat_range(
    &self,
    span: Span,
    lhs: Option<(bool, Ty<'tcx>, Span)>,
    rhs: Option<(bool, Ty<'tcx>, Span)>
)
[src]

pub(in check::pat) fn check_pat_ident(
    &self,
    pat: &'tcx Pat<'tcx>,
    ba: BindingAnnotation,
    var_id: HirId,
    sub: Option<&'tcx Pat<'tcx>>,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn check_binding_alt_eq_ty(
    &self,
    span: Span,
    var_id: HirId,
    ty: Ty<'tcx>,
    ti: TopInfo<'tcx>
)
[src]

pub(in check::pat) fn borrow_pat_suggestion(
    &self,
    err: &mut DiagnosticBuilder<'_>,
    pat: &Pat<'_>,
    inner: &Pat<'_>,
    expected: Ty<'tcx>
)
[src]

pub fn check_dereferenceable(
    &self,
    span: Span,
    expected: Ty<'tcx>,
    inner: &Pat<'_>
) -> bool
[src]

pub(in check::pat) fn check_pat_struct(
    &self,
    pat: &'tcx Pat<'tcx>,
    qpath: &QPath<'_>,
    fields: &'tcx [FieldPat<'tcx>],
    etc: bool,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn check_pat_path<'b>(
    &self,
    pat: &Pat<'_>,
    path_resolution: (Res, Option<Ty<'tcx>>, &'b [PathSegment<'b>]),
    expected: Ty<'tcx>,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn maybe_suggest_range_literal(
    &self,
    e: &mut DiagnosticBuilder<'_>,
    opt_def_id: Option<DefId>,
    ident: Ident
) -> bool
[src]

pub(in check::pat) fn emit_bad_pat_path<'b>(
    &self,
    e: DiagnosticBuilder<'_>,
    pat_span: Span,
    res: Res,
    pat_res: Res,
    pat_ty: Ty<'tcx>,
    segments: &'b [PathSegment<'b>],
    parent_pat: Option<&Pat<'_>>
)
[src]

pub(in check::pat) fn check_pat_tuple_struct(
    &self,
    pat: &'tcx Pat<'tcx>,
    qpath: &QPath<'_>,
    subpats: &'tcx [&'tcx Pat<'tcx>],
    ddpos: Option<usize>,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn e0023(
    &self,
    pat_span: Span,
    res: Res,
    qpath: &QPath<'_>,
    subpats: &'tcx [&'tcx Pat<'tcx>],
    fields: &'tcx [FieldDef],
    expected: Ty<'tcx>,
    had_err: bool
)
[src]

pub(in check::pat) fn check_pat_tuple(
    &self,
    span: Span,
    elements: &'tcx [&'tcx Pat<'tcx>],
    ddpos: Option<usize>,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn check_struct_pat_fields(
    &self,
    adt_ty: Ty<'tcx>,
    pat: &'tcx Pat<'tcx>,
    variant: &'tcx VariantDef,
    fields: &'tcx [FieldPat<'tcx>],
    etc: bool,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> bool
[src]

pub(in check::pat) fn error_foreign_non_exhaustive_spat(
    &self,
    pat: &Pat<'_>,
    descr: &str,
    no_fields: bool
)
[src]

pub(in check::pat) fn error_field_already_bound(
    &self,
    span: Span,
    ident: Ident,
    other_field: Span
)
[src]

pub(in check::pat) fn error_inexistent_fields(
    &self,
    kind_name: &str,
    inexistent_fields: &[Ident],
    unmentioned_fields: &mut Vec<(&FieldDef, Ident)>,
    variant: &VariantDef
) -> DiagnosticBuilder<'tcx>
[src]

pub(in check::pat) fn error_tuple_variant_as_struct_pat(
    &self,
    pat: &Pat<'_>,
    fields: &'tcx [FieldPat<'tcx>],
    variant: &VariantDef
) -> Option<DiagnosticBuilder<'tcx>>
[src]

pub(in check::pat) fn error_no_accessible_fields(
    &self,
    pat: &Pat<'_>,
    fields: &'tcx [FieldPat<'tcx>]
) -> DiagnosticBuilder<'tcx>
[src]

Returns a diagnostic reporting a struct pattern which is missing an .. due to inaccessible fields.

error: pattern requires `..` due to inaccessible fields
  --> src/main.rs:10:9
   |
LL |     let foo::Foo {} = foo::Foo::default();
   |         ^^^^^^^^^^^
   |
help: add a `..`
   |
LL |     let foo::Foo { .. } = foo::Foo::default();
   |                  ^^^^^^

pub(in check::pat) fn error_unmentioned_fields(
    &self,
    pat: &Pat<'_>,
    unmentioned_fields: &[(&FieldDef, Ident)],
    fields: &'tcx [FieldPat<'tcx>]
) -> DiagnosticBuilder<'tcx>
[src]

Returns a diagnostic reporting a struct pattern which does not mention some fields.

error[E0027]: pattern does not mention field `you_cant_use_this_field`
  --> src/main.rs:15:9
   |
LL |     let foo::Foo {} = foo::Foo::new();
   |         ^^^^^^^^^^^ missing field `you_cant_use_this_field`

pub(in check::pat) fn check_pat_box(
    &self,
    span: Span,
    inner: &'tcx Pat<'tcx>,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn check_pat_ref(
    &self,
    pat: &'tcx Pat<'tcx>,
    inner: &'tcx Pat<'tcx>,
    mutbl: Mutability,
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

pub(in check::pat) fn new_ref_ty(
    &self,
    span: Span,
    mutbl: Mutability,
    ty: Ty<'tcx>
) -> Ty<'tcx>
[src]

Create a reference type with a fresh region variable.

pub(in check::pat) fn check_pat_slice(
    &self,
    span: Span,
    before: &'tcx [&'tcx Pat<'tcx>],
    slice: Option<&'tcx Pat<'tcx>>,
    after: &'tcx [&'tcx Pat<'tcx>],
    expected: Ty<'tcx>,
    def_bm: BindingMode,
    ti: TopInfo<'tcx>
) -> Ty<'tcx>
[src]

Type check a slice pattern.

Syntactically, these look like [pat_0, ..., pat_n]. Semantically, we are type checking a pattern with structure:

[before_0, ..., before_n, (slice, after_0, ... after_n)?]

The type of slice, if it is present, depends on the expected type. If slice is missing, then so is after_i. If slice is present, it can still represent 0 elements.

pub(in check::pat) fn check_array_pat_len(
    &self,
    span: Span,
    element_ty: Ty<'tcx>,
    arr_ty: Ty<'tcx>,
    slice: Option<&'tcx Pat<'tcx>>,
    len: &Const<'tcx>,
    min_len: u64
) -> (Option<Ty<'tcx>>, Ty<'tcx>)
[src]

Type check the length of an array pattern.

Returns both the type of the variable length pattern (or None), and the potentially inferred array type. We only return None for the slice type if slice.is_none().

pub(in check::pat) fn error_scrutinee_inconsistent_length(
    &self,
    span: Span,
    min_len: u64,
    size: u64
)
[src]

pub(in check::pat) fn error_scrutinee_with_rest_inconsistent_length(
    &self,
    span: Span,
    min_len: u64,
    size: u64
)
[src]

pub(in check::pat) fn error_scrutinee_unfixed_length(
    &self,
    span: Span
)
[src]

pub(in check::pat) fn error_expected_array_or_slice(
    &self,
    span: Span,
    expected_ty: Ty<'tcx>
)
[src]

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

pub(in check) fn lookup_derefing(
    &self,
    expr: &Expr<'_>,
    oprnd_expr: &'tcx Expr<'tcx>,
    oprnd_ty: Ty<'tcx>
) -> Option<Ty<'tcx>>
[src]

Type-check *oprnd_expr with oprnd_expr type-checked already.

pub(in check) fn lookup_indexing(
    &self,
    expr: &Expr<'_>,
    base_expr: &'tcx Expr<'tcx>,
    base_ty: Ty<'tcx>,
    idx_ty: Ty<'tcx>
) -> Option<(Ty<'tcx>, Ty<'tcx>)>
[src]

Type-check *base_expr[index_expr] with base_expr and index_expr type-checked already.

pub(in check::place_op) fn try_index_step(
    &self,
    expr: &Expr<'_>,
    base_expr: &Expr<'_>,
    autoderef: &Autoderef<'a, 'tcx>,
    index_ty: Ty<'tcx>
) -> Option<(Ty<'tcx>, Ty<'tcx>)>
[src]

To type-check base_expr[index_expr], we progressively autoderef (and otherwise adjust) base_expr, looking for a type which either supports builtin indexing or overloaded indexing. This loop implements one step in that search; the autoderef loop is implemented by lookup_indexing.

pub(in check) fn try_overloaded_place_op(
    &self,
    span: Span,
    base_ty: Ty<'tcx>,
    arg_tys: &[Ty<'tcx>],
    op: PlaceOp
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>>
[src]

Try to resolve an overloaded place op. We only deal with the immutable variant here (Deref/Index). In some contexts we would need the mutable variant (DerefMut/IndexMut); those would be later converted by convert_place_derefs_to_mutable.

pub(in check::place_op) fn try_mutable_overloaded_place_op(
    &self,
    span: Span,
    base_ty: Ty<'tcx>,
    arg_tys: &[Ty<'tcx>],
    op: PlaceOp
) -> Option<InferOk<'tcx, MethodCallee<'tcx>>>
[src]

pub fn convert_place_derefs_to_mutable(&self, expr: &Expr<'_>)[src]

Convert auto-derefs, indices, etc of an expression from Deref and Index into DerefMut and IndexMut respectively.

This is a second pass of typechecking derefs/indices. We need this because we do not always know whether a place needs to be mutable or not in the first pass. This happens whether there is an implicit mutable reborrow, e.g. when the type is used as the receiver of a method call.

pub(in check::place_op) fn convert_place_op_to_mutable(
    &self,
    op: PlaceOp,
    expr: &Expr<'_>,
    base_expr: &Expr<'_>
)
[src]

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

pub fn regionck_expr(&self, body: &'tcx Body<'tcx>)[src]

pub fn regionck_item(&self, item_id: HirId, span: Span, wf_tys: &[Ty<'tcx>])[src]

Region checking during the WF phase for items. wf_tys are the types from which we should derive implied bounds, if any.

pub fn regionck_fn(&self, fn_id: HirId, body: &'tcx Body<'tcx>)[src]

Region check a function body. Not invoked on closures, but only on the "root" fn item (in which closures may be embedded). Walks the function body and adds various add'l constraints that are needed for region inference. This is separated both to isolate "pure" region constraints from the rest of type check and because sometimes we need type inference to have completed before we can determine which constraints to add.

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

pub fn closure_analyze(&self, body: &'tcx Body<'tcx>)[src]

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

pub(in check::upvar) fn analyze_closure(
    &self,
    closure_hir_id: HirId,
    span: Span,
    body: &Body<'_>,
    capture_clause: CaptureBy
)
[src]

Analysis starting point.

pub(in check::upvar) fn final_upvar_tys(
    &self,
    closure_id: HirId
) -> Vec<Ty<'tcx>>
[src]

pub(in check::upvar) fn min_captures_to_closure_captures_bridge(
    &self,
    closure_def_id: DefId
)
[src]

Bridge for closure analysis

For closure with DefId c, the bridge converts structures required for supporting RFC 2229, to structures currently used in the compiler for handling closure captures.

For example the following structure will be converted:

closure_min_captures foo -> [ {foo.x, ImmBorrow}, {foo.y, MutBorrow} ] bar -> [ {bar.z, ByValue}, {bar.q, MutBorrow} ]

to

  1. closure_captures foo -> UpvarId(foo, c), bar -> UpvarId(bar, c)

  2. upvar_capture_map UpvarId(foo,c) -> MutBorrow, UpvarId(bar, c) -> ByValue

pub(in check::upvar) fn compute_min_captures(
    &self,
    closure_def_id: DefId,
    inferred_info: InferBorrowKind<'_, 'tcx>
)
[src]

Analyzes the information collected by InferBorrowKind to compute the min number of Places (and corresponding capture kind) that we need to keep track of to support all the required captured paths.

Eg:

struct Point { x: i32, y: i32 }

let s: String;  // hir_id_s
let mut p: Point; // his_id_p
let c = || {
       println!("{}", s);  // L1
       p.x += 10;  // L2
       println!("{}" , p.y) // L3
       println!("{}", p) // L4
       drop(s);   // L5
};

and let hir_id_L1..5 be the expressions pointing to use of a captured variable on the lines L1..5 respectively.

InferBorrowKind results in a structure like this:

{
      Place(base: hir_id_s, projections: [], ....) -> (hir_id_L5, ByValue),
      Place(base: hir_id_p, projections: [Field(0, 0)], ...) -> (hir_id_L2, ByRef(MutBorrow))
      Place(base: hir_id_p, projections: [Field(1, 0)], ...) -> (hir_id_L3, ByRef(ImmutBorrow))
      Place(base: hir_id_p, projections: [], ...) -> (hir_id_L4, ByRef(ImmutBorrow))

After the min capture analysis, we get:

{
      hir_id_s -> [
           Place(base: hir_id_s, projections: [], ....) -> (hir_id_L4, ByValue)
      ],
      hir_id_p -> [
           Place(base: hir_id_p, projections: [], ...) -> (hir_id_L2, ByRef(MutBorrow)),
      ],

pub(in check::upvar) fn init_capture_kind(
    &self,
    capture_clause: CaptureBy,
    upvar_id: UpvarId,
    closure_span: Span
) -> UpvarCapture<'tcx>
[src]

pub(in check::upvar) fn place_for_root_variable(
    &self,
    closure_def_id: LocalDefId,
    var_hir_id: HirId
) -> Place<'tcx>
[src]

pub(in check::upvar) fn should_log_capture_analysis(
    &self,
    closure_def_id: DefId
) -> bool
[src]

pub(in check::upvar) fn log_capture_analysis_first_pass(
    &self,
    closure_def_id: DefId,
    capture_information: &FxIndexMap<Place<'tcx>, CaptureInfo<'tcx>>,
    closure_span: Span
)
[src]

pub(in check::upvar) fn log_closure_min_capture_info(
    &self,
    closure_def_id: DefId,
    closure_span: Span
)
[src]

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

pub(in check::wfcheck) fn non_enum_variant(
    &self,
    struct_def: &VariantData<'_>
) -> AdtVariant<'tcx>
[src]

pub(in check::wfcheck) fn enum_variants(
    &self,
    enum_def: &EnumDef<'_>
) -> Vec<AdtVariant<'tcx>>
[src]

pub(in check) fn impl_implied_bounds(
    &self,
    impl_def_id: DefId,
    span: Span
) -> Vec<Ty<'tcx>>
[src]

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

pub fn resolve_type_vars_in_body(
    &self,
    body: &'tcx Body<'tcx>
) -> &'tcx TypeckResults<'tcx>
[src]

Methods from Deref<Target = Inherited<'a, 'tcx>>

pub(in check) fn register_predicate(
    &self,
    obligation: PredicateObligation<'tcx>
)
[src]

pub(in check) fn register_predicates<I>(
    &self,
    obligations: I
) where
    I: IntoIterator<Item = PredicateObligation<'tcx>>, 
[src]

pub(in check) fn register_infer_ok_obligations<T>(
    &self,
    infer_ok: InferOk<'tcx, T>
) -> T
[src]

pub(in check) fn normalize_associated_types_in<T>(
    &self,
    span: Span,
    body_id: HirId,
    param_env: ParamEnv<'tcx>,
    value: T
) -> T where
    T: TypeFoldable<'tcx>, 
[src]

Trait Implementations

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

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

type Target = Inherited<'a, 'tcx>

The resulting type after dereferencing.

Auto Trait Implementations

impl<'a, 'tcx> !RefUnwindSafe for FnCtxt<'a, 'tcx>

impl<'a, 'tcx> !Send for FnCtxt<'a, 'tcx>

impl<'a, 'tcx> !Sync for FnCtxt<'a, 'tcx>

impl<'a, 'tcx> Unpin for FnCtxt<'a, 'tcx> where
    'tcx: 'a, 

impl<'a, 'tcx> !UnwindSafe for FnCtxt<'a, 'tcx>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized, 
[src]

impl<T> Borrow<T> for T where
    T: ?Sized, 
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized, 
[src]

impl<'a, T> Captures<'a> for T where
    T: ?Sized, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<T> WithConstness for T[src]