Skip to content

Commit 68f2802

Browse files
committed
add variation of the #135246 unsoundness
1 parent b55f9c8 commit 68f2802

File tree

3 files changed

+124
-0
lines changed

3 files changed

+124
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0275]: overflow evaluating the requirement `<Vec<u8> as Trait<String>>::Proof == _`
2+
--> $DIR/item-bound-via-impl-where-clause.rs:24: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:14:12
9+
|
10+
LL | impl<L, R> Trait<R> for L
11+
| ^^^^^^^^ ^
12+
...
13+
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
14+
| ------------------------------------- unsatisfied trait bound introduced here
15+
= note: 1 redundant requirement hidden
16+
= note: required for `Vec<u8>` to implement `Trait<String>`
17+
note: required by a bound in `transmute`
18+
--> $DIR/item-bound-via-impl-where-clause.rs:22:17
19+
|
20+
LL | fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
21+
| ^^^^^^^^ required by this bound in `transmute`
22+
23+
error: aborting due to 1 previous error
24+
25+
For more information about this error, try `rustc --explain E0275`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
error[E0271]: type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
2+
--> $DIR/item-bound-via-impl-where-clause.rs:24:33
3+
|
4+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
5+
| ^ types differ
6+
|
7+
note: required for `String` to implement `Trait<String>`
8+
--> $DIR/item-bound-via-impl-where-clause.rs:14:12
9+
|
10+
LL | impl<L, R> Trait<R> for L
11+
| ^^^^^^^^ ^
12+
...
13+
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
14+
| ------------------------------------- unsatisfied trait bound introduced here
15+
= note: 2 redundant requirements hidden
16+
= note: required for `Vec<u8>` to implement `Trait<String>`
17+
note: required by a bound in `transmute`
18+
--> $DIR/item-bound-via-impl-where-clause.rs:22:17
19+
|
20+
LL | fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
21+
| ^^^^^^^^ required by this bound in `transmute`
22+
23+
error[E0271]: type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
24+
--> $DIR/item-bound-via-impl-where-clause.rs:24:21
25+
|
26+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
27+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
28+
|
29+
note: required for `String` to implement `Trait<String>`
30+
--> $DIR/item-bound-via-impl-where-clause.rs:14:12
31+
|
32+
LL | impl<L, R> Trait<R> for L
33+
| ^^^^^^^^ ^
34+
...
35+
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
36+
| ------------------------------------- unsatisfied trait bound introduced here
37+
= note: 1 redundant requirement hidden
38+
= note: required for `Vec<u8>` to implement `Trait<String>`
39+
note: required by a bound in `Trait`
40+
--> $DIR/item-bound-via-impl-where-clause.rs:11:17
41+
|
42+
LL | trait Trait<R>: Sized {
43+
| ^^^^^ required by this bound in `Trait`
44+
45+
error[E0271]: type mismatch resolving `<String as Trait<String>>::Proof == _`
46+
--> $DIR/item-bound-via-impl-where-clause.rs:24:21
47+
|
48+
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
49+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<String as Trait<String>>::Proof == _`
50+
|
51+
note: types differ
52+
--> $DIR/item-bound-via-impl-where-clause.rs:20:11
53+
|
54+
LL | = R;
55+
| ^
56+
note: required for `String` to implement `Trait<String>`
57+
--> $DIR/item-bound-via-impl-where-clause.rs:14:12
58+
|
59+
LL | impl<L, R> Trait<R> for L
60+
| ^^^^^^^^ ^
61+
...
62+
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
63+
| ------------------------------------- unsatisfied trait bound introduced here
64+
= note: 2 redundant requirements hidden
65+
= note: required for `Vec<u8>` to implement `Trait<String>`
66+
67+
error: aborting due to 3 previous errors
68+
69+
For more information about this error, try `rustc --explain E0271`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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+
// This has never been an unsound and fails with a non-productive
9+
// cycle when normalizing the expected term of the projection goal.
10+
11+
trait Trait<R>: Sized {
12+
type Proof: Trait<R, Proof = Self>;
13+
}
14+
impl<L, R> Trait<R> for L
15+
where
16+
L: Trait<R>,
17+
R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
18+
{
19+
type Proof
20+
= R;
21+
}
22+
fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
23+
fn main() {
24+
let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
25+
//[current]~^ ERROR overflow evaluating the requirement
26+
//[next]~^^ ERROR type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
27+
//[next]~| ERROR type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
28+
//[next]~| ERROR type mismatch resolving `<String as Trait<String>>::Proof == _`
29+
println!("{}", s);
30+
}

0 commit comments

Comments
 (0)