-
Notifications
You must be signed in to change notification settings - Fork 13k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of #110673 - compiler-errors:alias-bounds-2, r=lcnr
Make alias bounds sound in the new solver (take 2) Make alias bounds sound in the new solver (in a way that does not require coinduction) by only considering them for projection types whose corresponding trait refs come from a param-env candidate. That is, given `<T as Trait>::Assoc: Bound`, we only *really* need to consider the alias bound if `T: Trait` is satisfied via a param-env candidate. If it's instead satisfied, e.g., via an user provided impl candidate or a , then that impl should have a concrete type to which we could otherwise normalize `<T as Trait>::Assoc`, and that concrete type is then responsible to prove the `Bound` on it. Similar consideration is given to opaque types, since we only need to consider alias bounds if we're *not* in reveal-all mode, since similarly we'd be able to reveal the opaque types and prove any bounds that way. This does not remove that hacky "eager projection replacement" logic from object bounds, which are somewhat like alias bounds. But removing this eager normalization behavior (added in #108333) would require full coinduction to be enabled. Compare to #110628, which does remove this object-bound custom logic but requires coinduction to be sound. r? `@lcnr`
- Loading branch information
Showing
6 changed files
with
231 additions
and
93 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
|
||
// Makes sure that alias bounds are not unsound! | ||
|
||
#![feature(trivial_bounds)] | ||
|
||
trait Foo { | ||
type Item: Copy | ||
where | ||
<Self as Foo>::Item: Copy; | ||
|
||
fn copy_me(x: &Self::Item) -> Self::Item { | ||
*x | ||
} | ||
} | ||
|
||
impl Foo for () { | ||
type Item = String where String: Copy; | ||
} | ||
|
||
fn main() { | ||
let x = String::from("hello, world"); | ||
drop(<() as Foo>::copy_me(&x)); | ||
//~^ ERROR `<() as Foo>::Item: Copy` is not satisfied | ||
//~| ERROR `<() as Foo>::Item` is not well-formed | ||
println!("{x}"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0277]: the trait bound `<() as Foo>::Item: Copy` is not satisfied | ||
--> $DIR/alias-bound-unsound.rs:23:10 | ||
| | ||
LL | drop(<() as Foo>::copy_me(&x)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Copy` is not implemented for `<() as Foo>::Item` | ||
| | ||
note: required by a bound in `Foo::Item` | ||
--> $DIR/alias-bound-unsound.rs:10:30 | ||
| | ||
LL | type Item: Copy | ||
| ---- required by a bound in this associated type | ||
LL | where | ||
LL | <Self as Foo>::Item: Copy; | ||
| ^^^^ required by this bound in `Foo::Item` | ||
|
||
error: the type `<() as Foo>::Item` is not well-formed | ||
--> $DIR/alias-bound-unsound.rs:23:10 | ||
| | ||
LL | drop(<() as Foo>::copy_me(&x)); | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0277`. |
Oops, something went wrong.