Change:
<!-- Thank you for finding an Internal Compiler Error! If possible, try to provide a minimal verifiable example. You can read "Rust Bug Minimization Patterns" for how to create smaller examples. --<!-- If you're using the stable version of the compiler, you should also check if the bug also exists in the beta or nightly versions. --: <!-- Include a backtrace in the code block by setting in your environment. E.g. . --<details<summary<strongBacktrace</strong</summary<p</p</details<!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
I'm Rust newbie and I try to make a microservice. The offending line was at first the following: function serve When I did "cargo check", I had an error and when I tried to correct it with the recommended option, I panic message. I will investigate further to simplify the code, and sends this as requested in the error message. Regards Didier
Hi, thank you for your report. Can you verify that this issue still occurs on the latest nightly version?
Hi Nilstrieb, yes, same behavior with the nightly build.
This check was promoted to 'internal compiler error' in commit as part of pull request (
Looks like this is the same issue as , which unfortunately also doesn't contain useful info.
Thank you for the info. Best regards Didier
I can look into this. I was investigating the same assertion in . claim
Minimized quite a lot:
Hello. Michael, Many thanks, I will look at it and for sure learn a lot more Regards Didier Rigoli Senior Manager
This regressed in -- I can't really work on it any further without a self-contained, minimized version of the ICE, which I attempted and failed to do. If someone wants to minimize it, then that would be greatly appreciated, and I can pick it up after that if nobody else has. ping icebreakers-cleanup-crew release-assignment
Hey Cleanup Crew ICE-breakers! This bug has been identified as a good "Cleanup ICE-breaking candidate". In case it's useful, here are some [instructions] for tackling these sorts of bugs. Maybe take a look? Thanks! <3 [instructions]: https://rustc-dev- cc
Minimized more (): <details<summary<strongError output</strong</summary<p</p</details
How could an ambiguity error be raised when the canonical request has no inference variables? This looks interesting.
It's related to the variable name resolution error being emitted earlier, so maybe the inference context being tainted by errors causes something about evaluation to get messed up.
Here's a cve without any external dependencies. Not quiet small, but it does the job.
Minimized: label S-bug-has-mcve
interesting enough you seem to trigger the ICE in a different way than me? You're using the token, I use an incomplete trait impl. Maybe it's worth to test a possible solution to both inputs?
I'm pretty sure I understand this error now. Either via solution of having a with an error in its body, or via solution of having a missing associated type , we end up trying to check a trait bound on a () type in order to normalize a type inside a closure signature, which ends up evaluating as ambiguous. However, we don't handle ambiguities properly with the normalization query call. I took a stab at fixing this in , and I extended it a bit to also fix these cases, too.

Discussion:
use rustc_middle::ty::fold::{FallibleTypeFolder, TypeFoldable, TypeSuperFoldable}; use rustc_middle::ty::visit::{TypeSuperVisitable, TypeVisitable}; use rustc_middle::ty::{self, Ty, TyCtxt, TypeVisitor}; <ins> use rustc_span::DUMMY_SP; </ins> use std::ops::ControlFlow;

let result = tcx.normalize_projection_ty(c_data)?; // We don't expect ambiguity. if result.is_ambiguous() { <del> bug!("unexpected ambiguity: {:?} {:?}", c_data, result); </del> <ins> // Rustdoc normalizes possibly not well-formed types, so only // treat this as a bug if we're not in rustdoc. if !tcx.sess.opts.actually_rustdoc { tcx.sess.delay_span_bug( DUMMY_SP, format!("unexpected ambiguity: {:?} {:?}", c_data, result), ); } return Err(NoSolution); </ins> } let InferOk { value: result, obligations } = self.infcx.instantiate_query_response_and_region_obligations(

<ins> // compile-flags: -Znormalize-docs #![feature(type_alias_impl_trait)] trait Allocator { type Buffer; } struct DefaultAllocator; // This unconstrained impl parameter causes the normalization of // `<DefaultAllocator as Allocator>::Buffer` to be ambiguous, // which caused an ICE with `-Znormalize-docs`. impl<T> Allocator for DefaultAllocator { type Buffer = (); } type A = impl Fn(<DefaultAllocator as Allocator>::Buffer); fn foo() -> A { |_| () } fn main() {} </ins>

<ins> // edition:2021 mod hyper { use std::{fmt::Debug, future::Future, marker::PhantomData, pin::Pin, task::Poll}; pub trait HttpBody { type Error; } impl HttpBody for () { //~^ ERROR not all trait items implemented, missing: `Error` // don't implement `Error` here for the ICE } pub struct Server<I, S>(I, S); pub fn serve<I, S>(_: S) -> Server<I, S> { todo!() } impl<S, B> Future for Server<(), S> where S: MakeServiceRef<(), (), ResBody = B>, B: HttpBody, B::Error: Debug, { type Output = (); fn poll(self: Pin<&mut Self>, _: &mut std::task::Context<'_>) -> Poll<Self::Output> { todo!() } } pub trait MakeServiceRef<Target, ReqBody> { type ResBody; } impl<T, S> MakeServiceRef<(), ()> for T where T: for<'a> Service<&'a (), Response = S>, S: Service<()>, { type ResBody = (); } pub struct MakeServiceFn<F>(pub F); pub struct ServiceFn<F, R>(pub PhantomData<(F, R)>); pub trait Service<Request> { type Response; } impl<'t, F, Ret, Target, Svc> Service<&'t Target> for MakeServiceFn<F> where F: Fn() -> Ret, Ret: Future<Output = Result<Svc, ()>>, { type Response = Svc; } impl<F, ReqBody, Ret, ResBody, E> Service<ReqBody> for ServiceFn<F, ReqBody> where F: Fn() -> Ret, Ret: Future<Output = Result<ResBody, E>>, { type Response = ResBody; } } async fn smarvice() -> Result<(), ()> { Ok(()) } fn service_fn<F, R, S>(f: F) -> hyper::ServiceFn<F, R> where F: Fn() -> S, { hyper::ServiceFn(std::marker::PhantomData) } async fn iceice() { let service = hyper::MakeServiceFn(|| async { Ok::<_, ()>(service_fn(|| smarvice())) }); hyper::serve::<(), _>(service).await; } fn main() {} </ins>

<ins> error[E0046]: not all trait items implemented, missing: `Error` --> $DIR/issue-103181-1.rs:9:5 | LL |         type Error; |         ---------- `Error` from trait LL |     } LL |     impl HttpBody for () { |     ^^^^^^^^^^^^^^^^^^^^ missing `Error` in implementation error: aborting due to previous error For more information about this error, try `rustc --explain E0046`. </ins>

<ins> // edition:2021 trait SendFuture: Send { type Output; } impl<Fut: Send> SendFuture for Fut { type Output = (); } async fn broken_fut() { ident_error; //~^ ERROR cannot find value `ident_error` in this scope } // triggers normalization of `<Fut as SendFuture>::Output`, // which requires `Fut: Send`. fn normalize<Fut: SendFuture>(_: Fut, _: Fut::Output) {} async fn iceice<A, B>() // <- async fn is necessary where A: Send, B: Send, // <- a second bound { normalize(broken_fut(), ()); } fn main() {} </ins>

<ins> error[E0425]: cannot find value `ident_error` in this scope --> $DIR/issue-103181-2.rs:12:5 | LL |     ident_error; |     ^^^^^^^^^^^ not found in this scope error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. </ins>