Skip to content

Compute the result of a projection type with region errors#153105

Merged
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
makai410:erase-if-error
Apr 2, 2026
Merged

Compute the result of a projection type with region errors#153105
rust-bors[bot] merged 2 commits intorust-lang:mainfrom
makai410:erase-if-error

Conversation

@makai410
Copy link
Copy Markdown
Member

@makai410 makai410 commented Feb 25, 2026

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

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Feb 25, 2026
@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Feb 25, 2026

r? @petrochenkov

rustbot has assigned @petrochenkov.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: compiler
  • compiler expanded to 68 candidates
  • Random selection from 14 candidates

Comment on lines +13 to +40
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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway these errors will be triggered if the code don't have the lifetime error, so

@petrochenkov
Copy link
Copy Markdown
Contributor

r? types

@rustbot rustbot added the T-types Relevant to the types team, which will review and decide on the PR/issue. label Feb 26, 2026
@rustbot rustbot assigned lcnr and unassigned petrochenkov Feb 26, 2026
Copy link
Copy Markdown
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 🤔

View changes since this review

@makai410
Copy link
Copy Markdown
Member Author

but then during const eval we normalize differently and don't get a type error as the output?

Yeah since they get the ty using normalize_erasing_regions which wont return a type error in this case.

@makai410
Copy link
Copy Markdown
Member Author

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 🤔

cool I'm going to try this to see if it would cause any regressions or something.

@makai410 makai410 changed the title Erase regions if there are any region errors when collecting predicates Compute the result of a projection type with region errors Mar 8, 2026
@makai410
Copy link
Copy Markdown
Member Author

makai410 commented Mar 8, 2026

@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 {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that name is very confusing I would expect that to be TypeFlags::HAS_TY_OR_CONST_ERROR same as has_non_region_infer

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right now this is "has_no_region_error", which also still breaks if you have both a region error and a proper type error

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I split TypeFlags::HAS_ERROR into TypeFlags::HAS_TY_OR_CONST_ERROR and TypeFlags::HAS_RE_ERROR, which should cover the case.

Copy link
Copy Markdown
Contributor

@lcnr lcnr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could just be Err(guar) = obligation.predicate.non_region_error_reported()

@@ -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;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const HAS_TY_OR_CT_ERROR = 1 << 15;
const HAS_NON_REGION_ERROR = 1 << 15;

@rustbot

This comment has been minimized.

@rustbot
Copy link
Copy Markdown
Collaborator

rustbot commented Apr 1, 2026

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.

@makai410
Copy link
Copy Markdown
Member Author

makai410 commented Apr 1, 2026

@bors r=lcnr

@rust-bors
Copy link
Copy Markdown
Contributor

rust-bors bot commented Apr 1, 2026

📌 Commit 339fb64 has been approved by lcnr

It is now in the queue for this repository.

@rust-bors rust-bors bot added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Apr 1, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 1, 2026
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
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Apr 1, 2026
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
rust-bors bot pushed a commit that referenced this pull request Apr 1, 2026
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)
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 2, 2026
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
rust-bors bot pushed a commit that referenced this pull request Apr 2, 2026
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)
jhpratt added a commit to jhpratt/rust that referenced this pull request Apr 2, 2026
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
rust-bors bot pushed a commit that referenced this pull request Apr 2, 2026
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)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 2, 2026
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
rust-bors bot pushed a commit that referenced this pull request Apr 2, 2026
…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`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Apr 2, 2026
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
rust-bors bot pushed a commit that referenced this pull request Apr 2, 2026
…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`)
rust-bors bot pushed a commit that referenced this pull request Apr 2, 2026
…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`)
@rust-bors rust-bors bot merged commit 828e302 into rust-lang:main Apr 2, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Apr 2, 2026
rust-timer added a commit that referenced this pull request Apr 2, 2026
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
github-actions bot pushed a commit to rust-lang/miri that referenced this pull request Apr 3, 2026
…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`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: expected wide pointer extra data (e.g. slice length or trait object vtable) (missing lifetime)

4 participants