Skip to content

Commit 9e305a8

Browse files
committed
type_check/mod.rs: rustfmt
1 parent 2f31698 commit 9e305a8

File tree

1 file changed

+100
-137
lines changed
  • src/librustc_mir/borrow_check/nll/type_check

1 file changed

+100
-137
lines changed

src/librustc_mir/borrow_check/nll/type_check/mod.rs

Lines changed: 100 additions & 137 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ use borrow_check::nll::constraints::{ConstraintCategory, ConstraintSet, Outlives
1717
use borrow_check::nll::facts::AllFacts;
1818
use borrow_check::nll::region_infer::values::{LivenessValues, RegionValueElements};
1919
use borrow_check::nll::region_infer::{ClosureRegionRequirementsExt, TypeTest};
20+
use borrow_check::nll::renumber;
2021
use borrow_check::nll::type_check::free_region_relations::{
2122
CreateResult, UniversalRegionRelations,
2223
};
2324
use borrow_check::nll::universal_regions::UniversalRegions;
2425
use borrow_check::nll::ToRegionVid;
25-
use borrow_check::nll::renumber;
2626
use dataflow::move_paths::MoveData;
2727
use dataflow::FlowAtLocation;
2828
use dataflow::MaybeInitializedPlaces;
@@ -35,13 +35,13 @@ use rustc::mir::interpret::EvalErrorKind::BoundsCheck;
3535
use rustc::mir::tcx::PlaceTy;
3636
use rustc::mir::visit::{PlaceContext, Visitor};
3737
use rustc::mir::*;
38-
use rustc::traits::{ObligationCause, PredicateObligations};
3938
use rustc::traits::query::type_op;
4039
use rustc::traits::query::type_op::custom::CustomTypeOp;
4140
use rustc::traits::query::{Fallible, NoSolution};
41+
use rustc::traits::{ObligationCause, PredicateObligations};
4242
use rustc::ty::fold::TypeFoldable;
43-
use rustc::ty::{self, CanonicalTy, RegionVid, ToPolyTraitRef, Ty, TyCtxt, TyKind};
4443
use rustc::ty::subst::Subst;
44+
use rustc::ty::{self, CanonicalTy, RegionVid, ToPolyTraitRef, Ty, TyCtxt, TyKind};
4545
use std::fmt;
4646
use std::rc::Rc;
4747
use syntax_pos::{Span, DUMMY_SP};
@@ -161,11 +161,7 @@ pub(crate) fn type_check<'gcx, 'tcx>(
161161
Some(&mut borrowck_context),
162162
Some(&universal_region_relations),
163163
|cx| {
164-
cx.equate_inputs_and_outputs(
165-
mir,
166-
universal_regions,
167-
&normalized_inputs_and_output,
168-
);
164+
cx.equate_inputs_and_outputs(mir, universal_regions, &normalized_inputs_and_output);
169165
liveness::generate(cx, mir, elements, flow_inits, move_data);
170166
},
171167
);
@@ -377,14 +373,12 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
377373

378374
debug!("sanitize_constant: expected_ty={:?}", constant.literal.ty);
379375

380-
if let Err(terr) = self.cx
381-
.eq_types(
382-
constant.literal.ty,
383-
constant.ty,
384-
location.to_locations(),
385-
ConstraintCategory::Boring,
386-
)
387-
{
376+
if let Err(terr) = self.cx.eq_types(
377+
constant.literal.ty,
378+
constant.ty,
379+
location.to_locations(),
380+
ConstraintCategory::Boring,
381+
) {
388382
span_mirbug!(
389383
self,
390384
constant,
@@ -429,12 +423,10 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
429423
let sty = self.sanitize_type(place, sty);
430424
let ty = self.tcx().type_of(def_id);
431425
let ty = self.cx.normalize(ty, location);
432-
if let Err(terr) = self.cx.eq_types(
433-
ty,
434-
sty,
435-
location.to_locations(),
436-
ConstraintCategory::Boring,
437-
) {
426+
if let Err(terr) =
427+
self.cx
428+
.eq_types(ty, sty, location.to_locations(), ConstraintCategory::Boring)
429+
{
438430
span_mirbug!(
439431
self,
440432
place,
@@ -955,66 +947,55 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
955947
let tcx = infcx.tcx;
956948
let param_env = self.param_env;
957949
let parent_def_id = infcx.tcx.closure_base_def_id(self.mir_def_id);
958-
let opaque_type_map =
959-
self.fully_perform_op(
960-
locations,
961-
category,
962-
CustomTypeOp::new(
963-
|infcx| {
964-
let mut obligations = ObligationAccumulator::default();
965-
966-
let dummy_body_id = ObligationCause::dummy().body_id;
967-
let (output_ty, opaque_type_map) =
968-
obligations.add(infcx.instantiate_opaque_types(
969-
parent_def_id,
970-
dummy_body_id,
971-
param_env,
972-
&anon_ty,
973-
));
950+
let opaque_type_map = self.fully_perform_op(
951+
locations,
952+
category,
953+
CustomTypeOp::new(
954+
|infcx| {
955+
let mut obligations = ObligationAccumulator::default();
956+
957+
let dummy_body_id = ObligationCause::dummy().body_id;
958+
let (output_ty, opaque_type_map) =
959+
obligations.add(infcx.instantiate_opaque_types(
960+
parent_def_id,
961+
dummy_body_id,
962+
param_env,
963+
&anon_ty,
964+
));
965+
debug!(
966+
"eq_opaque_type_and_type: \
967+
instantiated output_ty={:?} \
968+
opaque_type_map={:#?} \
969+
revealed_ty={:?}",
970+
output_ty, opaque_type_map, revealed_ty
971+
);
972+
obligations.add(infcx
973+
.at(&ObligationCause::dummy(), param_env)
974+
.eq(output_ty, revealed_ty)?);
975+
976+
for (&opaque_def_id, opaque_decl) in &opaque_type_map {
977+
let opaque_defn_ty = tcx.type_of(opaque_def_id);
978+
let opaque_defn_ty = opaque_defn_ty.subst(tcx, opaque_decl.substs);
979+
let opaque_defn_ty = renumber::renumber_regions(infcx, &opaque_defn_ty);
974980
debug!(
975-
"eq_opaque_type_and_type: \
976-
instantiated output_ty={:?} \
977-
opaque_type_map={:#?} \
978-
revealed_ty={:?}",
979-
output_ty,
980-
opaque_type_map,
981-
revealed_ty
982-
);
983-
obligations.add(
984-
infcx
985-
.at(&ObligationCause::dummy(), param_env)
986-
.eq(output_ty, revealed_ty)?,
981+
"eq_opaque_type_and_type: concrete_ty={:?} opaque_defn_ty={:?}",
982+
opaque_decl.concrete_ty, opaque_defn_ty
987983
);
984+
obligations.add(infcx
985+
.at(&ObligationCause::dummy(), param_env)
986+
.eq(opaque_decl.concrete_ty, opaque_defn_ty)?);
987+
}
988988

989-
for (&opaque_def_id, opaque_decl) in &opaque_type_map {
990-
let opaque_defn_ty = tcx.type_of(opaque_def_id);
991-
let opaque_defn_ty = opaque_defn_ty.subst(tcx, opaque_decl.substs);
992-
let opaque_defn_ty = renumber::renumber_regions(
993-
infcx,
994-
&opaque_defn_ty,
995-
);
996-
debug!(
997-
"eq_opaque_type_and_type: concrete_ty={:?} opaque_defn_ty={:?}",
998-
opaque_decl.concrete_ty,
999-
opaque_defn_ty
1000-
);
1001-
obligations.add(
1002-
infcx
1003-
.at(&ObligationCause::dummy(), param_env)
1004-
.eq(opaque_decl.concrete_ty, opaque_defn_ty)?,
1005-
);
1006-
}
1007-
1008-
debug!("eq_opaque_type_and_type: equated");
989+
debug!("eq_opaque_type_and_type: equated");
1009990

1010-
Ok(InferOk {
1011-
value: Some(opaque_type_map),
1012-
obligations: obligations.into_vec(),
1013-
})
1014-
},
1015-
|| "input_output".to_string(),
1016-
),
1017-
)?;
991+
Ok(InferOk {
992+
value: Some(opaque_type_map),
993+
obligations: obligations.into_vec(),
994+
})
995+
},
996+
|| "input_output".to_string(),
997+
),
998+
)?;
1018999

10191000
let universal_region_relations = match self.universal_region_relations {
10201001
Some(rel) => rel,
@@ -1035,7 +1016,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10351016
infcx.constrain_opaque_type(
10361017
opaque_def_id,
10371018
&opaque_decl,
1038-
universal_region_relations
1019+
universal_region_relations,
10391020
);
10401021
Ok(InferOk {
10411022
value: (),
@@ -1073,12 +1054,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10731054

10741055
let place_ty = place.ty(mir, tcx).to_ty(tcx);
10751056
let rv_ty = rv.ty(mir, tcx);
1076-
if let Err(terr) = self.sub_types_or_anon(
1077-
rv_ty,
1078-
place_ty,
1079-
location.to_locations(),
1080-
category,
1081-
) {
1057+
if let Err(terr) =
1058+
self.sub_types_or_anon(rv_ty, place_ty, location.to_locations(), category)
1059+
{
10821060
span_mirbug!(
10831061
self,
10841062
stmt,
@@ -1117,7 +1095,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11171095
self.prove_trait_ref(
11181096
trait_ref,
11191097
location.to_locations(),
1120-
ConstraintCategory::SizedBound,
1098+
ConstraintCategory::SizedBound,
11211099
);
11221100
}
11231101
}
@@ -1148,15 +1126,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
11481126
}
11491127
StatementKind::AscribeUserType(ref place, variance, c_ty) => {
11501128
let place_ty = place.ty(mir, tcx).to_ty(tcx);
1151-
if let Err(terr) =
1152-
self.relate_type_and_user_type(
1153-
place_ty,
1154-
variance,
1155-
c_ty,
1156-
Locations::All(stmt.source_info.span),
1157-
ConstraintCategory::TypeAnnotation,
1158-
)
1159-
{
1129+
if let Err(terr) = self.relate_type_and_user_type(
1130+
place_ty,
1131+
variance,
1132+
c_ty,
1133+
Locations::All(stmt.source_info.span),
1134+
ConstraintCategory::TypeAnnotation,
1135+
) {
11601136
span_mirbug!(
11611137
self,
11621138
stmt,
@@ -1208,12 +1184,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12081184
let rv_ty = value.ty(mir, tcx);
12091185

12101186
let locations = term_location.to_locations();
1211-
if let Err(terr) = self.sub_types(
1212-
rv_ty,
1213-
place_ty,
1214-
locations,
1215-
ConstraintCategory::Assignment,
1216-
) {
1187+
if let Err(terr) =
1188+
self.sub_types(rv_ty, place_ty, locations, ConstraintCategory::Assignment)
1189+
{
12171190
span_mirbug!(
12181191
self,
12191192
term,
@@ -1327,8 +1300,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13271300
ty,
13281301
term_location.to_locations(),
13291302
ConstraintCategory::Return,
1330-
)
1331-
{
1303+
) {
13321304
span_mirbug!(
13331305
self,
13341306
term,
@@ -1366,12 +1338,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13661338

13671339
let locations = term_location.to_locations();
13681340

1369-
if let Err(terr) = self.sub_types_or_anon(
1370-
sig.output(),
1371-
dest_ty,
1372-
locations,
1373-
category,
1374-
) {
1341+
if let Err(terr) =
1342+
self.sub_types_or_anon(sig.output(), dest_ty, locations, category)
1343+
{
13751344
span_mirbug!(
13761345
self,
13771346
term,
@@ -1539,12 +1508,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
15391508
}
15401509
}
15411510

1542-
fn check_local(
1543-
&mut self,
1544-
mir: &Mir<'tcx>,
1545-
local: Local,
1546-
local_decl: &LocalDecl<'tcx>,
1547-
) {
1511+
fn check_local(&mut self, mir: &Mir<'tcx>, local: Local, local_decl: &LocalDecl<'tcx>) {
15481512
match mir.local_kind(local) {
15491513
LocalKind::ReturnPointer | LocalKind::Arg => {
15501514
// return values of normal functions are required to be
@@ -1713,13 +1677,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
17131677
ConstraintCategory::Cast,
17141678
) {
17151679
span_mirbug!(
1716-
self,
1717-
rvalue,
1718-
"equating {:?} with {:?} yields {:?}",
1719-
ty_fn_ptr_from,
1720-
ty,
1721-
terr
1722-
);
1680+
self,
1681+
rvalue,
1682+
"equating {:?} with {:?} yields {:?}",
1683+
ty_fn_ptr_from,
1684+
ty,
1685+
terr
1686+
);
17231687
}
17241688
}
17251689

@@ -1739,13 +1703,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
17391703
ConstraintCategory::Cast,
17401704
) {
17411705
span_mirbug!(
1742-
self,
1743-
rvalue,
1744-
"equating {:?} with {:?} yields {:?}",
1745-
ty_fn_ptr_from,
1746-
ty,
1747-
terr
1748-
);
1706+
self,
1707+
rvalue,
1708+
"equating {:?} with {:?} yields {:?}",
1709+
ty_fn_ptr_from,
1710+
ty,
1711+
terr
1712+
);
17491713
}
17501714
}
17511715

@@ -1768,13 +1732,13 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
17681732
ConstraintCategory::Cast,
17691733
) {
17701734
span_mirbug!(
1771-
self,
1772-
rvalue,
1773-
"equating {:?} with {:?} yields {:?}",
1774-
ty_fn_ptr_from,
1775-
ty,
1776-
terr
1777-
);
1735+
self,
1736+
rvalue,
1737+
"equating {:?} with {:?} yields {:?}",
1738+
ty_fn_ptr_from,
1739+
ty,
1740+
terr
1741+
);
17781742
}
17791743
}
17801744

@@ -2277,4 +2241,3 @@ impl<'tcx> ObligationAccumulator<'tcx> {
22772241
self.obligations
22782242
}
22792243
}
2280-

0 commit comments

Comments
 (0)