Skip to content

Commit c7e00ae

Browse files
authored
Unrolled build for rust-lang#126004
Rollup merge of rust-lang#126004 - compiler-errors:captures-soundness-test, r=lcnr Add another test for hidden types capturing lifetimes that outlive but arent mentioned in substs Another test to make sure future implementations of rust-lang#116040 don't have any subtle unsoundness 🤔 r? types
2 parents 5ee2dfd + dd6bca5 commit c7e00ae

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// This test should never pass!
2+
3+
#![feature(type_alias_impl_trait)]
4+
5+
pub trait Captures<'a> {}
6+
impl<T> Captures<'_> for T {}
7+
8+
pub struct MyTy<'a, 'b>(Option<*mut &'a &'b ()>);
9+
unsafe impl Send for MyTy<'_, 'static> {}
10+
11+
pub mod step1 {
12+
use super::*;
13+
pub type Step1<'a, 'b: 'a> = impl Sized + Captures<'b> + 'a;
14+
pub fn step1<'a, 'b: 'a>() -> Step1<'a, 'b> {
15+
MyTy::<'a, 'b>(None)
16+
}
17+
}
18+
19+
pub mod step2 {
20+
pub type Step2<'a> = impl Send + 'a;
21+
22+
// Although `Step2` is WF at the definition site, it's not WF in its
23+
// declaration site (above). We check this in `check_opaque_meets_bounds`,
24+
// which must remain sound.
25+
pub fn step2<'a, 'b: 'a>() -> Step2<'a>
26+
where crate::step1::Step1<'a, 'b>: Send
27+
{
28+
crate::step1::step1::<'a, 'b>()
29+
//~^ ERROR hidden type for `Step2<'a>` captures lifetime that does not appear in bounds
30+
}
31+
}
32+
33+
fn step3<'a, 'b>() {
34+
fn is_send<T: Send>() {}
35+
is_send::<crate::step2::Step2::<'a>>();
36+
}
37+
38+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0700]: hidden type for `Step2<'a>` captures lifetime that does not appear in bounds
2+
--> $DIR/tait-hidden-erased-unsoundness-2.rs:28:9
3+
|
4+
LL | pub type Step2<'a> = impl Send + 'a;
5+
| -------------- opaque type defined here
6+
...
7+
LL | pub fn step2<'a, 'b: 'a>() -> Step2<'a>
8+
| -- hidden type `Step1<'a, 'b>` captures the lifetime `'b` as defined here
9+
...
10+
LL | crate::step1::step1::<'a, 'b>()
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error: aborting due to 1 previous error
14+
15+
For more information about this error, try `rustc --explain E0700`.

0 commit comments

Comments
 (0)