struct TypeChecker<'a, 'tcx> {Show 16 fields
root_cx: &'a mut BorrowCheckRootCtxt<'tcx>,
infcx: &'a BorrowckInferCtxt<'tcx>,
last_span: Span,
body: &'a Body<'tcx>,
promoted: &'a IndexSlice<Promoted, Body<'tcx>>,
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>,
region_bound_pairs: &'a RegionBoundPairs<'tcx>,
known_type_outlives_obligations: &'a [PolyTypeOutlivesPredicate<'tcx>],
reported_errors: FxIndexSet<(Ty<'tcx>, Span)>,
universal_regions: &'a UniversalRegions<'tcx>,
location_table: &'a PoloniusLocationTable,
polonius_facts: &'a mut Option<PoloniusFacts>,
borrow_set: &'a BorrowSet<'tcx>,
constraints: &'a mut MirTypeckRegionConstraints<'tcx>,
deferred_closure_requirements: &'a mut Vec<(LocalDefId, GenericArgsRef<'tcx>, Locations)>,
polonius_liveness: Option<PoloniusLivenessContext>,
}Expand description
The MIR type checker. Visits the MIR and enforces all the constraints needed for it to be valid and well-typed. Along the way, it accrues region constraints – these can later be used by NLL region checking.
Fields§
§root_cx: &'a mut BorrowCheckRootCtxt<'tcx>§infcx: &'a BorrowckInferCtxt<'tcx>§last_span: Span§body: &'a Body<'tcx>§promoted: &'a IndexSlice<Promoted, Body<'tcx>>The bodies of all promoteds. As promoteds have a completely separate CFG recursing into them may corrupt your data structures if you’re not careful.
user_type_annotations: &'a CanonicalUserTypeAnnotations<'tcx>User type annotations are shared between the main MIR and the MIR of all of the promoted items.
region_bound_pairs: &'a RegionBoundPairs<'tcx>§known_type_outlives_obligations: &'a [PolyTypeOutlivesPredicate<'tcx>]§reported_errors: FxIndexSet<(Ty<'tcx>, Span)>§universal_regions: &'a UniversalRegions<'tcx>§location_table: &'a PoloniusLocationTable§polonius_facts: &'a mut Option<PoloniusFacts>§borrow_set: &'a BorrowSet<'tcx>§constraints: &'a mut MirTypeckRegionConstraints<'tcx>§deferred_closure_requirements: &'a mut Vec<(LocalDefId, GenericArgsRef<'tcx>, Locations)>§polonius_liveness: Option<PoloniusLivenessContext>When using -Zpolonius=next, the liveness helper data used to create polonius constraints.
Implementations§
Source§impl<'a, 'tcx> TypeChecker<'a, 'tcx>
impl<'a, 'tcx> TypeChecker<'a, 'tcx>
Sourcepub(super) fn fully_perform_op<R: Debug, Op>(
&mut self,
locations: Locations,
category: ConstraintCategory<'tcx>,
op: Op,
) -> Result<R, ErrorGuaranteed>where
Op: TypeOp<'tcx, Output = R>,
Op::ErrorInfo: ToUniverseInfo<'tcx>,
pub(super) fn fully_perform_op<R: Debug, Op>(
&mut self,
locations: Locations,
category: ConstraintCategory<'tcx>,
op: Op,
) -> Result<R, ErrorGuaranteed>where
Op: TypeOp<'tcx, Output = R>,
Op::ErrorInfo: ToUniverseInfo<'tcx>,
Given some operation op that manipulates types, proves
predicates, or otherwise uses the inference context, executes
op and then executes all the further obligations that op
returns. This will yield a set of outlives constraints amongst
regions which are extracted and stored as having occurred at
locations.
Any rustc_infer::infer operations that might generate region
constraints should occur within this method so that those
constraints can be properly localized!
pub(super) fn instantiate_canonical<T>(
&mut self,
span: Span,
canonical: &Canonical<'tcx, T>,
) -> Twhere
T: TypeFoldable<TyCtxt<'tcx>>,
pub(super) fn prove_trait_ref( &mut self, trait_ref: TraitRef<'tcx>, locations: Locations, category: ConstraintCategory<'tcx>, )
pub(super) fn normalize_and_prove_instantiated_predicates( &mut self, _def_id: DefId, instantiated_predicates: InstantiatedPredicates<'tcx>, locations: Locations, )
pub(super) fn prove_predicates( &mut self, predicates: impl IntoIterator<Item: Upcast<TyCtxt<'tcx>, Predicate<'tcx>> + Debug>, locations: Locations, category: ConstraintCategory<'tcx>, )
pub(super) fn prove_predicate( &mut self, predicate: impl Upcast<TyCtxt<'tcx>, Predicate<'tcx>> + Debug, locations: Locations, category: ConstraintCategory<'tcx>, )
pub(super) fn normalize<T>( &mut self, value: T, location: impl NormalizeLocation, ) -> T
pub(super) fn deeply_normalize<T>( &mut self, value: T, location: impl NormalizeLocation, ) -> T
pub(super) fn normalize_with_category<T>( &mut self, value: T, location: impl NormalizeLocation, category: ConstraintCategory<'tcx>, ) -> T
pub(super) fn struct_tail( &mut self, ty: Ty<'tcx>, location: impl NormalizeLocation, ) -> Ty<'tcx>
pub(super) fn structurally_resolve( &mut self, ty: Ty<'tcx>, location: impl NormalizeLocation, ) -> Ty<'tcx>
pub(super) fn ascribe_user_type( &mut self, mir_ty: Ty<'tcx>, user_ty: UserType<'tcx>, span: Span, )
Sourcepub(super) fn ascribe_user_type_skip_wf(
&mut self,
mir_ty: Ty<'tcx>,
user_ty: UserType<'tcx>,
span: Span,
)
pub(super) fn ascribe_user_type_skip_wf( &mut self, mir_ty: Ty<'tcx>, user_ty: UserType<'tcx>, span: Span, )
Incorrectly skips the WF checks we normally do in ascribe_user_type.
FIXME(#104478, #104477): This is a hack for backward-compatibility.
Source§impl<'a, 'tcx> TypeChecker<'a, 'tcx>
impl<'a, 'tcx> TypeChecker<'a, 'tcx>
Sourcepub(super) fn check_signature_annotation(&mut self)
pub(super) fn check_signature_annotation(&mut self)
Check explicit closure signature annotation,
e.g., |x: FxIndexMap<_, &'static u32>| ....
Sourcepub(super) fn equate_inputs_and_outputs(
&mut self,
normalized_inputs_and_output: &[Ty<'tcx>],
)
pub(super) fn equate_inputs_and_outputs( &mut self, normalized_inputs_and_output: &[Ty<'tcx>], )
Enforce that the types of the locals corresponding to the inputs and output of the body are equal to those of the (normalized) signature.
This is necessary for two reasons:
-
Locals in the MIR all start out with
'erasedregions and then are replaced with unconstrained nll vars. If we have a function returning&'a u32then the local_0: &'?10 u32needs to have its region var equated with the nll var representing'a. i.e. borrow check must uphold that'?10 = 'a. -
When computing the normalized signature we may introduce new unconstrained nll vars due to higher ranked where clauses (#136547). We then wind up with implied bounds involving these vars.
For this reason it is important that we equate with the normalized signature which was produced when computing implied bounds. If we do not do so then we will wind up with implied bounds on nll vars which cannot actually be used as the nll var never gets related to anything.
For ‘closure-like’ bodies this function effectively relates the inferred signature
of the closure against the locals corresponding to the closure’s inputs/output. It does
not relate the user provided types for the signature to the locals, this is handled
separately by: TypeChecker::check_signature_annotation.
fn equate_normalized_input_or_output( &mut self, a: Ty<'tcx>, b: Ty<'tcx>, span: Span, )
Source§impl<'a, 'tcx> TypeChecker<'a, 'tcx>
impl<'a, 'tcx> TypeChecker<'a, 'tcx>
Sourcepub(super) fn relate_types(
&mut self,
a: Ty<'tcx>,
v: Variance,
b: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory<'tcx>,
) -> Result<(), NoSolution>
pub(super) fn relate_types( &mut self, a: Ty<'tcx>, v: Variance, b: Ty<'tcx>, locations: Locations, category: ConstraintCategory<'tcx>, ) -> Result<(), NoSolution>
Adds sufficient constraints to ensure that a R b where R depends on v:
- “Covariant”
a <: b - “Invariant”
a == b - “Contravariant”
a :> b
N.B., the type a is permitted to have unresolved inference
variables, but not the type b.
Sourcepub(super) fn eq_args(
&mut self,
a: GenericArgsRef<'tcx>,
b: GenericArgsRef<'tcx>,
locations: Locations,
category: ConstraintCategory<'tcx>,
) -> Result<(), NoSolution>
pub(super) fn eq_args( &mut self, a: GenericArgsRef<'tcx>, b: GenericArgsRef<'tcx>, locations: Locations, category: ConstraintCategory<'tcx>, ) -> Result<(), NoSolution>
Add sufficient constraints to ensure a == b. See also Self::relate_types.
Source§impl<'a, 'tcx> TypeChecker<'a, 'tcx>
impl<'a, 'tcx> TypeChecker<'a, 'tcx>
fn tcx(&self) -> TyCtxt<'tcx>
fn body(&self) -> &Body<'tcx>
fn unsized_feature_enabled(&self) -> bool
Sourcefn check_user_type_annotations(&mut self)
fn check_user_type_annotations(&mut self)
Equate the inferred type and the annotated type for user type annotations
fn push_region_constraints( &mut self, locations: Locations, category: ConstraintCategory<'tcx>, data: &QueryRegionConstraints<'tcx>, )
Sourcefn sub_types(
&mut self,
sub: Ty<'tcx>,
sup: Ty<'tcx>,
locations: Locations,
category: ConstraintCategory<'tcx>,
) -> Result<(), NoSolution>
fn sub_types( &mut self, sub: Ty<'tcx>, sup: Ty<'tcx>, locations: Locations, category: ConstraintCategory<'tcx>, ) -> Result<(), NoSolution>
Try to relate sub <: sup
fn eq_types( &mut self, expected: Ty<'tcx>, found: Ty<'tcx>, locations: Locations, category: ConstraintCategory<'tcx>, ) -> Result<(), NoSolution>
fn relate_type_and_user_type( &mut self, a: Ty<'tcx>, v: Variance, user_ty: &UserTypeProjection, locations: Locations, category: ConstraintCategory<'tcx>, ) -> Result<(), NoSolution>
fn check_promoted(&mut self, promoted_body: &'a Body<'tcx>, location: Location)
Source§impl<'a, 'tcx> TypeChecker<'a, 'tcx>
impl<'a, 'tcx> TypeChecker<'a, 'tcx>
fn check_call_dest( &mut self, term: &Terminator<'tcx>, sig: &FnSig<'tcx>, destination: Place<'tcx>, is_diverging: bool, term_location: Location, )
fn check_call_inputs( &mut self, term: &Terminator<'tcx>, func: &Operand<'tcx>, sig: &FnSig<'tcx>, args: &[Spanned<Operand<'tcx>>], term_location: Location, call_source: CallSource, )
fn check_iscleanup(&mut self, block_data: &BasicBlockData<'tcx>)
fn assert_iscleanup( &mut self, ctxt: &dyn Debug, bb: BasicBlock, iscleanuppad: bool, )
fn assert_iscleanup_unwind( &mut self, ctxt: &dyn Debug, unwind: UnwindAction, is_cleanup: bool, )
fn ensure_place_sized(&mut self, ty: Ty<'tcx>, span: Span)
fn aggregate_field_ty( &mut self, ak: &AggregateKind<'tcx>, field_index: FieldIdx, location: Location, ) -> Result<Ty<'tcx>, FieldAccessError>
Sourcefn rvalue_user_ty(
&self,
rvalue: &Rvalue<'tcx>,
) -> Option<UserTypeAnnotationIndex>
fn rvalue_user_ty( &self, rvalue: &Rvalue<'tcx>, ) -> Option<UserTypeAnnotationIndex>
If this rvalue supports a user-given type annotation, then extract and return it. This represents the final type of the rvalue and will be unified with the inferred type.
fn check_aggregate_rvalue( &mut self, rvalue: &Rvalue<'tcx>, aggregate_kind: &AggregateKind<'tcx>, operands: &IndexSlice<FieldIdx, Operand<'tcx>>, location: Location, )
Sourcefn add_reborrow_constraint(
&mut self,
location: Location,
borrow_region: Region<'tcx>,
borrowed_place: &Place<'tcx>,
)
fn add_reborrow_constraint( &mut self, location: Location, borrow_region: Region<'tcx>, borrowed_place: &Place<'tcx>, )
Adds the constraints that arise from a borrow expression &'a P at the location L.
§Parameters
location: the locationLwhere the borrow expression occursborrow_region: the region'aassociated with the borrowborrowed_place: the placePbeing borrowed
fn prove_aggregate_predicates( &mut self, aggregate_kind: &AggregateKind<'tcx>, location: Location, )
fn prove_closure_bounds( &mut self, tcx: TyCtxt<'tcx>, def_id: LocalDefId, args: GenericArgsRef<'tcx>, location: Location, ) -> InstantiatedPredicates<'tcx>
Trait Implementations§
Source§impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx>
fn visit_span(&mut self, span: Span)
fn visit_body(&mut self, body: &Body<'tcx>)
fn visit_statement(&mut self, stmt: &Statement<'tcx>, location: Location)
fn visit_terminator(&mut self, term: &Terminator<'tcx>, term_location: Location)
fn visit_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>)
fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location)
fn visit_operand(&mut self, op: &Operand<'tcx>, location: Location)
Source§fn visit_const_operand(
&mut self,
constant: &ConstOperand<'tcx>,
location: Location,
)
fn visit_const_operand( &mut self, constant: &ConstOperand<'tcx>, location: Location, )
required_consts
(i.e., including consts that have been dead-code-eliminated).fn visit_place( &mut self, place: &Place<'tcx>, context: PlaceContext, location: Location, )
fn visit_projection_elem( &mut self, place: PlaceRef<'tcx>, elem: PlaceElem<'tcx>, context: PlaceContext, location: Location, )
fn visit_basic_block_data( &mut self, block: BasicBlock, data: &BasicBlockData<'tcx>, )
fn visit_source_scope_data(&mut self, scope_data: &SourceScopeData<'tcx>)
fn visit_statement_debuginfo( &mut self, stmt_debuginfo: &StmtDebugInfo<'tcx>, location: Location, )
fn visit_assign( &mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location, )
fn visit_assert_message( &mut self, msg: &AssertKind<Operand<'tcx>>, location: Location, )
fn visit_ascribe_user_ty( &mut self, place: &Place<'tcx>, variance: Variance, user_ty: &UserTypeProjection, location: Location, )
fn visit_coverage(&mut self, kind: &CoverageKind, location: Location)
fn visit_retag( &mut self, kind: RetagKind, place: &Place<'tcx>, location: Location, )
fn visit_projection( &mut self, place_ref: PlaceRef<'tcx>, context: PlaceContext, location: Location, )
fn super_place( &mut self, place: &Place<'tcx>, context: PlaceContext, location: Location, )
fn super_projection( &mut self, place_ref: PlaceRef<'tcx>, context: PlaceContext, location: Location, )
fn super_projection_elem( &mut self, _place_ref: PlaceRef<'tcx>, elem: ProjectionElem<Local, Ty<'tcx>>, context: PlaceContext, location: Location, )
fn visit_ty_const(&mut self, ct: Const<'tcx>, location: Location)
fn visit_source_info(&mut self, source_info: &SourceInfo)
fn visit_ty(&mut self, ty: Ty<'tcx>, _: TyContext)
fn visit_user_type_projection(&mut self, ty: &UserTypeProjection)
fn visit_user_type_annotation( &mut self, index: UserTypeAnnotationIndex, ty: &CanonicalUserTypeAnnotation<'tcx>, )
fn visit_region(&mut self, region: Region<'tcx>, _: Location)
fn visit_args( &mut self, args: &&'tcx RawList<(), GenericArg<'tcx>>, _: Location, )
fn visit_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>)
fn visit_local( &mut self, local: Local, context: PlaceContext, location: Location, )
fn visit_source_scope(&mut self, scope: SourceScope)
fn super_body(&mut self, body: &Body<'tcx>)
fn super_basic_block_data( &mut self, block: BasicBlock, data: &BasicBlockData<'tcx>, )
fn super_source_scope_data(&mut self, scope_data: &SourceScopeData<'tcx>)
fn super_statement_debuginfo( &mut self, stmt_debuginfo: &StmtDebugInfo<'tcx>, location: Location, )
fn super_statement(&mut self, statement: &Statement<'tcx>, location: Location)
fn super_assign( &mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location, )
fn super_terminator( &mut self, terminator: &Terminator<'tcx>, location: Location, )
fn super_assert_message( &mut self, msg: &AssertKind<Operand<'tcx>>, location: Location, )
fn super_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location)
fn super_operand(&mut self, operand: &Operand<'tcx>, location: Location)
fn super_ascribe_user_ty( &mut self, place: &Place<'tcx>, variance: Variance, user_ty: &UserTypeProjection, location: Location, )
fn super_coverage(&mut self, _kind: &CoverageKind, _location: Location)
fn super_retag( &mut self, _kind: RetagKind, place: &Place<'tcx>, location: Location, )
fn super_local_decl(&mut self, local: Local, local_decl: &LocalDecl<'tcx>)
fn super_local( &mut self, _local: Local, _context: PlaceContext, _location: Location, )
fn super_var_debug_info(&mut self, var_debug_info: &VarDebugInfo<'tcx>)
fn super_source_scope(&mut self, _scope: SourceScope)
fn super_const_operand( &mut self, constant: &ConstOperand<'tcx>, location: Location, )
fn super_ty_const(&mut self, _ct: Const<'tcx>, _location: Location)
fn super_span(&mut self, _span: Span)
fn super_source_info(&mut self, source_info: &SourceInfo)
fn super_user_type_projection(&mut self, _ty: &UserTypeProjection)
fn super_user_type_annotation( &mut self, _index: UserTypeAnnotationIndex, ty: &CanonicalUserTypeAnnotation<'tcx>, )
fn super_ty(&mut self, _ty: Ty<'tcx>)
fn super_region(&mut self, _region: Region<'tcx>)
fn super_args(&mut self, _args: &&'tcx RawList<(), GenericArg<'tcx>>)
fn visit_location(&mut self, body: &Body<'tcx>, location: Location)
Auto Trait Implementations§
impl<'a, 'tcx> !DynSend for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> !DynSync for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> Freeze for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> !RefUnwindSafe for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> !Send for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> !Sync for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> Unpin for TypeChecker<'a, 'tcx>
impl<'a, 'tcx> !UnwindSafe for TypeChecker<'a, 'tcx>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T, R> CollectAndApply<T, R> for T
impl<T, R> CollectAndApply<T, R> for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<P> IntoQueryParam<P> for P
impl<P> IntoQueryParam<P> for P
fn into_query_param(self) -> P
Source§impl<T> MaybeResult<T> for T
impl<T> MaybeResult<T> for T
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
impl<I, T, U> Upcast<I, U> for Twhere
U: UpcastFrom<I, T>,
Source§impl<I, T> UpcastFrom<I, T> for T
impl<I, T> UpcastFrom<I, T> for T
fn upcast_from(from: T, _tcx: I) -> T
Source§impl<'tcx, T> Value<'tcx> for T
impl<'tcx, T> Value<'tcx> for T
default fn from_cycle_error( tcx: TyCtxt<'tcx>, cycle_error: &CycleError, _guar: ErrorGuaranteed, ) -> T
Source§impl<T> WithSubscriber for T
impl<T> WithSubscriber for T
Source§fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
Source§fn with_current_subscriber(self) -> WithDispatch<Self>
fn with_current_subscriber(self) -> WithDispatch<Self>
impl<T> ErasedDestructor for Twhere
T: 'static,
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: 240 bytes