Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1581,12 +1581,18 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
.unwrap();
}
(None, None) => {
// `struct_tail` returns regions which haven't been mapped
// to nll vars yet so we do it here as `outlives_constraints`
// expects nll vars.
let src_lt = self.universal_regions.to_region_vid(src_lt);
let dst_lt = self.universal_regions.to_region_vid(dst_lt);

// The principalless (no non-auto traits) case:
// You can only cast `dyn Send + 'long` to `dyn Send + 'short`.
self.constraints.outlives_constraints.push(
OutlivesConstraint {
sup: src_lt.as_var(),
sub: dst_lt.as_var(),
sup: src_lt,
sub: dst_lt,
locations: location.to_locations(),
span: location.to_locations().span(self.body),
category: ConstraintCategory::Cast {
Expand Down
15 changes: 15 additions & 0 deletions tests/ui/cast/ptr-to-ptr-unsized-adt-tail-with-static-region.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//@ check-pass

// During MIR typeck when casting `*mut dyn Sync + '?x` to
// `*mut Wrap` we compute the tail of `Wrap` as `dyn Sync + 'static`.
//
// This test ensures that we first convert the `'static` lifetime to
// the nll var `'?0` before introducing the region constraint `'?x: 'static`.

struct Wrap(dyn Sync + 'static);

fn cast(x: *mut (dyn Sync + 'static)) {
x as *mut Wrap;
}

fn main() {}
Loading