Skip to content

Commit 3d965bd

Browse files
committed
Convert static lifetime to an nll var
1 parent d9617c8 commit 3d965bd

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

compiler/rustc_borrowck/src/type_check/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1581,12 +1581,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
15811581
.unwrap();
15821582
}
15831583
(None, None) => {
1584+
// `struct_tail` returns regions which haven't been mapped
1585+
// to nll vars yet so we do it here as `outlives_constraints`
1586+
// expects nll vars.
1587+
let src_lt = self.universal_regions.to_region_vid(src_lt);
1588+
let dst_lt = self.universal_regions.to_region_vid(dst_lt);
1589+
15841590
// The principalless (no non-auto traits) case:
15851591
// You can only cast `dyn Send + 'long` to `dyn Send + 'short`.
15861592
self.constraints.outlives_constraints.push(
15871593
OutlivesConstraint {
1588-
sup: src_lt.as_var(),
1589-
sub: dst_lt.as_var(),
1594+
sup: src_lt,
1595+
sub: dst_lt,
15901596
locations: location.to_locations(),
15911597
span: location.to_locations().span(self.body),
15921598
category: ConstraintCategory::Cast {
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//@ check-pass
2+
3+
// During MIR typeck when casting `*mut dyn Sync + '?x` to
4+
// `*mut Wrap` we compute the tail of `Wrap` as `dyn Sync + 'static`.
5+
//
6+
// This test ensures that we first convert the `'static` lifetime to
7+
// the nll var `'?0` before introducing the region constraint `'?x: 'static`.
8+
9+
struct Wrap(dyn Sync + 'static);
10+
11+
fn cast(x: *mut (dyn Sync + 'static)) {
12+
x as *mut Wrap;
13+
}
14+
15+
fn main() {}

0 commit comments

Comments
 (0)