Skip to content

Commit 74a623f

Browse files
author
Alexander Regueiro
committed
Updated tests.
1 parent 3be9417 commit 74a623f

6 files changed

+56
-9
lines changed

src/librustc/infer/opaque_types/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
404404
// For soundness, we need to ensure that every region that is captured by the opaque type
405405
// but does not explicitly appear in the opaque type outlives the actual (concrete) type.
406406
// This allows for invariant lifetimes to be captured by opaque types as long as
407-
// short-lived lifetimes are not permitted to escape and cause UB.
407+
// short-lived lifetimes are not permitted to escape and cause UB.
408408
let opaque_substs_regions = opaque_defn.substs.regions().collect();
409409
let captured_regions = concrete_ty_regions.difference(&opaque_substs_regions);
410410
for captured_region in captured_regions {

src/test/ui/impl-trait/issue-55608-captures-empty-region.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
// run-pass
2+
13
// This used to ICE because it creates an `impl Trait` that captures a
24
// hidden empty region.
35

4-
#![feature(conservative_impl_trait)]
5-
6-
fn server() -> impl FilterBase2 { //~ ERROR [E0700]
6+
fn server() -> impl FilterBase2 {
77
segment2(|| { loop { } }).map2(|| "")
88
}
99

src/test/ui/impl-trait/region-escape-via-bound-contravariant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// In contrast to `region-escape-via-bound-invariant`, in this case we
1+
// In contrast to `region-escape-via-bound.rs`, in this case we
22
// *can* return a value of type `&'x u32`, even though `'x` does not
33
// appear in the bounds. This is because `&` is contravariant, and so
44
// we are *actually* returning a `&'y u32`.

src/test/ui/impl-trait/region-escape-via-bound.rs

+10-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
// Test that we do not allow the region `'x` to escape in the impl
2-
// trait **even though** `'y` escapes, which outlives `'x`.
1+
// run-pass
2+
3+
// Test that we allow the region `'x` to escape in the impl
4+
// because 'y` escapes, which outlives `'x`.
35
//
46
// See https://github.com/rust-lang/rust/issues/46541 for more details.
57

@@ -14,10 +16,14 @@ trait Trait<'a> { }
1416
impl Trait<'b> for Cell<&'a u32> { }
1517

1618
fn foo(x: Cell<&'x u32>) -> impl Trait<'y>
17-
//~^ ERROR hidden type for `impl Trait` captures lifetime that does not appear in bounds [E0700]
19+
// ^ hidden type for `impl Trait` captures lifetime that does not appear in bounds
20+
// because it outlives the lifetime that *does* appear in the bounds, `'y`
1821
where 'x: 'y
1922
{
2023
x
2124
}
2225

23-
fn main() { }
26+
fn main() {
27+
let x = 123;
28+
let _ = foo(Cell::new(&x));
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// compile-fail
2+
3+
// See https://github.com/rust-lang/rust/pull/57870#issuecomment-457333709 for more details.
4+
5+
trait Swap: Sized {
6+
fn swap(self, other: Self);
7+
}
8+
9+
impl<T> Swap for &mut T {
10+
fn swap(self, other: Self) {
11+
std::mem::swap(self, other);
12+
}
13+
}
14+
15+
// The hidden relifetimegion `'b` should not be allowed to escape this function, since it may not
16+
// outlive '`a`, in which case we have a dangling reference.
17+
fn hide<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
18+
//~^ lifetime mismatch [E0623]
19+
x
20+
}
21+
22+
fn dangle() -> &'static [i32; 3] {
23+
let mut res = &[4, 5, 6];
24+
let x = [1, 2, 3];
25+
hide(&mut res).swap(hide(&mut &x));
26+
res
27+
}
28+
29+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0623]: lifetime mismatch
2+
--> $DIR/region-escape-via-swap.rs:17:50
3+
|
4+
LL | fn hide<'a, 'b, T: 'static>(x: &'a mut &'b T) -> impl Swap + 'a {
5+
| ----- ^^^^^^^^^^^^^^
6+
| | |
7+
| | ...but data from `x` is returned here
8+
| this parameter and the return type are declared with different lifetimes...
9+
10+
error: aborting due to previous error
11+
12+
For more information about this error, try `rustc --explain E0623`.

0 commit comments

Comments
 (0)