Skip to content

Conversation

@nnethercote
Copy link
Contributor

Various cleanups I found while reading this code closely, mostly involving folding and the use of ReErased.

r? @lcnr

@rustbot
Copy link
Collaborator

rustbot commented Jan 9, 2026

Some changes occurred in src/tools/clippy

cc @rust-lang/clippy

Some changes occurred to the core trait solver

cc @rust-lang/initiative-trait-system-refactor

Some changes occurred to the CTFE / Miri interpreter

cc @rust-lang/miri

Some changes occurred to the CTFE machinery

cc @RalfJung, @oli-obk, @lcnr

rust-analyzer is developed in its own repository. If possible, consider making this change to rust-lang/rust-analyzer instead.

cc @rust-lang/rust-analyzer

@rustbot rustbot added A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Jan 9, 2026
@rust-log-analyzer

This comment has been minimized.

&self,
_dst: Ty<'db>,
_src: Ty<'db>,
_dst: Ty<'db>,
Copy link
Member

Choose a reason for hiding this comment

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

Nb.: we're currently using an older version of rustc_next_trait_solver (from crates.io), but this is fine because it's a no-op.

assert!(!outlives_predicate.has_escaping_bound_vars());
let erased_outlives_predicate = tcx.erase_and_anonymize_regions(outlives_predicate);
let outlives_ty = erased_outlives_predicate.skip_binder().0;
let outlives_ty = tcx.erase_and_anonymize_regions(outlives_predicate.skip_binder().0);
Copy link
Contributor

Choose a reason for hiding this comment

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

that impacts behavior. for<'a> Ty<'a, 'param> currently gets changed to Ty<'bound0, 'erased> but now stays as Ty<'a, 'erased> where bound0 and 'a are escaping bound region.

This doesn't matter as we need to special case the bound regions of the outlives predicate anyways and use a hashmap for them in MatchAgainstHigherRankedOutlives.

hmm. I am not too happy about this. I like having all regions in there anonymized, even if it doesn't matter. If we anonymize, we could use a SmallVec instead of a hashmap here 🤷 idk if this is in any way perf relevant, i'd guess not.

Please either revert this commit, or add a comment that we don't anonymize the escaping bound regions, but that this is fine as MatchAgainstHigherRankedOutlives handles them specially anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll just remove the change. I wasn't intending to change behaviour.

let ty = tcx.type_of(variant.tail().did).instantiate_identity();
let ty = tcx.erase_and_anonymize_regions(ty);
assert!(!ty.has_infer());
assert!(!ty.has_type_flags(TypeFlags::HAS_TY_INFER | TypeFlags::HAS_CT_INFER));
Copy link
Contributor

Choose a reason for hiding this comment

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

!ty.has_non_region_infer()? though 🤷 that assert is unnecessary, ty is the output of a query. It never has infer vars

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I'll remove the assertion

) -> Result<Certainty, NoSolution> {
// Erase regions because we compute layouts in `rustc_transmute`,
// which will ICE for region vars.
let (dst, src) = self.tcx.erase_and_anonymize_regions((dst, src));
Copy link
Contributor

Choose a reason for hiding this comment

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

it's not about looking at regions, we do call layout_of for types here though... surprised that removing this doesn't cause test failures.,

Do you encounter region vars here? if so, why does fn is_transmutable not ICE when calling Tree::from_ty

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll just remove this commit.

@lcnr
Copy link
Contributor

lcnr commented Jan 11, 2026

some thoughts, otherwise r=me

@lcnr lcnr closed this Jan 11, 2026
@rustbot rustbot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2026
@lcnr lcnr reopened this Jan 11, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2026
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

Because these folders only change regions.

Note: `BottomUpFolder` folds all regions, while `fold_regions` skips
some bound regions. But that's ok because these two folders only modify
`ReVar`s.
The exact same call appears earlier in this function.
The only thing we do with the result is consult the `.def_id` field,
which is unaffected by `erase_and_anonymize_regions`.
- Remove the vacuous `Types`, which provides extremely little value.
- Make sure `src` comes before `dst` in all transmute-related functions.
  (Currently it's a mix: sometimes `src` is first, sometimes it is
  second`.)
It duplicates `has_erased_regions` from the compiler.
@rustbot
Copy link
Collaborator

rustbot commented Jan 11, 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.

@nnethercote
Copy link
Contributor Author

I removed the commits mentioned in the reviews, and a couple more involving needs_drops because there is an assert within that function that checks for erased regions. With those changes, this meets the r=me conditions above. Thanks for the review!

@bors r=lcnr

@rust-bors rust-bors bot added the S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. label Jan 11, 2026
@rust-bors
Copy link
Contributor

rust-bors bot commented Jan 11, 2026

📌 Commit e7036b1 has been approved by lcnr

It is now in the queue for this repository.

@rust-bors rust-bors bot removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jan 11, 2026
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jan 12, 2026
Folding/`ReErased` cleanups

Various cleanups I found while reading this code closely, mostly involving folding and the use of `ReErased`.

r? @lcnr
rust-bors bot added a commit that referenced this pull request Jan 12, 2026
Rollup of 5 pull requests

Successful merges:

 - #150861 (Folding/`ReErased` cleanups)
 - #150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping)
 - #150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items))
 - #150980 (Use updated indexes to build reverse map for delegation generics)
 - #150986 (std: Fix size returned by UEFI tcp4 read operations)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 12, 2026
Rollup of 8 pull requests

Successful merges:

 - #150861 (Folding/`ReErased` cleanups)
 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)
 - #150920 (Use a hook to decouple `rustc_mir_transform` from `rustc_mir_build`)
 - #150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping)
 - #150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items))
 - #150980 (Use updated indexes to build reverse map for delegation generics)
 - #150986 (std: Fix size returned by UEFI tcp4 read operations)
 - #150996 (Remove `S-waiting-on-bors` after a PR is merged)

r? @ghost
rust-bors bot pushed a commit that referenced this pull request Jan 12, 2026
Rollup of 8 pull requests

Successful merges:

 - #150861 (Folding/`ReErased` cleanups)
 - #150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)
 - #150920 (Use a hook to decouple `rustc_mir_transform` from `rustc_mir_build`)
 - #150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping)
 - #150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items))
 - #150980 (Use updated indexes to build reverse map for delegation generics)
 - #150986 (std: Fix size returned by UEFI tcp4 read operations)
 - #150996 (Remove `S-waiting-on-bors` after a PR is merged)

r? @ghost
@rust-bors rust-bors bot merged commit 79445c3 into rust-lang:main Jan 12, 2026
11 checks passed
@rustbot rustbot added this to the 1.94.0 milestone Jan 12, 2026
rust-timer added a commit that referenced this pull request Jan 12, 2026
Rollup merge of #150861 - folding-cleanups, r=lcnr

Folding/`ReErased` cleanups

Various cleanups I found while reading this code closely, mostly involving folding and the use of `ReErased`.

r? @lcnr
@nnethercote nnethercote deleted the folding-cleanups branch January 12, 2026 21:40
github-actions bot pushed a commit to rust-lang/rust-analyzer that referenced this pull request Jan 15, 2026
Rollup of 8 pull requests

Successful merges:

 - rust-lang/rust#150861 (Folding/`ReErased` cleanups)
 - rust-lang/rust#150869 (Emit error instead of delayed bug when meeting mismatch type for const tuple)
 - rust-lang/rust#150920 (Use a hook to decouple `rustc_mir_transform` from `rustc_mir_build`)
 - rust-lang/rust#150941 (rustc_parse_format: improve diagnostics for unsupported python numeric grouping)
 - rust-lang/rust#150972 (Rename EII attributes slightly (being consistent in naming things foreign items, not extern items))
 - rust-lang/rust#150980 (Use updated indexes to build reverse map for delegation generics)
 - rust-lang/rust#150986 (std: Fix size returned by UEFI tcp4 read operations)
 - rust-lang/rust#150996 (Remove `S-waiting-on-bors` after a PR is merged)

r? @ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rust-analyzer Relevant to the rust-analyzer 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.

5 participants