X-Git-Url: https://git.lizzy.rs/?a=blobdiff_plain;f=compiler%2Frustc_typeck%2Fsrc%2Fcollect%2Ftype_of.rs;h=f1dbe64f13abbb33e3cb4a323abb015be0288489;hb=0dc39c7bd9795927b903c8c24e89a00788ce3e33;hp=534ddfa9531c160494c75f86564078a4be572f6c;hpb=e820ecdba115e56d3d1cb0df169463a23a28fabd;p=rust.git diff --git a/compiler/rustc_typeck/src/collect/type_of.rs b/compiler/rustc_typeck/src/collect/type_of.rs index 534ddfa9531..f1dbe64f13a 100644 --- a/compiler/rustc_typeck/src/collect/type_of.rs +++ b/compiler/rustc_typeck/src/collect/type_of.rs @@ -801,6 +801,9 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { match tcx.sess.diagnostic().steal_diagnostic(span, StashKey::ItemNoType) { Some(mut err) => { if !ty.references_error() { + // Only suggest adding `:` if it was missing (and suggested by parsing diagnostic) + let colon = if span == item_ident.span.shrink_to_hi() { ":" } else { "" }; + // The parser provided a sub-optimal `HasPlaceholders` suggestion for the type. // We are typeck and have the real type, so remove that and suggest the actual type. // FIXME(eddyb) this looks like it should be functionality on `Diagnostic`. @@ -816,7 +819,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> { err.span_suggestion( span, &format!("provide a type for the {item}", item = kind), - format!("{}: {}", item_ident, sugg_ty), + format!("{colon} {sugg_ty}"), Applicability::MachineApplicable, ); } else {