rust/compiler/rustc_middle
Matthias Krüger 3cb1a4676a
Rollup merge of #111279 - compiler-errors:core-item-resolve, r=cjgillot
More robust debug assertions for `Instance::resolve` on built-in traits with non-standard trait items

In #111264, a user added a new item to the `Future` trait, but the code in [`resolve_associated_item`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ty_utils/instance/fn.resolve_associated_item.html) implicitly assumes that the `Future` trait is defined with only one method (`Future::poll`) and treats the generator body as the implementation of that method.

This PR adds some debug assertions to make sure that that new methods defined on `Future`/`Generator`/etc. don't accidentally resolve to the wrong item when they are added, and adds a helpful comment guiding a compiler dev (or curious `#![no_core]` user) to what must be done to support adding new associated items to these built-in implementations.

I am open to discuss whether a test should be added, but I chose against it because I opted to make these `bug!()`s instead of, e.g., diagnostics or fatal errors. Arguably it doesn't need a test because it's not a bug that can be triggered by an end user, and internal-facing misuses of core kind of touch on rust-lang/compiler-team#620 -- however, I think the assertions I added in this PR are still a very useful way to make sure this bug doesn't waste debugging resources down the line.

Fixes #111264
2023-05-06 13:30:06 +02:00
..
src Rollup merge of #111279 - compiler-errors:core-item-resolve, r=cjgillot 2023-05-06 13:30:06 +02:00
Cargo.toml Remove QueryEngine trait 2023-04-26 07:46:13 +02:00
messages.ftl Avoid ICEing miri on layout query cycles 2023-05-02 16:14:20 +00:00
README.md

For more information about how rustc works, see the rustc dev guide.