Erase regions if there are any region errors when collecting predicates#153105
Erase regions if there are any region errors when collecting predicates#153105makai410 wants to merge 2 commits intorust-lang:mainfrom
Conversation
|
rustbot has assigned @petrochenkov. Use Why was this reviewer chosen?The reviewer was selected based on:
|
| error[E0277]: the size for values of type `[&usize]` cannot be known at compilation time | ||
| --> $DIR/ice-unsized-struct-const-eval-123154.rs:14:1 | ||
| | | ||
| LL | static ST: AA = AA::new(); | ||
| | ^^^^^^^^^^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: within `AA`, the trait `Sized` is not implemented for `[&usize]` | ||
| note: required because it appears within the type `AA` | ||
| --> $DIR/ice-unsized-struct-const-eval-123154.rs:3:8 | ||
| | | ||
| LL | struct AA { | ||
| | ^^ | ||
| = note: statics and constants must have a statically known size | ||
|
|
||
| error[E0277]: the size for values of type `[&usize]` cannot be known at compilation time | ||
| --> $DIR/ice-unsized-struct-const-eval-123154.rs:9:23 | ||
| | | ||
| LL | const fn new() -> Self { } | ||
| | ^^^^ doesn't have a size known at compile-time | ||
| | | ||
| = help: within `AA`, the trait `Sized` is not implemented for `[&usize]` | ||
| note: required because it appears within the type `AA` | ||
| --> $DIR/ice-unsized-struct-const-eval-123154.rs:3:8 | ||
| | | ||
| LL | struct AA { | ||
| | ^^ | ||
| = note: the return type of a function must have a statically known size | ||
|
|
There was a problem hiding this comment.
Anyway these errors will be triggered if the code don't have the lifetime error, so
|
r? types |
There was a problem hiding this comment.
so what's happening here is that type_is_sized_modulo_regions encounters a field of type ty::Error as normalizing <&'re_error [fn()] as core::ops::Deref>::Target results in a type error,
but then during const eval we normalize differently and don't get a type error as the output?
I feel like erasing error regions this way seems... unfortunate and maybe we should instead change the trait solver/type system to check for HAS_NON_REGION_ERROR when creating type errors 🤔
Yeah since they get the ty using |
cool I'm going to try this to see if it would cause any regressions or something. |
Fixes: #152682
With the old trait solver,
type_known_to_meet_bound_modulo_regions()isn't really operating "modulo regions" if there are any region errors, sincenormalizewill just return a type error to the trait solver if given a ty with a region error, which then starts cascading when there are so many assumptions.So I think it would be good to erase regions if there are any region errors before we normalize the type when collecting predicates for confirmation.
That said, I somehow feel like this is kind of ad-hoc... I'd really appreciate if someone more familiar with this code could take a closer look :3