Skip to content

Commit 4642ba8

Browse files
committed
refactor type_check module slightly
- use a consistent name for `TypeChecker`, which is usually referred to as `typeck` - remove an incorrect doc comment - remove a single-use local
1 parent c18951a commit 4642ba8

File tree

1 file changed

+48
-47
lines changed
  • compiler/rustc_borrowck/src/type_check

1 file changed

+48
-47
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 48 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,6 @@ mod relate_tys;
106106
/// # Parameters
107107
///
108108
/// - `infcx` -- inference context to use
109-
/// - `param_env` -- parameter environment to use for trait solving
110109
/// - `body` -- MIR body to type-check
111110
/// - `promoted` -- map of promoted constants within `body`
112111
/// - `universal_regions` -- the universal regions from `body`s function signature
@@ -154,7 +153,7 @@ pub(crate) fn type_check<'a, 'tcx>(
154153

155154
debug!(?normalized_inputs_and_output);
156155

157-
let mut checker = TypeChecker {
156+
let mut typeck = TypeChecker {
158157
infcx,
159158
last_span: body.span,
160159
body,
@@ -170,23 +169,22 @@ pub(crate) fn type_check<'a, 'tcx>(
170169
constraints: &mut constraints,
171170
};
172171

173-
checker.check_user_type_annotations();
172+
typeck.check_user_type_annotations();
174173

175-
let mut verifier = TypeVerifier { cx: &mut checker, promoted, last_span: body.span };
174+
let mut verifier = TypeVerifier { typeck: &mut typeck, promoted, last_span: body.span };
176175
verifier.visit_body(body);
177176

178-
checker.typeck_mir(body);
179-
checker.equate_inputs_and_outputs(body, &normalized_inputs_and_output);
180-
checker.check_signature_annotation(body);
177+
typeck.typeck_mir(body);
178+
typeck.equate_inputs_and_outputs(body, &normalized_inputs_and_output);
179+
typeck.check_signature_annotation(body);
181180

182-
liveness::generate(&mut checker, body, &elements, flow_inits, move_data);
181+
liveness::generate(&mut typeck, body, &elements, flow_inits, move_data);
183182

184-
let opaque_type_values = infcx.take_opaque_types();
185-
186-
let opaque_type_values = opaque_type_values
183+
let opaque_type_values = infcx
184+
.take_opaque_types()
187185
.into_iter()
188186
.map(|(opaque_type_key, decl)| {
189-
let _: Result<_, ErrorGuaranteed> = checker.fully_perform_op(
187+
let _: Result<_, ErrorGuaranteed> = typeck.fully_perform_op(
190188
Locations::All(body.span),
191189
ConstraintCategory::OpaqueType,
192190
CustomTypeOp::new(
@@ -216,11 +214,11 @@ pub(crate) fn type_check<'a, 'tcx>(
216214
match region.kind() {
217215
ty::ReVar(_) => region,
218216
ty::RePlaceholder(placeholder) => {
219-
checker.constraints.placeholder_region(infcx, placeholder)
217+
typeck.constraints.placeholder_region(infcx, placeholder)
220218
}
221219
_ => ty::Region::new_var(
222220
infcx.tcx,
223-
checker.universal_regions.to_region_vid(region),
221+
typeck.universal_regions.to_region_vid(region),
224222
),
225223
}
226224
});
@@ -250,7 +248,7 @@ enum FieldAccessError {
250248
/// type, calling `span_mirbug` and returning an error type if there
251249
/// is a problem.
252250
struct TypeVerifier<'a, 'b, 'tcx> {
253-
cx: &'a mut TypeChecker<'b, 'tcx>,
251+
typeck: &'a mut TypeChecker<'b, 'tcx>,
254252
promoted: &'b IndexSlice<Promoted, Body<'tcx>>,
255253
last_span: Span,
256254
}
@@ -272,9 +270,9 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
272270
self.super_const_operand(constant, location);
273271
let ty = self.sanitize_type(constant, constant.const_.ty());
274272

275-
self.cx.infcx.tcx.for_each_free_region(&ty, |live_region| {
276-
let live_region_vid = self.cx.universal_regions.to_region_vid(live_region);
277-
self.cx.constraints.liveness_constraints.add_location(live_region_vid, location);
273+
self.typeck.infcx.tcx.for_each_free_region(&ty, |live_region| {
274+
let live_region_vid = self.typeck.universal_regions.to_region_vid(live_region);
275+
self.typeck.constraints.liveness_constraints.add_location(live_region_vid, location);
278276
});
279277

280278
// HACK(compiler-errors): Constants that are gathered into Body.required_consts
@@ -286,14 +284,14 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
286284
};
287285

288286
if let Some(annotation_index) = constant.user_ty {
289-
if let Err(terr) = self.cx.relate_type_and_user_type(
287+
if let Err(terr) = self.typeck.relate_type_and_user_type(
290288
constant.const_.ty(),
291289
ty::Invariant,
292290
&UserTypeProjection { base: annotation_index, projs: vec![] },
293291
locations,
294292
ConstraintCategory::Boring,
295293
) {
296-
let annotation = &self.cx.user_type_annotations[annotation_index];
294+
let annotation = &self.typeck.user_type_annotations[annotation_index];
297295
span_mirbug!(
298296
self,
299297
constant,
@@ -322,9 +320,12 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
322320
promoted: &Body<'tcx>,
323321
ty,
324322
san_ty| {
325-
if let Err(terr) =
326-
verifier.cx.eq_types(ty, san_ty, locations, ConstraintCategory::Boring)
327-
{
323+
if let Err(terr) = verifier.typeck.eq_types(
324+
ty,
325+
san_ty,
326+
locations,
327+
ConstraintCategory::Boring,
328+
) {
328329
span_mirbug!(
329330
verifier,
330331
promoted,
@@ -342,18 +343,18 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
342343
let promoted_ty = promoted_body.return_ty();
343344
check_err(self, promoted_body, ty, promoted_ty);
344345
} else {
345-
self.cx.ascribe_user_type(
346+
self.typeck.ascribe_user_type(
346347
constant.const_.ty(),
347348
UserType::TypeOf(uv.def, UserArgs { args: uv.args, user_self_ty: None }),
348-
locations.span(self.cx.body),
349+
locations.span(self.typeck.body),
349350
);
350351
}
351352
} else if let Some(static_def_id) = constant.check_static_ptr(tcx) {
352353
let unnormalized_ty = tcx.type_of(static_def_id).instantiate_identity();
353-
let normalized_ty = self.cx.normalize(unnormalized_ty, locations);
354+
let normalized_ty = self.typeck.normalize(unnormalized_ty, locations);
354355
let literal_ty = constant.const_.ty().builtin_deref(true).unwrap();
355356

356-
if let Err(terr) = self.cx.eq_types(
357+
if let Err(terr) = self.typeck.eq_types(
357358
literal_ty,
358359
normalized_ty,
359360
locations,
@@ -365,7 +366,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
365366

366367
if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() {
367368
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args);
368-
self.cx.normalize_and_prove_instantiated_predicates(
369+
self.typeck.normalize_and_prove_instantiated_predicates(
369370
def_id,
370371
instantiated_predicates,
371372
locations,
@@ -375,7 +376,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
375376
tcx.impl_of_method(def_id).map(|imp| tcx.def_kind(imp)),
376377
Some(DefKind::Impl { of_trait: true })
377378
));
378-
self.cx.prove_predicates(
379+
self.typeck.prove_predicates(
379380
args.types().map(|ty| ty::ClauseKind::WellFormed(ty.into())),
380381
locations,
381382
ConstraintCategory::Boring,
@@ -409,7 +410,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
409410
local_decl.ty
410411
};
411412

412-
if let Err(terr) = self.cx.relate_type_and_user_type(
413+
if let Err(terr) = self.typeck.relate_type_and_user_type(
413414
ty,
414415
ty::Invariant,
415416
user_ty,
@@ -439,11 +440,11 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> {
439440

440441
impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
441442
fn body(&self) -> &Body<'tcx> {
442-
self.cx.body
443+
self.typeck.body
443444
}
444445

445446
fn tcx(&self) -> TyCtxt<'tcx> {
446-
self.cx.infcx.tcx
447+
self.typeck.infcx.tcx
447448
}
448449

449450
fn sanitize_type(&mut self, parent: &dyn fmt::Debug, ty: Ty<'tcx>) -> Ty<'tcx> {
@@ -493,7 +494,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
493494
// whether the bounds fully apply: in effect, the rule is
494495
// that if a value of some type could implement `Copy`, then
495496
// it must.
496-
self.cx.prove_trait_ref(
497+
self.typeck.prove_trait_ref(
497498
trait_ref,
498499
location.to_locations(),
499500
ConstraintCategory::CopyBound,
@@ -508,7 +509,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
508509
// checker on the promoted MIR, then transfer the constraints back to
509510
// the main MIR, changing the locations to the provided location.
510511

511-
let parent_body = mem::replace(&mut self.cx.body, promoted_body);
512+
let parent_body = mem::replace(&mut self.typeck.body, promoted_body);
512513

513514
// Use new sets of constraints and closure bounds so that we can
514515
// modify their locations.
@@ -519,18 +520,18 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
519520
// Don't try to add borrow_region facts for the promoted MIR
520521

521522
let mut swap_constraints = |this: &mut Self| {
522-
mem::swap(this.cx.all_facts, all_facts);
523-
mem::swap(&mut this.cx.constraints.outlives_constraints, &mut constraints);
524-
mem::swap(&mut this.cx.constraints.liveness_constraints, &mut liveness_constraints);
523+
mem::swap(this.typeck.all_facts, all_facts);
524+
mem::swap(&mut this.typeck.constraints.outlives_constraints, &mut constraints);
525+
mem::swap(&mut this.typeck.constraints.liveness_constraints, &mut liveness_constraints);
525526
};
526527

527528
swap_constraints(self);
528529

529530
self.visit_body(promoted_body);
530531

531-
self.cx.typeck_mir(promoted_body);
532+
self.typeck.typeck_mir(promoted_body);
532533

533-
self.cx.body = parent_body;
534+
self.typeck.body = parent_body;
534535
// Merge the outlives constraints back in, at the given location.
535536
swap_constraints(self);
536537

@@ -546,7 +547,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
546547
// temporary from the user's point of view.
547548
constraint.category = ConstraintCategory::Boring;
548549
}
549-
self.cx.constraints.outlives_constraints.push(constraint)
550+
self.typeck.constraints.outlives_constraints.push(constraint)
550551
}
551552
// If the region is live at least one location in the promoted MIR,
552553
// then add a liveness constraint to the main MIR for this region
@@ -556,7 +557,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
556557
// unordered.
557558
#[allow(rustc::potential_query_instability)]
558559
for region in liveness_constraints.live_regions_unordered() {
559-
self.cx.constraints.liveness_constraints.add_location(region, location);
560+
self.typeck.constraints.liveness_constraints.add_location(region, location);
560561
}
561562
}
562563

@@ -640,13 +641,13 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
640641
},
641642
ProjectionElem::Field(field, fty) => {
642643
let fty = self.sanitize_type(place, fty);
643-
let fty = self.cx.normalize(fty, location);
644+
let fty = self.typeck.normalize(fty, location);
644645
match self.field_ty(place, base, field, location) {
645646
Ok(ty) => {
646-
let ty = self.cx.normalize(ty, location);
647+
let ty = self.typeck.normalize(ty, location);
647648
debug!(?fty, ?ty);
648649

649-
if let Err(terr) = self.cx.relate_types(
650+
if let Err(terr) = self.typeck.relate_types(
650651
ty,
651652
self.get_ambient_variance(context),
652653
fty,
@@ -678,8 +679,8 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
678679
}
679680
ProjectionElem::OpaqueCast(ty) => {
680681
let ty = self.sanitize_type(place, ty);
681-
let ty = self.cx.normalize(ty, location);
682-
self.cx
682+
let ty = self.typeck.normalize(ty, location);
683+
self.typeck
683684
.relate_types(
684685
ty,
685686
self.get_ambient_variance(context),
@@ -788,7 +789,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
788789
};
789790

790791
if let Some(field) = variant.fields.get(field) {
791-
Ok(self.cx.normalize(field.ty(tcx, args), location))
792+
Ok(self.typeck.normalize(field.ty(tcx, args), location))
792793
} else {
793794
Err(FieldAccessError::OutOfRange { field_count: variant.fields.len() })
794795
}

0 commit comments

Comments
 (0)