Skip to content

Commit 75babbc

Browse files
committed
add variation of the rust-lang#135246 unsoundness
1 parent b8f4d1b commit 75babbc

File tree

3 files changed

+111
-0
lines changed

3 files changed

+111
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
error[E0275]: overflow evaluating the requirement `Vec<u8>: Trait<String>`
2+
--> $DIR/item-bound-via-impl-where-clause.rs:31:21
3+
|
4+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
|
7+
note: required for `Vec<u8>` to implement `Trait<String>`
8+
--> $DIR/item-bound-via-impl-where-clause.rs:22:12
9+
|
10+
LL | impl<L, R> Trait<R> for L
11+
| ^^^^^^^^ ^
12+
LL | where
13+
LL | L: Trait<R>,
14+
| -------- unsatisfied trait bound introduced here
15+
note: required by a bound in `transmute`
16+
--> $DIR/item-bound-via-impl-where-clause.rs:29:17
17+
|
18+
LL | fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
19+
| ^^^^^^^^ required by this bound in `transmute`
20+
21+
error: aborting due to 1 previous error
22+
23+
For more information about this error, try `rustc --explain E0275`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
error[E0275]: overflow evaluating the requirement `Vec<u8>: Trait<String>`
2+
--> $DIR/item-bound-via-impl-where-clause.rs:31:33
3+
|
4+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
5+
| ^
6+
|
7+
note: required by a bound in `transmute`
8+
--> $DIR/item-bound-via-impl-where-clause.rs:29:17
9+
|
10+
LL | fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
11+
| ^^^^^^^^ required by this bound in `transmute`
12+
13+
error[E0275]: overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof == _`
14+
--> $DIR/item-bound-via-impl-where-clause.rs:31:21
15+
|
16+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
19+
error[E0275]: overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof == String`
20+
--> $DIR/item-bound-via-impl-where-clause.rs:31:21
21+
|
22+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
24+
25+
error[E0275]: overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof: Sized`
26+
--> $DIR/item-bound-via-impl-where-clause.rs:31:21
27+
|
28+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
29+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
30+
|
31+
= note: the return type of a function must have a statically known size
32+
33+
error[E0275]: overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof well-formed`
34+
--> $DIR/item-bound-via-impl-where-clause.rs:31:21
35+
|
36+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
37+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
38+
39+
error[E0275]: overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof == _`
40+
--> $DIR/item-bound-via-impl-where-clause.rs:31:21
41+
|
42+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
|
45+
= note: duplicate diagnostic emitted due to `-Z deduplicate-diagnostics=no`
46+
47+
error: aborting due to 6 previous errors
48+
49+
For more information about this error, try `rustc --explain E0275`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ revisions: current next
2+
//@ ignore-compare-mode-next-solver (explicit revisions)
3+
//@[next] compile-flags: -Znext-solver
4+
5+
// A variation of #135246 where the cyclic bounds are part of
6+
// the impl instead of the impl associated item.
7+
8+
trait Trait<R>: Sized {
9+
type Proof: Trait<R, Proof = Self>;
10+
}
11+
12+
// We need to use indirection here as we otherwise normalize
13+
// `<L::Proof as Trait<R>>::Proof` before recursing into
14+
// `R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>`.
15+
trait Indir<L: Trait<R>, R>: Trait<R, Proof = <L::Proof as Trait<R>>::Proof> {}
16+
impl<L, R> Indir<L, R> for R
17+
where
18+
L: Trait<R>,
19+
R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>,
20+
{}
21+
22+
impl<L, R> Trait<R> for L
23+
where
24+
L: Trait<R>,
25+
R: Indir<L, R>,
26+
{
27+
type Proof = R;
28+
}
29+
fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
30+
fn main() {
31+
let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
32+
//~^ ERROR overflow evaluating the requirement `Vec<u8>: Trait<String>`
33+
//[next]~| ERROR overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof == _`
34+
//[next]~| ERROR overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof == String`
35+
//[next]~| ERROR overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof: Sized`
36+
//[next]~| ERROR overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof well-formed`
37+
//[next]~| ERROR overflow evaluating the requirement `<<Vec<u8> as Trait<String>>::Proof as Trait<String>>::Proof == _`
38+
println!("{}", s); // ABC
39+
}

0 commit comments

Comments
 (0)