Compute the result of a projection type with region errors#153105
Compute the result of a projection type with region errors#153105rust-bors[bot] merged 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. |
|
@rustbot ready |
| @@ -352,6 +352,11 @@ pub trait TypeVisitableExt<I: Interner>: TypeVisitable<I> { | |||
| fn still_further_specializable(&self) -> bool { | |||
| self.has_type_flags(TypeFlags::STILL_FURTHER_SPECIALIZABLE) | |||
| } | |||
|
|
|||
| /// True if there is no region error | |||
| fn has_non_region_error(&self) -> bool { | |||
There was a problem hiding this comment.
that name is very confusing I would expect that to be TypeFlags::HAS_TY_OR_CONST_ERROR same as has_non_region_infer
There was a problem hiding this comment.
right now this is "has_no_region_error", which also still breaks if you have both a region error and a proper type error
There was a problem hiding this comment.
I split TypeFlags::HAS_ERROR into TypeFlags::HAS_TY_OR_CONST_ERROR and TypeFlags::HAS_RE_ERROR, which should cover the case.
94c3811 to
7840805
Compare
| if let Err(guar) = obligation.predicate.error_reported() { | ||
| // We can still compute a projection type when there are only region errors, | ||
| // but type/const errors require early return. | ||
| if obligation.predicate.has_type_or_const_error() |
There was a problem hiding this comment.
we tend to use has_non_region_X instead of type_or_const
| // We can still compute a projection type when there are only region errors, | ||
| // but type/const errors require early return. | ||
| if obligation.predicate.has_type_or_const_error() | ||
| && let Err(guar) = obligation.predicate.error_reported() |
There was a problem hiding this comment.
could just be Err(guar) = obligation.predicate.non_region_error_reported()
compiler/rustc_type_ir/src/flags.rs
Outdated
| @@ -91,27 +91,32 @@ bitflags::bitflags! { | |||
| | TypeFlags::HAS_TY_INHERENT.bits() | |||
| | TypeFlags::HAS_CT_PROJECTION.bits(); | |||
|
|
|||
| /// Is a type or const error reachable? | |||
| const HAS_TY_OR_CT_ERROR = 1 << 15; | |||
There was a problem hiding this comment.
| const HAS_TY_OR_CT_ERROR = 1 << 15; | |
| const HAS_NON_REGION_ERROR = 1 << 15; |
This comment has been minimized.
This comment has been minimized.
|
This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed. Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers. |
|
@bors r=lcnr |
Compute the result of a projection type with region errors Fixes: rust-lang#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, since `normalize` will 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
Compute the result of a projection type with region errors Fixes: rust-lang#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, since `normalize` will 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
Rollup of 7 pull requests Successful merges: - #153105 (Compute the result of a projection type with region errors) - #153960 (Make `layout_of` cycles fatal errors) - #154666 (Remove `StableHashContext` impls) - #154669 (Introduce #[diagnostic::on_move] on `Arc`) - #154442 (Export `derive` at the crate root: `core::derive` and `std::derive`) - #154660 (Avoid creating async return opaques for foreign async fns) - #154680 ([rustdoc] Replace `DocContext` with `TyCtxt` wherever possible)
Compute the result of a projection type with region errors Fixes: rust-lang#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, since `normalize` will 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
Rollup of 11 pull requests Successful merges: - #153105 (Compute the result of a projection type with region errors) - #153286 (various fixes for scalable vectors) - #153960 (Make `layout_of` cycles fatal errors) - #154527 (Emit pre-expansion feature gate warnings for negative impls and specialization) - #154666 (Remove `StableHashContext` impls) - #154669 (Introduce #[diagnostic::on_move] on `Arc`) - #154442 (Export `derive` at the crate root: `core::derive` and `std::derive`) - #154644 (rustdoc: seperate methods and associated functions in sidebar) - #154660 (Avoid creating async return opaques for foreign async fns) - #154671 (Add a test for a past ICE when calling a const fn of an unresolved type with the wrong number of args) - #154680 ([rustdoc] Replace `DocContext` with `TyCtxt` wherever possible)
Compute the result of a projection type with region errors Fixes: rust-lang#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, since `normalize` will 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
Rollup of 11 pull requests Successful merges: - #153105 (Compute the result of a projection type with region errors) - #153960 (Make `layout_of` cycles fatal errors) - #154527 (Emit pre-expansion feature gate warnings for negative impls and specialization) - #154666 (Remove `StableHashContext` impls) - #154669 (Introduce #[diagnostic::on_move] on `Arc`) - #154213 (tidy-alphabetical: fix line number in error message) - #154442 (Export `derive` at the crate root: `core::derive` and `std::derive`) - #154644 (rustdoc: seperate methods and associated functions in sidebar) - #154660 (Avoid creating async return opaques for foreign async fns) - #154671 (Add a test for a past ICE when calling a const fn of an unresolved type with the wrong number of args) - #154680 ([rustdoc] Replace `DocContext` with `TyCtxt` wherever possible)
Compute the result of a projection type with region errors Fixes: rust-lang#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, since `normalize` will 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
…uwer Rollup of 21 pull requests Successful merges: - #153105 (Compute the result of a projection type with region errors) - #153286 (various fixes for scalable vectors) - #153532 (Attributes containing rustc) - #153960 (Make `layout_of` cycles fatal errors) - #154527 (Emit pre-expansion feature gate warnings for negative impls and specialization) - #154666 (Remove `StableHashContext` impls) - #154669 (Introduce #[diagnostic::on_move] on `Arc`) - #154710 (opaque_generic_const_args -> generic_const_args) - #154712 (Revert "`-Znext-solver` Remove the forced ambiguity hack from search graph") - #154713 (Stop compiling when we get resolving crate failure) - #154213 (tidy-alphabetical: fix line number in error message) - #154425 (Migrate transmute tests) - #154442 (Export `derive` at the crate root: `core::derive` and `std::derive`) - #154469 (mGCA: Lower spans for literal const args) - #154578 (Rename `probe_ty_var` to `try_resolve_ty_var`) - #154615 (Moving issues) - #154644 (rustdoc: seperate methods and associated functions in sidebar) - #154660 (Avoid creating async return opaques for foreign async fns) - #154671 (Add a test for a past ICE when calling a const fn of an unresolved type with the wrong number of args) - #154680 ([rustdoc] Replace `DocContext` with `TyCtxt` wherever possible) - #154709 (Revert `Ty` type alias in `rustc_type_ir`)
Compute the result of a projection type with region errors Fixes: rust-lang#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, since `normalize` will 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
…uwer Rollup of 21 pull requests Successful merges: - #153105 (Compute the result of a projection type with region errors) - #153286 (various fixes for scalable vectors) - #153532 (Attributes containing rustc) - #153960 (Make `layout_of` cycles fatal errors) - #154527 (Emit pre-expansion feature gate warnings for negative impls and specialization) - #154666 (Remove `StableHashContext` impls) - #154669 (Introduce #[diagnostic::on_move] on `Arc`) - #154710 (opaque_generic_const_args -> generic_const_args) - #154712 (Revert "`-Znext-solver` Remove the forced ambiguity hack from search graph") - #153614 (`FindParamInClause` handle edge-cases) - #154213 (tidy-alphabetical: fix line number in error message) - #154425 (Migrate transmute tests) - #154442 (Export `derive` at the crate root: `core::derive` and `std::derive`) - #154469 (mGCA: Lower spans for literal const args) - #154578 (Rename `probe_ty_var` to `try_resolve_ty_var`) - #154615 (Moving issues) - #154644 (rustdoc: seperate methods and associated functions in sidebar) - #154660 (Avoid creating async return opaques for foreign async fns) - #154671 (Add a test for a past ICE when calling a const fn of an unresolved type with the wrong number of args) - #154680 ([rustdoc] Replace `DocContext` with `TyCtxt` wherever possible) - #154709 (Revert `Ty` type alias in `rustc_type_ir`)
…uwer Rollup of 20 pull requests Successful merges: - #153105 (Compute the result of a projection type with region errors) - #153532 (Attributes containing rustc) - #153960 (Make `layout_of` cycles fatal errors) - #154527 (Emit pre-expansion feature gate warnings for negative impls and specialization) - #154666 (Remove `StableHashContext` impls) - #154669 (Introduce #[diagnostic::on_move] on `Arc`) - #154710 (opaque_generic_const_args -> generic_const_args) - #154712 (Revert "`-Znext-solver` Remove the forced ambiguity hack from search graph") - #153614 (`FindParamInClause` handle edge-cases) - #154213 (tidy-alphabetical: fix line number in error message) - #154425 (Migrate transmute tests) - #154442 (Export `derive` at the crate root: `core::derive` and `std::derive`) - #154469 (mGCA: Lower spans for literal const args) - #154578 (Rename `probe_ty_var` to `try_resolve_ty_var`) - #154615 (Moving issues) - #154644 (rustdoc: seperate methods and associated functions in sidebar) - #154660 (Avoid creating async return opaques for foreign async fns) - #154671 (Add a test for a past ICE when calling a const fn of an unresolved type with the wrong number of args) - #154680 ([rustdoc] Replace `DocContext` with `TyCtxt` wherever possible) - #154709 (Revert `Ty` type alias in `rustc_type_ir`)
Rollup merge of #153105 - makai410:erase-if-error, r=lcnr Compute the result of a projection type with region errors 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, since `normalize` will 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
…uwer Rollup of 20 pull requests Successful merges: - rust-lang/rust#153105 (Compute the result of a projection type with region errors) - rust-lang/rust#153532 (Attributes containing rustc) - rust-lang/rust#153960 (Make `layout_of` cycles fatal errors) - rust-lang/rust#154527 (Emit pre-expansion feature gate warnings for negative impls and specialization) - rust-lang/rust#154666 (Remove `StableHashContext` impls) - rust-lang/rust#154669 (Introduce #[diagnostic::on_move] on `Arc`) - rust-lang/rust#154710 (opaque_generic_const_args -> generic_const_args) - rust-lang/rust#154712 (Revert "`-Znext-solver` Remove the forced ambiguity hack from search graph") - rust-lang/rust#153614 (`FindParamInClause` handle edge-cases) - rust-lang/rust#154213 (tidy-alphabetical: fix line number in error message) - rust-lang/rust#154425 (Migrate transmute tests) - rust-lang/rust#154442 (Export `derive` at the crate root: `core::derive` and `std::derive`) - rust-lang/rust#154469 (mGCA: Lower spans for literal const args) - rust-lang/rust#154578 (Rename `probe_ty_var` to `try_resolve_ty_var`) - rust-lang/rust#154615 (Moving issues) - rust-lang/rust#154644 (rustdoc: seperate methods and associated functions in sidebar) - rust-lang/rust#154660 (Avoid creating async return opaques for foreign async fns) - rust-lang/rust#154671 (Add a test for a past ICE when calling a const fn of an unresolved type with the wrong number of args) - rust-lang/rust#154680 ([rustdoc] Replace `DocContext` with `TyCtxt` wherever possible) - rust-lang/rust#154709 (Revert `Ty` type alias in `rustc_type_ir`)
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