Type Alias rustc_hir_typeck::coercion::DynamicCoerceMany
source · pub type DynamicCoerceMany<'tcx> = CoerceMany<'tcx, 'tcx, &'tcx Expr<'tcx>>;
Expand description
The type of a CoerceMany
that is storing up the expressions into
a buffer. We use this in check/mod.rs
for things like break
.
Aliased Type§
struct DynamicCoerceMany<'tcx> {
expected_ty: Ty<'tcx>,
final_ty: Option<Ty<'tcx>>,
expressions: Expressions<'tcx, 'tcx, &'tcx Expr<'tcx>>,
pushed: usize,
}
Fields§
§expected_ty: Ty<'tcx>
§final_ty: Option<Ty<'tcx>>
§expressions: Expressions<'tcx, 'tcx, &'tcx Expr<'tcx>>
§pushed: usize
Implementations§
source§impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E>
impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E>
sourcepub fn new(expected_ty: Ty<'tcx>) -> Self
pub fn new(expected_ty: Ty<'tcx>) -> Self
The usual case; collect the set of expressions dynamically.
If the full set of coercion sites is known before hand,
consider with_coercion_sites()
instead to avoid allocation.
sourcepub fn with_coercion_sites(
expected_ty: Ty<'tcx>,
coercion_sites: &'exprs [E]
) -> Self
pub fn with_coercion_sites( expected_ty: Ty<'tcx>, coercion_sites: &'exprs [E] ) -> Self
As an optimization, you can create a CoerceMany
with a
preexisting slice of expressions. In this case, you are
expected to pass each element in the slice to coerce(...)
in
order. This is used with arrays in particular to avoid
needlessly cloning the slice.
fn make( expected_ty: Ty<'tcx>, expressions: Expressions<'tcx, 'exprs, E> ) -> Self
sourcepub fn expected_ty(&self) -> Ty<'tcx>
pub fn expected_ty(&self) -> Ty<'tcx>
Returns the “expected type” with which this coercion was constructed. This represents the “downward propagated” type that was given to us at the start of typing whatever construct we are typing (e.g., the match expression).
Typically, this is used as the expected type when type-checking each of the alternative expressions whose types we are trying to merge.
sourcepub fn merged_ty(&self) -> Ty<'tcx>
pub fn merged_ty(&self) -> Ty<'tcx>
Returns the current “merged type”, representing our best-guess
at the LUB of the expressions we’ve seen so far (if any). This
isn’t final until you call self.complete()
, which will return
the merged type.
sourcepub fn coerce<'a>(
&mut self,
fcx: &FnCtxt<'a, 'tcx>,
cause: &ObligationCause<'tcx>,
expression: &'tcx Expr<'tcx>,
expression_ty: Ty<'tcx>
)
pub fn coerce<'a>( &mut self, fcx: &FnCtxt<'a, 'tcx>, cause: &ObligationCause<'tcx>, expression: &'tcx Expr<'tcx>, expression_ty: Ty<'tcx> )
Indicates that the value generated by expression
, which is
of type expression_ty
, is one of the possibilities that we
could coerce from. This will record expression
, and later
calls to coerce
may come back and add adjustments and things
if necessary.
sourcepub fn coerce_forced_unit<'a>(
&mut self,
fcx: &FnCtxt<'a, 'tcx>,
cause: &ObligationCause<'tcx>,
augment_error: impl FnOnce(&mut Diagnostic),
label_unit_as_expected: bool
)
pub fn coerce_forced_unit<'a>( &mut self, fcx: &FnCtxt<'a, 'tcx>, cause: &ObligationCause<'tcx>, augment_error: impl FnOnce(&mut Diagnostic), label_unit_as_expected: bool )
Indicates that one of the inputs is a “forced unit”. This
occurs in a case like if foo { ... };
, where the missing else
generates a “forced unit”. Another example is a loop { break; }
, where the break
has no argument expression. We treat
these cases slightly differently for error-reporting
purposes. Note that these tend to correspond to cases where
the ()
expression is implicit in the source, and hence we do
not take an expression argument.
The augment_error
gives you a chance to extend the error
message, in case any results (e.g., we use this to suggest
removing a ;
).
sourcepub(crate) fn coerce_inner<'a>(
&mut self,
fcx: &FnCtxt<'a, 'tcx>,
cause: &ObligationCause<'tcx>,
expression: Option<&'tcx Expr<'tcx>>,
expression_ty: Ty<'tcx>,
augment_error: impl FnOnce(&mut Diagnostic),
label_expression_as_expected: bool
)
pub(crate) fn coerce_inner<'a>( &mut self, fcx: &FnCtxt<'a, 'tcx>, cause: &ObligationCause<'tcx>, expression: Option<&'tcx Expr<'tcx>>, expression_ty: Ty<'tcx>, augment_error: impl FnOnce(&mut Diagnostic), label_expression_as_expected: bool )
The inner coercion “engine”. If expression
is None
, this
is a forced-unit case, and hence expression_ty
must be
Nil
.
fn note_unreachable_loop_return( &self, err: &mut Diagnostic, expr: &Expr<'tcx>, ret_exprs: &Vec<&'tcx Expr<'tcx>> )
fn report_return_mismatched_types<'a>( &self, cause: &ObligationCause<'tcx>, expected: Ty<'tcx>, found: Ty<'tcx>, ty_err: TypeError<'tcx>, fcx: &FnCtxt<'a, 'tcx>, id: HirId, expression: Option<&'tcx Expr<'tcx>>, blk_id: Option<HirId> ) -> DiagnosticBuilder<'a, ErrorGuaranteed>
sourcefn is_return_ty_definitely_unsized(&self, fcx: &FnCtxt<'_, 'tcx>) -> bool
fn is_return_ty_definitely_unsized(&self, fcx: &FnCtxt<'_, 'tcx>) -> bool
Checks whether the return type is unsized via an obligation, which makes
sure we consider dyn Trait: Sized
where clauses, which are trivially
false but technically valid for typeck.
pub fn complete<'a>(self, fcx: &FnCtxt<'a, 'tcx>) -> Ty<'tcx>
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 48 bytes