Change:
<!-- Thank you for filing a bug report! Please provide a short summary of the bug, along with any information you feel relevant to replicating the bug. --I have a full repro in , but the short version is, it seems like some cases of code that look_ like an omitted type should be inferrable: while certain dependencies, leading to , are in the compile pathway (I could only get it to reproduce via a weird dependency chain via a workspace and a couple of public crates), can lead to an overflow: If the dependency chain is altered in any way that I could divine, the expected error is output: <!-- 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. --I've reproduced this bug both in and in . :
Bisects to nightly-2023-10-07. In nightly-2023-10-06, we get "the expected error" shown above.
Looks like , because reproduces the issue, but the previous commit on master () does not.
Minimal:
I'll put up a fix in a sec
WG-prioritization assigning priority (). label -I-prioritize +P-medium

Discussion:
use rustc_middle::ty; use rustc_span::{Span, DUMMY_SP}; <ins> use crate::traits::query::evaluate_obligation::InferCtxtExt; </ins> use crate::traits::ObligationCtxt; #[derive(Debug)]

_ => return false, } <del> let impl_predicates = tcx.predicates_of(impl_def_id).instantiate(tcx, impl_args); ocx.register_obligations(impl_predicates.predicates.iter().map(|&predicate| { Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate) })); </del> <ins> let obligations = tcx .predicates_of(impl_def_id) .instantiate(tcx, impl_args) .into_iter() .map(|(predicate, _)| { Obligation::new(tcx, ObligationCause::dummy(), param_env, predicate) }) // Kinda hacky, but let's just throw away obligations that overflow. // This may reduce the accuracy of this check (if the obligation guides // inference or it actually resulted in error after others are processed) // ... but this is diagnostics code. .filter(|obligation| { infcx.next_trait_solver() || infcx.evaluate_obligation(obligation).is_ok() }); ocx.register_obligations(obligations); </ins> ocx.select_where_possible().is_empty() })

if ambiguities.len() > 5 { let infcx = self.infcx; if !ambiguities.iter().all(|option| match option { <del> DefId(did) => infcx.fresh_args_for_item(DUMMY_SP, *did).is_empty(), </del> <ins> DefId(did) => infcx.tcx.generics_of(*did).count() == 0, </ins> ParamEnv(_) => true, }) { // If not all are blanket impls, we filter blanked impls out. ambiguities.retain(|option| match option { <del> DefId(did) => infcx.fresh_args_for_item(DUMMY_SP, *did).is_empty(), </del> <ins> DefId(did) => infcx.tcx.generics_of(*did).count() == 0, </ins> ParamEnv(_) => true, }); }

<ins> trait Hello {} struct Foo<'a, T: ?Sized>(&'a T); impl<'a, T: ?Sized> Hello for Foo<'a, &'a T> where Foo<'a, T>: Hello {} impl Hello for Foo<'static, i32> {} fn hello<T: ?Sized + Hello>() {} fn main() { hello(); //~^ ERROR type annotations needed } </ins>

<ins> error[E0283]: type annotations needed --> $DIR/overflow-computing-ambiguity.rs:12:5 | LL |     hello(); |     ^^^^^ cannot infer type of the type parameter `T` declared on the function `hello` | = note: cannot satisfy `_: Hello` = help: the following types implement trait `Hello`: Foo<'a, &'a T> Foo<'static, i32> note: required by a bound in `hello` --> $DIR/overflow-computing-ambiguity.rs:9:22 | LL | fn hello<T: ?Sized + Hello>() {} |                      ^^^^^ required by this bound in `hello` help: consider specifying the generic argument | LL |     hello::<T>(); |          +++++ error: aborting due to 1 previous error For more information about this error, try `rustc --explain E0283`. </ins>