Skip to content

Commit 609bb27

Browse files
nikomatsakisdavidtwco
authored andcommitted
categorize Locations as interesting or boring
1 parent dbeda5e commit 609bb27

File tree

2 files changed

+48
-44
lines changed

2 files changed

+48
-44
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ impl<'gen, 'typeck, 'flow, 'gcx, 'tcx> TypeLivenessGenerator<'gen, 'typeck, 'flo
199199
});
200200

201201
if let Some(data) = &drop_data.region_constraint_data {
202-
self.cx.push_region_constraints(location.at_self(), data);
202+
self.cx.push_region_constraints(location.boring(), data);
203203
}
204204

205205
drop_data.dropck_result.report_overflows(

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

Lines changed: 47 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
288288
tcx.predicates_of(def_id).instantiate(tcx, substs);
289289
type_checker.normalize_and_prove_instantiated_predicates(
290290
instantiated_predicates,
291-
location,
291+
location.boring(),
292292
);
293293
}
294294

@@ -313,10 +313,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
313313

314314
debug!("sanitize_constant: expected_ty={:?}", expected_ty);
315315

316-
if let Err(terr) = self
317-
.cx
318-
.eq_types(expected_ty, constant.ty, location.at_self())
319-
{
316+
if let Err(terr) = self.cx.eq_types(expected_ty, constant.ty, location.boring()) {
320317
span_mirbug!(
321318
self,
322319
constant,
@@ -346,7 +343,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
346343
let sty = self.sanitize_type(place, sty);
347344
let ty = self.tcx().type_of(def_id);
348345
let ty = self.cx.normalize(ty, location);
349-
if let Err(terr) = self.cx.eq_types(ty, sty, location.at_self()) {
346+
if let Err(terr) = self.cx.eq_types(ty, sty, location.boring()) {
350347
span_mirbug!(
351348
self,
352349
place,
@@ -390,7 +387,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
390387
// (e.g., #29149). Note that we decide to use Copy before knowing whether the bounds
391388
// fully apply: in effect, the rule is that if a value of some type could implement
392389
// Copy, then it must.
393-
self.cx.prove_trait_ref(trait_ref, location);
390+
self.cx.prove_trait_ref(trait_ref, location.interesting());
394391
}
395392
place_ty
396393
}
@@ -489,7 +486,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
489486
ProjectionElem::Field(field, fty) => {
490487
let fty = self.sanitize_type(place, fty);
491488
match self.field_ty(place, base, field, location) {
492-
Ok(ty) => if let Err(terr) = self.cx.eq_types(ty, fty, location.at_self()) {
489+
Ok(ty) => if let Err(terr) = self.cx.eq_types(ty, fty, location.boring()) {
493490
span_mirbug!(
494491
self,
495492
place,
@@ -787,7 +784,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
787784
StatementKind::Assign(ref place, ref rv) => {
788785
let place_ty = place.ty(mir, tcx).to_ty(tcx);
789786
let rv_ty = rv.ty(mir, tcx);
790-
if let Err(terr) = self.sub_types(rv_ty, place_ty, location.at_self()) {
787+
if let Err(terr) = self.sub_types(rv_ty, place_ty, location.interesting()) {
791788
span_mirbug!(
792789
self,
793790
stmt,
@@ -802,7 +799,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
802799
def_id: tcx.lang_items().sized_trait().unwrap(),
803800
substs: tcx.mk_substs_trait(place_ty, &[]),
804801
};
805-
self.prove_trait_ref(trait_ref, location);
802+
self.prove_trait_ref(trait_ref, location.interesting());
806803
}
807804
StatementKind::SetDiscriminant {
808805
ref place,
@@ -909,7 +906,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
909906
..
910907
} => {
911908
let discr_ty = discr.ty(mir, tcx);
912-
if let Err(terr) = self.sub_types(discr_ty, switch_ty, term_location.at_self()) {
909+
if let Err(terr) = self.sub_types(discr_ty, switch_ty, term_location.boring()) {
913910
span_mirbug!(
914911
self,
915912
term,
@@ -949,7 +946,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
949946

950947
self.prove_predicates(
951948
sig.inputs().iter().map(|ty| ty::Predicate::WellFormed(ty)),
952-
term_location,
949+
term_location.boring(),
953950
);
954951

955952
// The ordinary liveness rules will ensure that all
@@ -991,7 +988,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
991988
match mir.yield_ty {
992989
None => span_mirbug!(self, term, "yield in non-generator"),
993990
Some(ty) => {
994-
if let Err(terr) = self.sub_types(value_ty, ty, term_location.at_self()) {
991+
if let Err(terr) = self.sub_types(value_ty, ty, term_location.interesting()) {
995992
span_mirbug!(
996993
self,
997994
term,
@@ -1056,7 +1053,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
10561053
}
10571054
for (n, (fn_arg, op_arg)) in sig.inputs().iter().zip(args).enumerate() {
10581055
let op_arg_ty = op_arg.ty(mir, self.tcx());
1059-
if let Err(terr) = self.sub_types(op_arg_ty, fn_arg, term_location.at_self()) {
1056+
if let Err(terr) = self.sub_types(op_arg_ty, fn_arg, term_location.interesting()) {
10601057
span_mirbug!(
10611058
self,
10621059
term,
@@ -1284,7 +1281,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12841281
substs: tcx.mk_substs_trait(operand_ty, &[]),
12851282
};
12861283

1287-
self.prove_trait_ref(trait_ref, location);
1284+
self.prove_trait_ref(trait_ref, location.interesting());
12881285
},
12891286

12901287
Rvalue::NullaryOp(_, ty) => {
@@ -1293,7 +1290,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
12931290
substs: tcx.mk_substs_trait(ty, &[]),
12941291
};
12951292

1296-
self.prove_trait_ref(trait_ref, location);
1293+
self.prove_trait_ref(trait_ref, location.interesting());
12971294
}
12981295

12991296
Rvalue::Cast(cast_kind, op, ty) => match cast_kind {
@@ -1309,7 +1306,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13091306

13101307
let ty_fn_ptr_from = tcx.mk_fn_ptr(fn_sig);
13111308

1312-
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.at_self()) {
1309+
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.interesting()) {
13131310
span_mirbug!(
13141311
self,
13151312
rvalue,
@@ -1330,7 +1327,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13301327
};
13311328
let ty_fn_ptr_from = tcx.coerce_closure_fn_ty(sig);
13321329

1333-
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.at_self()) {
1330+
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.interesting()) {
13341331
span_mirbug!(
13351332
self,
13361333
rvalue,
@@ -1354,7 +1351,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13541351

13551352
let ty_fn_ptr_from = tcx.safe_to_unsafe_fn_ty(fn_sig);
13561353

1357-
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.at_self()) {
1354+
if let Err(terr) = self.eq_types(ty_fn_ptr_from, ty, location.interesting()) {
13581355
span_mirbug!(
13591356
self,
13601357
rvalue,
@@ -1373,7 +1370,7 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
13731370
substs: tcx.mk_substs_trait(op.ty(mir, tcx), &[ty.into()]),
13741371
};
13751372

1376-
self.prove_trait_ref(trait_ref, location);
1373+
self.prove_trait_ref(trait_ref, location.interesting());
13771374
}
13781375

13791376
CastKind::Misc => {}
@@ -1422,7 +1419,8 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
14221419
}
14231420
};
14241421
let operand_ty = operand.ty(mir, tcx);
1425-
if let Err(terr) = self.sub_types(operand_ty, field_ty, location.at_self()) {
1422+
1423+
if let Err(terr) = self.sub_types(operand_ty, field_ty, location.boring()) {
14261424
span_mirbug!(
14271425
self,
14281426
rvalue,
@@ -1483,8 +1481,9 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
14831481
*substs,
14841482
);
14851483

1484+
// Hmm, are these constraints *really* boring?
14861485
self.push_region_constraints(
1487-
location.at_self(),
1486+
location.boring(),
14881487
&closure_constraints,
14891488
);
14901489
}
@@ -1499,53 +1498,53 @@ impl<'a, 'gcx, 'tcx> TypeChecker<'a, 'gcx, 'tcx> {
14991498
AggregateKind::Array(_) | AggregateKind::Tuple => ty::InstantiatedPredicates::empty(),
15001499
};
15011500

1502-
self.normalize_and_prove_instantiated_predicates(instantiated_predicates, location);
1501+
self.normalize_and_prove_instantiated_predicates(instantiated_predicates, location.boring());
15031502
}
15041503

1505-
fn prove_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>, location: Location) {
1504+
fn prove_trait_ref(&mut self, trait_ref: ty::TraitRef<'tcx>, locations: Locations) {
15061505
self.prove_predicates(
15071506
Some(ty::Predicate::Trait(
15081507
trait_ref.to_poly_trait_ref().to_poly_trait_predicate(),
15091508
)),
1510-
location,
1509+
locations,
15111510
);
15121511
}
15131512

15141513
fn normalize_and_prove_instantiated_predicates(
15151514
&mut self,
15161515
instantiated_predicates: ty::InstantiatedPredicates<'tcx>,
1517-
location: Location,
1516+
locations: Locations,
15181517
) {
15191518
for predicate in instantiated_predicates.predicates {
1520-
let predicate = self.normalize(predicate, location);
1521-
self.prove_predicate(predicate, location);
1519+
let predicate = self.normalize(predicate, locations);
1520+
self.prove_predicate(predicate, locations);
15221521
}
15231522
}
15241523

15251524
fn prove_predicates(
15261525
&mut self,
15271526
predicates: impl IntoIterator<Item = ty::Predicate<'tcx>>,
1528-
location: Location,
1527+
locations: Locations,
15291528
) {
15301529
for predicate in predicates {
15311530
debug!(
1532-
"prove_predicates(predicate={:?}, location={:?})",
1533-
predicate, location,
1531+
"prove_predicates(predicate={:?}, locations={:?})",
1532+
predicate, locations,
15341533
);
15351534

1536-
self.prove_predicate(predicate, location);
1535+
self.prove_predicate(predicate, locations);
15371536
}
15381537
}
15391538

1540-
fn prove_predicate(&mut self, predicate: ty::Predicate<'tcx>, location: Location) {
1539+
fn prove_predicate(&mut self, predicate: ty::Predicate<'tcx>, locations: Locations) {
15411540
debug!(
15421541
"prove_predicate(predicate={:?}, location={:?})",
1543-
predicate, location,
1542+
predicate, locations,
15441543
);
15451544

15461545
let param_env = self.param_env;
15471546
self.fully_perform_op(
1548-
location.at_self(),
1547+
locations,
15491548
param_env.and(type_op::prove_predicate::ProvePredicate::new(predicate)),
15501549
).unwrap_or_else(|NoSolution| {
15511550
span_mirbug!(self, NoSolution, "could not prove {:?}", predicate);
@@ -1632,20 +1631,25 @@ impl MirPass for TypeckMir {
16321631
}
16331632

16341633
trait AtLocation {
1635-
/// Creates a `Locations` where `self` is both the from-location
1636-
/// and the at-location. This means that any required region
1637-
/// relationships must hold upon entering the statement/terminator
1638-
/// indicated by `self`. This is typically used when processing
1639-
/// "inputs" to the given location.
1640-
fn at_self(self) -> Locations;
1634+
/// Indicates a "boring" constraint that the user probably
1635+
/// woudln't want to see highlights.
1636+
fn boring(self) -> Locations;
1637+
1638+
/// Indicates an "interesting" edge, which is of significance only
1639+
/// for diagnostics.
1640+
fn interesting(self) -> Locations;
16411641
}
16421642

16431643
impl AtLocation for Location {
1644-
fn at_self(self) -> Locations {
1644+
fn boring(self) -> Locations {
16451645
Locations::Pair {
16461646
from_location: self,
16471647
}
16481648
}
1649+
1650+
fn interesting(self) -> Locations {
1651+
self.boring()
1652+
}
16491653
}
16501654

16511655
trait NormalizeLocation: fmt::Debug + Copy {
@@ -1660,6 +1664,6 @@ impl NormalizeLocation for Locations {
16601664

16611665
impl NormalizeLocation for Location {
16621666
fn to_locations(self) -> Locations {
1663-
self.at_self()
1667+
self.boring()
16641668
}
16651669
}

0 commit comments

Comments
 (0)