Skip to content

Fix opaque type ICE in late lints under the next-generation trait solver - #159840

Merged
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Gri-ffin:lint-post-borrowck-typing-mode
Jul 27, 2026
Merged

Fix opaque type ICE in late lints under the next-generation trait solver#159840
rust-bors[bot] merged 3 commits into
rust-lang:mainfrom
Gri-ffin:lint-post-borrowck-typing-mode

Conversation

@Gri-ffin

@Gri-ffin Gri-ffin commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

fixes rust-lang/rust-clippy#17411

Under the next trait solver, late lints trigger an ICE due to having non-empty opaque storage when dropping InferCtxt.

Rather than forcing all current and future late lints to manually use ignoring_regions, use PostBorrowck in LateContext.

cc @adwinwhite

@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 Jul 24, 2026
@rustbot

rustbot commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

r? @nnethercote

rustbot has assigned @nnethercote.
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 74 candidates
  • Random selection from 18 candidates

@Gri-ffin Gri-ffin changed the title Fix opaque InferCtxt drop bomb in LateContext by using PostBorrowck typing mode Fix opaque InferCtxt ICE in LateContext by using PostBorrowck typing mode Jul 24, 2026
@Gri-ffin Gri-ffin changed the title Fix opaque InferCtxt ICE in LateContext by using PostBorrowck typing mode Fix opaque type ICE in late lints under the next-generation trait solver Jul 24, 2026
@Jarcho

Jarcho commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Is the clippy ICE not caused by the fallback to TypingMode::non_body_analysis() for bodies which don't define opaque types?

@adwinwhite

Copy link
Copy Markdown
Contributor

Thanks! Could you add a next solver revision in the future_not_send clippy test?

Also the reason we trigger ICE is that we have non-empty opaque storage when dropping InferCtxt rather than we have unresolved hidden types. Please update the description :>

We should also update the comments in the Drop impl of InferCtxt to remove the mention of lints.

@Jarcho

Jarcho commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

I definitely did not read the condition correctly. It wouldn't even matter anyway since it's in a function defining an opaque type.

The ICE is fixed by normalizing the return type first. Given that we have 158 instances of skip_norm_wip there's probably more issues to be found.

@adwinwhite

adwinwhite commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Is the clippy ICE not caused by the fallback to TypingMode::non_body_analysis() for bodies which don't define opaque types?

No, we're not using TypingMode::non_body_analysis in the next solver. And using it is wrong as late lints are run after borrowck so we should have access to opaque types defined in the body.

@adwinwhite

adwinwhite commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

The ICE is fixed by normalizing the return type first.

care to elaborate more? normalizing it shouldn't fix this 🤔 normalization only registers/check this opaque.

Ah, I'm blind. you mean normalizing the return type. that will only fix cases that the opaques types are return types.
The skip_norm_wip is #155345.
Normalization has cost and it's unsure we can normalize everywhere.

@Jarcho

Jarcho commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

The type is currently retrieved via:

let ret_ty = cx.tcx.normalize_erasing_regions(cx.typing_env(), cx.tcx.fn_sig(fn_def_id).instantiate_identity()).output();
cx.tcx.instantiate_bound_regions_with_erased(ret_ty)

Switching it to:

let ret_ty = cx.tcx.normalize_erasing_regions(cx.typing_env(), cx.tcx.fn_sig(fn_def_id).instantiate_identity()).output();
cx.tcx.instantiate_bound_regions_with_erased(ret_ty)

Gets rid of the ICE.

@Jarcho

Jarcho commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

The crashing lint looks for functions returning impl Future and checks if they implement Send. Currently we pass the opaqued type alias into the trait solver.

@Jarcho

Jarcho commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Normalization has cost and it's unsure we can normalize everywhere.

I thought the new solver generally wanted things normalized first. There's quite a few times where we want to explicitly skip normalization since we want what was actually typed, but we also do quite a few trait queries.

@nnethercote

Copy link
Copy Markdown
Contributor

r? @adwinwhite

...who clearly knows much more about this than I do :)

@rustbot rustbot assigned adwinwhite and unassigned nnethercote Jul 25, 2026
@adwinwhite

adwinwhite commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Thanks for the clarification.

But actually the root cause of this ICE affects more than the future_not_send lint or return_ty.
short list:

  • tests/ui/future_not_send.rs
  • tests/ui/large_futures.rs
  • tests/ui/missing_transmute_annotations_unfixable.rs
  • tests/ui/new_ret_no_self_overflow.rs
  • tests/ui/search_is_some_fixable_some.rs

Any use of defining opaque types under TypingMode::PostTypeckUntilBorrowck will register entry to the opaque storage.
And they'll trigger the drop bomb in InferCtxt::drop unless we explicitly consume/take the opaques type from the storage which we don't often do in late lints, or ever do?
Using the correct typing mode would eliminate this footgun entirely - With TypingMode::PostBorrowck we don't register any opaque type into the storage.

I thought the new solver generally wanted things normalized first.

Yeah, just that it's not always achievable 😔

@rustbot

rustbot commented Jul 25, 2026

Copy link
Copy Markdown
Collaborator

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

cc @rust-lang/clippy

@rustbot rustbot added the T-clippy Relevant to the Clippy team. label Jul 25, 2026
@Jarcho

Jarcho commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Any use of defining opaque types under TypingMode::PostTypeckUntilBorrowck will register entry to the opaque storage.
And they'll trigger the drop bomb in InferCtxt::drop unless we explicitly consume/take the opaques type from the storage which we don't often do in late lints, or ever do?

I assume the point of what both the typeck and borrowck modes are doing is to gather up all the different types that flow into the opaque type. If that's the the case then lint passes are using the wrong mode since we don't ever do that. If a lint ever needed to it could still switch to a different mode.

@adwinwhite

Copy link
Copy Markdown
Contributor

@bors r+ rollup

@rust-bors

rust-bors Bot commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

📌 Commit 964e8ee has been approved by adwinwhite

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 Jul 27, 2026
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 27, 2026
…-mode, r=adwinwhite

Fix opaque type ICE in late lints under the next-generation trait solver

fixes rust-lang/rust-clippy#17411

Under the next trait solver, late lints trigger an ICE due to having non-empty opaque storage when dropping `InferCtxt`.

Rather than forcing all current and future late lints to manually use `ignoring_regions`, use `PostBorrowck` in `LateContext`.

cc @adwinwhite
rust-bors Bot pushed a commit that referenced this pull request Jul 27, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #159085 (Fix decoding attributes of `SyntheticCoroutineBody`)
 - #159554 (feat: Update method signature of int_from_ascii)
 - #159637 (Some place analysis tweaks)
 - #159961 (sanitize_standard_fds: Miri supports poll now)
 - #159967 (rustc_target: callconv: mips64: Return structs with single f128 in FPRs)
 - #159253 (Add suggestions for using `#[export_name]` instead of `#[link_name]` on static)
 - #159840 (Fix opaque type ICE in late lints under the next-generation trait solver)
 - #159956 (Fix observable intermediate state in `thread::add_spawn_hook`)
rust-bors Bot pushed a commit that referenced this pull request Jul 27, 2026
…uwer

Rollup of 8 pull requests

Successful merges:

 - #159085 (Fix decoding attributes of `SyntheticCoroutineBody`)
 - #159554 (feat: Update method signature of int_from_ascii)
 - #159637 (Some place analysis tweaks)
 - #159961 (sanitize_standard_fds: Miri supports poll now)
 - #159967 (rustc_target: callconv: mips64: Return structs with single f128 in FPRs)
 - #159253 (Add suggestions for using `#[export_name]` instead of `#[link_name]` on static)
 - #159840 (Fix opaque type ICE in late lints under the next-generation trait solver)
 - #159956 (Fix observable intermediate state in `thread::add_spawn_hook`)
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Jul 27, 2026
…-mode, r=adwinwhite

Fix opaque type ICE in late lints under the next-generation trait solver

fixes rust-lang/rust-clippy#17411

Under the next trait solver, late lints trigger an ICE due to having non-empty opaque storage when dropping `InferCtxt`.

Rather than forcing all current and future late lints to manually use `ignoring_regions`, use `PostBorrowck` in `LateContext`.

cc @adwinwhite
rust-bors Bot pushed a commit that referenced this pull request Jul 27, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - #158417 (Avoid ICE when cfg_eval recovers no item from derive input)
 - #159085 (Fix decoding attributes of `SyntheticCoroutineBody`)
 - #159554 (feat: Update method signature of int_from_ascii)
 - #159637 (Some place analysis tweaks)
 - #159649 (Normalize region obligations before regionck)
 - #159961 (sanitize_standard_fds: Miri supports poll now)
 - #159967 (rustc_target: callconv: mips64: Return structs with single f128 in FPRs)
 - #159253 (Add suggestions for using `#[export_name]` instead of `#[link_name]` on static)
 - #159804 (Expand docs for fs::metadata and fs::symlink_metadata)
 - #159821 (Update expect message using the recommended style in binary_heap module)
 - #159840 (Fix opaque type ICE in late lints under the next-generation trait solver)
 - #159956 (Fix observable intermediate state in `thread::add_spawn_hook`)
 - #159991 (std: make send_process_group_signal unsupported on VxWorks)
 - #159996 (Detect when a macro without exclamation mark uses square brackets)
@rust-bors
rust-bors Bot merged commit 0b2da47 into rust-lang:main Jul 27, 2026
13 checks passed
@rustbot rustbot added this to the 1.99.0 milestone Jul 27, 2026
rust-timer added a commit that referenced this pull request Jul 27, 2026
Rollup merge of #159840 - Gri-ffin:lint-post-borrowck-typing-mode, r=adwinwhite

Fix opaque type ICE in late lints under the next-generation trait solver

fixes rust-lang/rust-clippy#17411

Under the next trait solver, late lints trigger an ICE due to having non-empty opaque storage when dropping `InferCtxt`.

Rather than forcing all current and future late lints to manually use `ignoring_regions`, use `PostBorrowck` in `LateContext`.

cc @adwinwhite
@Gri-ffin
Gri-ffin deleted the lint-post-borrowck-typing-mode branch July 27, 2026 16:38
@Mark-Simulacrum

Copy link
Copy Markdown
Member

@rustbot build 919a1dc

cc #160003 (comment)

pull Bot pushed a commit to xtqqczze/rust-lang-miri that referenced this pull request Jul 28, 2026
…uwer

Rollup of 14 pull requests

Successful merges:

 - rust-lang/rust#158417 (Avoid ICE when cfg_eval recovers no item from derive input)
 - rust-lang/rust#159085 (Fix decoding attributes of `SyntheticCoroutineBody`)
 - rust-lang/rust#159554 (feat: Update method signature of int_from_ascii)
 - rust-lang/rust#159637 (Some place analysis tweaks)
 - rust-lang/rust#159649 (Normalize region obligations before regionck)
 - rust-lang/rust#159961 (sanitize_standard_fds: Miri supports poll now)
 - rust-lang/rust#159967 (rustc_target: callconv: mips64: Return structs with single f128 in FPRs)
 - rust-lang/rust#159253 (Add suggestions for using `#[export_name]` instead of `#[link_name]` on static)
 - rust-lang/rust#159804 (Expand docs for fs::metadata and fs::symlink_metadata)
 - rust-lang/rust#159821 (Update expect message using the recommended style in binary_heap module)
 - rust-lang/rust#159840 (Fix opaque type ICE in late lints under the next-generation trait solver)
 - rust-lang/rust#159956 (Fix observable intermediate state in `thread::add_spawn_hook`)
 - rust-lang/rust#159991 (std: make send_process_group_signal unsupported on VxWorks)
 - rust-lang/rust#159996 (Detect when a macro without exclamation mark uses square brackets)
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-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ICE: next solver: future_not_send on any async code

6 participants