Change:
When I run this code (via ): I get the output I expected (i.e., a single line of output that says "My number is 42"). However, if I run this code (via the same with no other changes): I get two compiler errors. The first error indicates that is not in scope - this makes sense, I have not defined anywhere. However, the second error indicates (provided below) does not make sense: It appears that, when there are no other compiler issues, the compiler can infer a type for just fine. However, as soon as any other compiler issue appears, it loses the ability to infer type. That doesn't make sense to me - the ability to infer type should be unrelated to any other compiler errors present. : <!-- TRIAGEBOTSTART --<!-- TRIAGEBOTASSIGNSTART --<!-- TRIAGEBOTASSIGNDATASTARTTRIAGEBOTASSIGNDATAEND --<!-- TRIAGEBOTASSIGNEND --<!-- TRIAGEBOTEND --
I partially fixed this for and in , but not in general. I am dissatisfied with this error message. I'll look into fixing it. claim

Discussion:
use rustc_span::{ExpnKind, Span, DUMMY_SP}; use std::fmt; use std::iter; <ins> use std::ops::ControlFlow; </ins> use crate::traits::query::evaluate_obligation::InferCtxtExt as _; use crate::traits::query::normalize::AtExt as _;

post.dedup(); if self.is_tainted_by_errors() <del> && crate_names.len() == 1 && ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str()) && spans.len() == 0 </del> <ins> && (crate_names.len() == 1 && spans.len() == 0 && ["`core`", "`alloc`", "`std`"].contains(&crate_names[0].as_str()) || predicate.visit_with(&mut HasNumericInferVisitor).is_break()) </ins> { // Avoid complaining about other inference issues for expressions like // `42 >> 1`, where the types are still `{integer}`, but we want to

} } } <ins> struct HasNumericInferVisitor; impl<'tcx> ty::TypeVisitor<'tcx> for HasNumericInferVisitor { type BreakTy = (); fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<Self::BreakTy> { if matches!(ty.kind(), ty::Infer(ty::FloatVar(_) | ty::IntVar(_))) { ControlFlow::Break(()) } else { ControlFlow::CONTINUE } } } </ins>

<ins> trait Fallback { fn foo(&self) {} } impl Fallback for i32 {} impl Fallback for u64 {} impl Fallback for usize {} fn main() { missing(); //~^ ERROR cannot find function `missing` in this scope 0.foo(); // But then we shouldn't report an inference ambiguity here... } </ins>

<ins> error[E0425]: cannot find function `missing` in this scope --> $DIR/no-fallback-multiple-impls.rs:12:5 | LL |     missing(); |     ^^^^^^^ not found in this scope error: aborting due to previous error For more information about this error, try `rustc --explain E0425`. </ins>

impl bar for u32 { fn dup(&self) -> u32 { *self } fn blah<X>(&self) {} } fn main() { <del> 10.dup::<i32>(); //~ ERROR type annotations needed </del> <ins> 10.dup::<i32>(); </ins> //~^ ERROR this associated function takes 0 generic arguments but 1 <del> 10.blah::<i32, i32>(); //~ ERROR type annotations needed </del> <ins> 10.blah::<i32, i32>(); </ins> //~^ ERROR this associated function takes 1 generic argument but 2 (Box::new(10) as Box<dyn bar>).dup(); //~^ ERROR E0038

= note: required because of the requirements on the impl of `CoerceUnsized<Box<dyn bar>>` for `Box<{integer}>` = note: required by cast to type `Box<dyn bar>` <del> error[E0283]: type annotations needed --> $DIR/test-2.rs:9:8 | LL |     10.dup::<i32>(); |        ^^^ cannot infer type for type `{integer}` | note: multiple `impl`s satisfying `{integer}: bar` found --> $DIR/test-2.rs:5:1 | LL | impl bar for i32 { fn dup(&self) -> i32 { *self } fn blah<X>(&self) {} } | ^^^^^^^^^^^^^^^^ LL | impl bar for u32 { fn dup(&self) -> u32 { *self } fn blah<X>(&self) {} } | ^^^^^^^^^^^^^^^^ error[E0283]: type annotations needed --> $DIR/test-2.rs:11:8 | LL |     10.blah::<i32, i32>(); |        ^^^^ cannot infer type for type `{integer}` | note: multiple `impl`s satisfying `{integer}: bar` found --> $DIR/test-2.rs:5:1 | LL | impl bar for i32 { fn dup(&self) -> i32 { *self } fn blah<X>(&self) {} } | ^^^^^^^^^^^^^^^^ LL | impl bar for u32 { fn dup(&self) -> u32 { *self } fn blah<X>(&self) {} } | ^^^^^^^^^^^^^^^^ error: aborting due to 7 previous errors </del> <ins> error: aborting due to 5 previous errors </ins> <del> Some errors have detailed explanations: E0038, E0107, E0283. </del> <ins> Some errors have detailed explanations: E0038, E0107. </ins> For more information about an error, try `rustc --explain E0038`.