Skip to content

Commit

Permalink
add variation of the rust-lang#135246 unsoundness
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Feb 13, 2025
1 parent b55f9c8 commit 68f2802
Show file tree
Hide file tree
Showing 3 changed files with 124 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
error[E0275]: overflow evaluating the requirement `<Vec<u8> as Trait<String>>::Proof == _`
--> $DIR/item-bound-via-impl-where-clause.rs:24:21
|
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: required for `Vec<u8>` to implement `Trait<String>`
--> $DIR/item-bound-via-impl-where-clause.rs:14:12
|
LL | impl<L, R> Trait<R> for L
| ^^^^^^^^ ^
...
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
| ------------------------------------- unsatisfied trait bound introduced here
= note: 1 redundant requirement hidden
= note: required for `Vec<u8>` to implement `Trait<String>`
note: required by a bound in `transmute`
--> $DIR/item-bound-via-impl-where-clause.rs:22:17
|
LL | fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
| ^^^^^^^^ required by this bound in `transmute`

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0275`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
error[E0271]: type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
--> $DIR/item-bound-via-impl-where-clause.rs:24:33
|
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
| ^ types differ
|
note: required for `String` to implement `Trait<String>`
--> $DIR/item-bound-via-impl-where-clause.rs:14:12
|
LL | impl<L, R> Trait<R> for L
| ^^^^^^^^ ^
...
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
| ------------------------------------- unsatisfied trait bound introduced here
= note: 2 redundant requirements hidden
= note: required for `Vec<u8>` to implement `Trait<String>`
note: required by a bound in `transmute`
--> $DIR/item-bound-via-impl-where-clause.rs:22:17
|
LL | fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
| ^^^^^^^^ required by this bound in `transmute`

error[E0271]: type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
--> $DIR/item-bound-via-impl-where-clause.rs:24:21
|
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ types differ
|
note: required for `String` to implement `Trait<String>`
--> $DIR/item-bound-via-impl-where-clause.rs:14:12
|
LL | impl<L, R> Trait<R> for L
| ^^^^^^^^ ^
...
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
| ------------------------------------- unsatisfied trait bound introduced here
= note: 1 redundant requirement hidden
= note: required for `Vec<u8>` to implement `Trait<String>`
note: required by a bound in `Trait`
--> $DIR/item-bound-via-impl-where-clause.rs:11:17
|
LL | trait Trait<R>: Sized {
| ^^^^^ required by this bound in `Trait`

error[E0271]: type mismatch resolving `<String as Trait<String>>::Proof == _`
--> $DIR/item-bound-via-impl-where-clause.rs:24:21
|
LL | let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ type mismatch resolving `<String as Trait<String>>::Proof == _`
|
note: types differ
--> $DIR/item-bound-via-impl-where-clause.rs:20:11
|
LL | = R;
| ^
note: required for `String` to implement `Trait<String>`
--> $DIR/item-bound-via-impl-where-clause.rs:14:12
|
LL | impl<L, R> Trait<R> for L
| ^^^^^^^^ ^
...
LL | R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
| ------------------------------------- unsatisfied trait bound introduced here
= note: 2 redundant requirements hidden
= note: required for `Vec<u8>` to implement `Trait<String>`

error: aborting due to 3 previous errors

For more information about this error, try `rustc --explain E0271`.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//@ revisions: current next
//@ ignore-compare-mode-next-solver (explicit revisions)
//@[next] compile-flags: -Znext-solver

// A variation of #135246 where the cyclic bounds are part of
// the impl instead of the impl associated item.
//
// This has never been an unsound and fails with a non-productive
// cycle when normalizing the expected term of the projection goal.

trait Trait<R>: Sized {
type Proof: Trait<R, Proof = Self>;
}
impl<L, R> Trait<R> for L
where
L: Trait<R>,
R: Trait<R, Proof = <L::Proof as Trait<R>>::Proof>
{
type Proof
= R;
}
fn transmute<L: Trait<R>, R>(r: L) -> <L::Proof as Trait<R>>::Proof { r }
fn main() {
let s: String = transmute::<_, String>(vec![65_u8, 66, 67]);
//[current]~^ ERROR overflow evaluating the requirement
//[next]~^^ ERROR type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
//[next]~| ERROR type mismatch resolving `<String as Trait<String>>::Proof normalizes-to String`
//[next]~| ERROR type mismatch resolving `<String as Trait<String>>::Proof == _`
println!("{}", s);
}

0 comments on commit 68f2802

Please sign in to comment.