forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#111623 - BoxyUwU:move_eval_hack, r=compiler-e…
…rrors move `super_relate_consts` hack to `normalize_param_env_or_error` `super_relate_consts` has as hack in it to work around the fact that `normalize_param_env_or_error` is broken. When relating two constants we attempt to evaluate them (aka normalize them). This is not an issue in any way specific to const generics, type aliases also have the same issue as demonstrated in [this code](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=84b6d3956a2c852a04b60782476b56c9). Since the hack in `super_relate_consts` only exists to make `normalize_param_env_or_error` emit less errors move it to `normalize_param_env_or_error`. This makes `super_relate_consts` act more like the normal plain structural equality its supposed to and should help ensure that the hack doesnt accidentally affect other situations. r? `@compiler-errors`
- Loading branch information
Showing
3 changed files
with
81 additions
and
16 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,35 @@ | ||
// compile-flags: -Ztrait-solver=next | ||
// check-pass | ||
|
||
#[derive(Default)] | ||
struct Foo { | ||
x: i32, | ||
} | ||
|
||
impl MyDefault for Foo { | ||
fn my_default() -> Self { | ||
Self { | ||
x: 0, | ||
} | ||
} | ||
} | ||
|
||
trait MyDefault { | ||
fn my_default() -> Self; | ||
} | ||
|
||
impl MyDefault for [Foo; 0] { | ||
fn my_default() -> Self { | ||
[] | ||
} | ||
} | ||
impl MyDefault for [Foo; 1] { | ||
fn my_default() -> Self { | ||
[Foo::my_default(); 1] | ||
} | ||
} | ||
|
||
fn main() { | ||
let mut xs = <[Foo; 1]>::default(); | ||
let mut xs = <[Foo; 1]>::my_default(); | ||
xs[0].x = 1; | ||
(&mut xs[0]).x = 2; | ||
} |