Skip to content

Fix rustdoc ICE caused by mishandling of ambiguity errors - #162782

Open
ShoyuVanilla wants to merge 1 commit into
rust-lang:mainfrom
ShoyuVanilla:issue-162557
Open

ShoyuVanilla wants to merge 1 commit into
rust-lang:mainfrom
ShoyuVanilla:issue-162557

Conversation

@ShoyuVanilla

@ShoyuVanilla ShoyuVanilla commented Sep 14, 2026

Copy link
Copy Markdown
Member

Fixes #162557

pub trait Service<Request> {
    type Future;
}

pub trait ZebraService<Request>: Service<Request> {}

impl<MaybeVerify, Request> ZebraService<Request> for MaybeVerify where
    MaybeVerify: Service<Request, Future: 'static>
{
}

pub struct Verifier;

impl Service<()> for Verifier {
    type Future = &'static ();
}

In the above minimization of the issue, when we try to check whether the blanket impl can be applied to Verifier,

let args = infcx.fresh_args_for_item(DUMMY_SP, item_def_id);
let impl_ty = ty.instantiate(tcx, args).skip_norm_wip();
let param_env = ty::ParamEnv::empty();
let impl_args = infcx.fresh_args_for_item(DUMMY_SP, impl_def_id);
let impl_trait_ref = trait_ref.instantiate(tcx, impl_args).skip_norm_wip();
// Require the type the impl is implemented on to match
// our type, and ignore the impl if there was a mismatch.
let Ok(eq_result) = infcx.at(&traits::ObligationCause::dummy(), param_env).eq(
DefineOpaqueTypes::Yes,
impl_trait_ref.self_ty(),
impl_ty,
) else {
continue;
};
let InferOk { value: (), obligations } = eq_result;
// FIXME(eddyb) ignoring `obligations` might cause false positives.
drop(obligations);
let clauses = tcx
.clauses_of(impl_def_id)
.instantiate(tcx, impl_args)
.clauses
.into_iter()
.map(Unnormalized::skip_norm_wip)

We make fresh args for the where-clause and skip normalization for it.

So, we have <?MaybeVerify as Service<?Request>>::Future: 'static bound to check. But it immediately evaluated into ambiguity due to stalled on infer vars in the fast path as the obligation contains the infer vars.

But due #162182 we evaluated it directly in the solver without stalled_on and this time it succeeded because we can normalize the alias into a concrete type &'static () and it outlives the static region.

So, I think it's very iffy to call InferCtxt::evaluate_obligation on a non-rigid alias and we should eagerly normalize it in L67 from the above rustdoc code.
But it may break something in rustdoc as normalizations inside it is pretty messy in general 🫠 So, I guess in another PR with crater runs.

r? lcnr

@rustbot

rustbot commented Sep 14, 2026

Copy link
Copy Markdown
Collaborator

Some changes occurred to the core trait solver

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

These commits modify tests/rustdoc-json.
rustdoc-json is a public (but unstable) interface.

Please ensure that if you've changed the output:

  • It's intentional.
  • The FORMAT_VERSION in src/librustdoc-json-types is bumped if necessary.

cc @obi1kenobi

@rustbot rustbot added A-rustdoc-json Area: Rustdoc JSON backend 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Sep 14, 2026
@ShoyuVanilla ShoyuVanilla changed the title Fix rustdoc ICE due to mishandling of ambiguity errors Fix rustdoc ICE caused by mishandling of ambiguity errors Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-rustdoc-json Area: Rustdoc JSON backend 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. T-rustdoc Relevant to the rustdoc 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]: "did not expect successful goal when collecting ambiguity errors"

3 participants