Skip to content

Replace infers and non-rigid aliases with Ty/Const::Error if param env normalization fails - #160856

Merged
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
adwinwhite:param-env-norm-fail-with-err
Aug 13, 2026
Merged

Replace infers and non-rigid aliases with Ty/Const::Error if param env normalization fails#160856
rust-bors[bot] merged 1 commit into
rust-lang:mainfrom
adwinwhite:param-env-norm-fail-with-err

Conversation

@adwinwhite

@adwinwhite adwinwhite commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

View all comments

Fixes #160196
Fixes #148630

Previously we use unnormalized param env if we fail to normalize it. This causes problem for places which expect normalized param env, like in lexical region solving.

I also sneak in a one-line change that we resolve regions with normalized param env in param env normalization now.
This fixes ICEs in polkadot and zerocopy which had non-rigid const aliases in type outlive env before. I can split it into another PR if that's preferred.

r? lcnr

@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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Aug 10, 2026
@adwinwhite

Copy link
Copy Markdown
Contributor Author

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 10, 2026
@rust-bors

This comment has been minimized.

rust-bors Bot pushed a commit that referenced this pull request Aug 10, 2026
Replace infers and non-rigid aliases with `Ty/Const::Error` if param env normalization fails
@rust-log-analyzer

This comment has been minimized.

@rust-bors

rust-bors Bot commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

☀️ Try build successful (CI)
Build commit: 63c3ea0 (63c3ea08d1963147f00c41c604e746c02103f144)
Base parent: 7088e4b (7088e4b63a9516ebfbfe2ab2d999cf01a528ac14)

@rust-timer

This comment has been minimized.

@rust-timer

Copy link
Copy Markdown
Collaborator

Finished benchmarking commit (63c3ea0): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking means the PR may be perf-sensitive. Consider adding rollup=never if this change is not fit for rolling up.

@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This perf run didn't have relevant results for this metric.

Max RSS (memory usage)

Results (primary 1.4%, secondary 0.3%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
1.4% [1.4%, 1.4%] 1
Regressions ❌
(secondary)
2.5% [0.5%, 6.1%] 3
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.6% [-0.8%, -0.4%] 8
All ❌✅ (primary) 1.4% [1.4%, 1.4%] 1

Cycles

Results (secondary 0.1%)

A less reliable metric. May be of interest, but not used to determine the overall result above.

mean range count
Regressions ❌
(primary)
- - 0
Regressions ❌
(secondary)
0.8% [0.4%, 1.5%] 10
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
-0.8% [-1.6%, -0.4%] 7
All ❌✅ (primary) - - 0

Binary size

This perf run didn't have relevant results for this metric.

Bootstrap: 455.179s -> 456.527s (0.30%)
Artifact size: 398.37 MiB -> 398.42 MiB (0.01%)

@rustbot rustbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Aug 10, 2026
_ => ty,
}
},
lt_op: |lt| lt,

@lcnr lcnr Aug 10, 2026

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 have to deal with infer regions here, don't we? 🤔

/ does fully_resolve even make sense as an abstraction? it's a version of resolve_vars_if_possible which also looks at the region graph?

View changes since the review

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

We already replace unresolved region infers with Region::Error in fully_resolve.

it's a version of resolve_vars_if_possible which also looks at the region graph?

Yap, another difference is that it eagerly returns with 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.

doesn't that mean this incorrectly handles having both unresolved regions and an unresolved ty var? because it keeps the unresolved region

unsure when exactly fully_resolve errors here

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.

also, can you move these folders into a separate replace_infer_and_non_rigid_alias_with_error function or sth 🤔

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

doesn't that mean this incorrectly handles having both unresolved regions and an unresolved ty var? because it keeps the unresolved region

What do you mean? fully_resolve itself would replace unresolved region and return Ok with delayed error.

unsure when exactly fully_resolve errors here

Yeah, it's not obvious.
It errors when the clauses contain ty vars or const vars which would happen if we don't have normalization failure but have ill-formed impls like impl<T> Trait for () where the generic parameter is unused. I have a comment about this above but it doesn't mention what the impl would look like.
See tests/ui/traits/normalize/self-referential-param-env-normalization.rs

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

also, can you move these folders into a separate replace_infer_and_non_rigid_alias_with_error function or sth 🤔

The two folders are slightly different. Unsure we should fold non-rigid aliases to error if we don't have normalization failure. Those non-rigid aliases can come from opaques. Maybe we can still do that since we're on a failed code path anyway. Could cause some spurious failures? 🤔

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.

What do you mean? fully_resolve itself would replace unresolved region and return Ok with delayed error.

if fully_resolve has both unresolved regions (which it replaced) and an unresolved type (which causes it to return an Err), then wouldn't we fold over the type without the unresolved region replaced?

@lcnr lcnr left a comment

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.

one slightly confusing thing, otherwise r=me

View changes since this review

@adwinwhite
adwinwhite force-pushed the param-env-norm-fail-with-err branch from ea6993b to ef03c32 Compare August 11, 2026 02:49
@rust-log-analyzer

This comment has been minimized.

@adwinwhite
adwinwhite force-pushed the param-env-norm-fail-with-err branch from ef03c32 to d79e9fd Compare August 11, 2026 04:44
@rustbot

rustbot commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

This PR changes a file inside tests/crashes. If a crash was fixed, please move into the corresponding ui subdir and add 'Fixes #' to the PR description to autoclose the issue upon merge.

@rust-log-analyzer

This comment has been minimized.

@adwinwhite
adwinwhite force-pushed the param-env-norm-fail-with-err branch 2 times, most recently from 7b33584 to 14870df Compare August 12, 2026 02:17
})
}

enum ReplaceRegion {

@lcnr lcnr Aug 12, 2026

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
enum ReplaceRegion {
enum ReplaceRegions {

View changes since the review

Comment on lines +301 to +302
// We can't resolve regions using lexical resolution here since that's
// private. It probably doesn't matter since we already got more severe error.

@lcnr lcnr Aug 12, 2026

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.

vibe, want to move this above the ReplaceRegions::Yes as that should make the formatting slightly nicer here

View changes since the review

Comment on lines +400 to +401
// FIXME: We should avoid interning clauses both here and at the caller sites. We should also
// avoid cloning if possible.

@lcnr lcnr Aug 12, 2026

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
// FIXME: We should avoid interning clauses both here and at the caller sites. We should also
// avoid cloning if possible.
// FIXME: We should avoid interning clauses both here and at the
// caller sites. We should also avoid cloning if possible.

minor formatting nit, the lines are very long here in general :<

View changes since the review

@lcnr lcnr left a comment

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.

r=me after style nits

View changes since this review

@adwinwhite
adwinwhite force-pushed the param-env-norm-fail-with-err branch from 14870df to 51ef2f2 Compare August 13, 2026 03:45
@adwinwhite

Copy link
Copy Markdown
Contributor Author

@bors r=lcnr

@rust-bors

rust-bors Bot commented Aug 13, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 51ef2f2 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 Aug 13, 2026
rust-bors Bot pushed a commit that referenced this pull request Aug 13, 2026
Rollup of 8 pull requests

Successful merges:

 - #159593 (merge ambiguity errors that blame the same inference variable)
 - #160687 (Experiment: Add `core::cmp::smallest` and `core::cmp::largest`)
 - #160856 (Replace infers and non-rigid aliases with `Ty/Const::Error` if param env normalization fails)
 - #160961 (bootstrap: Overhaul matching of command-line selectors to steps)
 - #160975 (Remove target argument from get_proc_macros)
 - #161023 (bootstrap: Replace the `exit!` macro with a function `helpers::exit_process`)
 - #160932 (Make tidy::Version public)
 - #161029 (mailmap: Update my default email)
@rust-bors
rust-bors Bot merged commit 1f0923d into rust-lang:main Aug 13, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Aug 13, 2026
rust-timer added a commit that referenced this pull request Aug 13, 2026
Rollup merge of #160856 - adwinwhite:param-env-norm-fail-with-err, r=lcnr

Replace infers and non-rigid aliases with `Ty/Const::Error` if param env normalization fails

Fixes #160196
Fixes #148630

Previously we use unnormalized param env if we fail to normalize it. This causes problem for places which expect normalized param env, like in lexical region solving.

I also sneak in a one-line change that we resolve regions with normalized param env in param env normalization now.
This fixes ICEs in `polkadot` and `zerocopy` which had non-rigid const aliases in type outlive env before. I can split it into another PR if that's preferred.

r? lcnr
rust-bors Bot pushed a commit that referenced this pull request Aug 14, 2026
replace infers and non-rigid aliases with `Ty/Const::Error`
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. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[ICE]: !infcx.next_trait_solver() || !type_outlives.has_non_rigid_aliases() ICE: Unexpected node Synthetic

5 participants