Skip to content

Also check the defining crate's features for items from dependencies - #166443

Open
kimhappy wants to merge 11 commits into
rust-lang:mainfrom
kimhappy:main
Open

kimhappy wants to merge 11 commits into
rust-lang:mainfrom
kimhappy:main

Conversation

@kimhappy

@kimhappy kimhappy commented Nov 24, 2026 •

Copy link
Copy Markdown

Some feature checks only look at the current crate's features, even when the item comes from a dependency. This causes ICEs, spurious errors, and one unsound acceptance.

This PR records each crate's enabled language features in its metadata. The checks now also look at the crate that defines the item.

Background

While investigating #166244, I found that a downstream crate ignores an upstream crate's gca_const_items. I then looked for similar cases and fixed each one.

Problems

Each case has a regression test.

  • gca_const_items
  • generic_const_exprs
  • coroutine_clone: Calling clone() on an upstream impl Coroutine + Clone ICEs, because no builtin Clone candidate is assembled.
  • move_trait (next solver): The fast path treats an upstream impl !Move type as Move, so it wrongly satisfies T: Move.
  • ergonomic_clones: When an upstream generic function using .use is monomorphized or inlined downstream, it calls Clone::clone instead of copying Copy types.
  • with_negative_coherence: Implementing an upstream #[rustc_strict_coherence] trait errors with "strict coherence needs negative coherence".

Solution

A check now uses the features enabled in the current crate or in the crate that defines the item. Downstream crates that enable a feature and use upstream items work as before.

Enabled features are recorded the same way as specialization_enabled_in(CrateNum):

  • CrateRoot::enabled_lang_features: Stores the language features a crate enables.
  • enabled_lang_features_in(CrateNum) -> &FxIndexSet<Symbol>: Queries to read them.
  • TyCtxt::lang_feature_enabled_in(CrateNum, Symbol): Checks whether one crate enables a feature.
  • TyCtxt::features_for(DefId) -> ItemFeatures: Features enabled in the current crate or in the crate defining def_id.
  • Interner::features_for and inherent::ItemFeatures: The same for code using the interner, like the next solver.

Exceptions:

  • generic_const_exprs: A goal can mix consts from several crates, so ty::gce_applies_to checks whether a value mentions a const from a crate with the feature.
  • move_trait: ADTs use their own crate's features. Tuples, arrays, slices and pattern types never take the fast path, so their components are checked instead.
  • ergonomic_clones: .use Calls are optimized whenever the MIR has one, regardless of crate features.
  • with_negative_coherence: Only #[rustc_strict_coherence] uses the trait's crate. OverlapMode::WithNegative still uses only the current crate, so core enabling the feature doesn't change coherence everywhere (tests/ui/coherence/negative-coherence-foreign-trait.rs).

Fixes #166244
Fixes #145069
Fixes #166409


LLM disclosure: I used an LLM to investigate the problem areas, write reproductions, and find related issues. I designed the solution, applied it to each case, and wrote the commit messages and PR description. I reviewed all LLM output myself.

@rustbot

rustbot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred in match checking

cc @Nadrieril

Some changes occurred to MIR optimizations

cc @rust-lang/wg-mir-opt

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

rustbot commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the pull request, and welcome! The Rust Project has assigned @folkertdev (or someone else) to review your changes, you should hear from them (or someone else) within the next two weeks.

Please see the contribution instructions and our LLM policy for more information.

Why was this reviewer chosen?

The reviewer was selected based on:

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

@rustbot

This comment has been minimized.

@rust-bors

This comment has been minimized.

Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
Signed-off-by: kimhappy <babtul21@gmail.com>
@rustbot

rustbot commented Nov 27, 2026

Copy link
Copy Markdown
Collaborator

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.

Signed-off-by: kimhappy <babtul21@gmail.com>
@rust-bors

rust-bors Bot commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

☔ The latest upstream changes (presumably #166674) made this pull request unmergeable. Please resolve the merge conflicts by rebasing.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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)

Projects

None yet

3 participants