Skip to content

Commit 842f059

Browse files
matthewjasperlqd
authored andcommitted
Show bound lifetimes when comparing types in diagnostics
1 parent 5d52c0e commit 842f059

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,16 +1191,26 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
11911191
// | |
11921192
// | elided as they were the same
11931193
// not elided, they were different, but irrelevant
1194+
//
1195+
// For bound lifetimes, keep the names of the lifetimes,
1196+
// even if they are the same so that it's clear what's happening
1197+
// if we have something like
1198+
//
1199+
// for<'r, 's> fn(Inv<'r>, Inv<'s>)
1200+
// for<'r> fn(Inv<'r>, Inv<'r>)
11941201
let lifetimes = sub1.regions().zip(sub2.regions());
11951202
for (i, lifetimes) in lifetimes.enumerate() {
11961203
let l1 = lifetime_display(lifetimes.0);
11971204
let l2 = lifetime_display(lifetimes.1);
1198-
if lifetimes.0 == lifetimes.1 {
1199-
values.0.push_normal("'_");
1200-
values.1.push_normal("'_");
1201-
} else {
1205+
if lifetimes.0 != lifetimes.1 {
12021206
values.0.push_highlighted(l1);
12031207
values.1.push_highlighted(l2);
1208+
} else if lifetimes.0.is_late_bound() {
1209+
values.0.push_normal(l1);
1210+
values.1.push_normal(l2);
1211+
} else {
1212+
values.0.push_normal("'_");
1213+
values.1.push_normal("'_");
12041214
}
12051215
self.push_comma(&mut values.0, &mut values.1, len, i);
12061216
}

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
pub use self::freshen::TypeFreshener;
2+
pub use self::lexical_region_resolve::RegionResolutionError;
23
pub use self::LateBoundRegionConversionTime::*;
34
pub use self::RegionVariableOrigin::*;
45
pub use self::SubregionOrigin::*;

0 commit comments

Comments
 (0)