Change:
I tried this code on nightly: I expected to see this happen: compiler does not panic. Instead, this happened: compiler panics and suggests I open a bug report. I initially posted to , but says this is a different issue, despite panicking on the same line in . (Though I'm realizing now that might be the proximal cause but not very related to the root cause.) : <details<summaryPanic message</summary<p</p</detailsThanks all for maintaining Rust, by the way.
Thanks!
searched nightlies: from nightly-2022-12-01 to nightly-2023-01-21 regressed nightly: nightly-2023-01-07 searched commit range: regressed commit: <details<summarybisected with <a href=''cargo-bisect-rustc</av0.6.5</summaryHost triple: x86_64-unknown-linux-gnu Reproduce with: </details
It's , i'll fix it unless someone beats me to it since I'm busy this weekend
Hi it's Justin from Commure :wave:. I found a compiler panic you made :grinning:
sorry for causing you trouble

Discussion:
|| self.suggest_into(err, expr, expr_ty, expected) || self.suggest_floating_point_literal(err, expr, expected); if !suggested { <del> self.point_at_expr_source_of_inferred_type(err, expr, expr_ty, expected); </del> <ins> self.point_at_expr_source_of_inferred_type(err, expr, expr_ty, expected, expr.span); </ins> } }

expr: &hir::Expr<'_>, found: Ty<'tcx>, expected: Ty<'tcx>, <ins> mismatch_span: Span, </ins> ) -> bool { let map = self.tcx.hir();

lt_op: |_| self.tcx.lifetimes.re_erased, ct_op: |c| c, ty_op: |t| match *t.kind() { <del> ty::Infer(ty::TyVar(vid)) => self.tcx.mk_ty_infer(ty::TyVar(self.root_var(vid))), </del> <ins> ty::Infer(ty::TyVar(_)) => self.tcx.mk_ty_var(ty::TyVid::from_u32(0)), </ins> ty::Infer(ty::IntVar(_)) => { self.tcx.mk_ty_infer(ty::IntVar(ty::IntVid { index: 0 })) }

}, }; let mut prev = eraser.fold_ty(ty); <del> let mut prev_span = None; </del> <ins> let mut prev_span: Option<Span> = None; </ins> for binding in expr_finder.uses { // In every expression where the binding is referenced, we will look at that

// inferred in this method call. let arg = &args[i]; let arg_ty = self.node_ty(arg.hir_id); <del> err.span_label( arg.span, &format!( "this is of type `{arg_ty}`, which causes `{ident}` to be  inferred as `{ty}`", ), ); </del> <ins> if !arg.span.overlaps(mismatch_span) { err.span_label( arg.span, &format!( "this is of type `{arg_ty}`, which causes `{ident}` to be  inferred as `{ty}`", ), ); } </ins> param_args.insert(param_ty, (arg, arg_ty)); } }

&& self.can_eq(self.param_env, ty, found).is_ok() { // We only point at the first place where the found type was inferred. <ins> if !segment.ident.span.overlaps(mismatch_span) { </ins> err.span_label( segment.ident.span, with_forced_trimmed_paths!(format!( "here the type of `{ident}` is inferred to be `{ty}`", )), <del> ); </del> <ins> );} </ins> break; } else if !param_args.is_empty() { break;

// We use the *previous* span because if the type is known *here* it means // it was *evaluated earlier*. We don't do this for method calls because we // evaluate the method's self type eagerly, but not in any other case. <del> err.span_label( span, with_forced_trimmed_paths!(format!( "here the type of `{ident}` is inferred to be `{ty}`", )), ); </del> <ins> if !span.overlaps(mismatch_span) { err.span_label( span, with_forced_trimmed_paths!(format!( "here the type of `{ident}` is inferred to be `{ty}`", )), ); } </ins> break; } prev = ty;

kind: TypeVariableOriginKind::MiscVariable, span: full_call_span, }); <del> self.point_at_expr_source_of_inferred_type(&mut err, rcvr, expected, callee_ty); </del> <ins> self.point_at_expr_source_of_inferred_type( &mut err, rcvr, expected, callee_ty, provided_arg_span, ); </ins> } // Call out where the function is defined self.label_fn_like(

<ins> // The error message here still is pretty confusing. fn main() { let mut result = vec![1]; // The type of `result` is constrained to be `Vec<{integer}>` here. // But the logic we use to find what expression constrains a type // is not sophisticated enough to know this. let mut vector = Vec::new(); vector.sort(); result.push(vector); //~^ ERROR mismatched types // So it thinks that the type of `result` is constrained here. } fn example2() { let mut x = vec![1]; x.push(""); //~^ ERROR mismatched types } </ins>

<ins> error[E0308]: mismatched types --> $DIR/bad-type-in-vec-push.rs:11:17 | LL |     vector.sort(); |     ------ here the type of `vector` is inferred to be `Vec<_>` LL |     result.push(vector); |            ---- ^^^^^^ expected integer, found struct `Vec` |            | |            arguments to this method are incorrect | = note: expected type `{integer}` found struct `Vec<_>` note: associated function defined here --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL error[E0308]: mismatched types --> $DIR/bad-type-in-vec-push.rs:18:12 | LL |     x.push(""); |       ---- ^^ expected integer, found `&str` |       | |       arguments to this method are incorrect | note: associated function defined here --> $SRC_DIR/alloc/src/vec/mod.rs:LL:COL error: aborting due to 2 previous errors For more information about this error, try `rustc --explain E0308`. </ins>