diff --git a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs index 36fb5c8a6f7e8..48bb527c45d15 100644 --- a/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs +++ b/compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs @@ -4577,9 +4577,7 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) { "\"\"".to_string() } else { - let Some(ty) = self.ty_kind_suggestion(param_env, *ty) else { - return None; - }; + let ty = self.ty_kind_suggestion(param_env, *ty)?; format!("&{}{ty}", mutability.prefix_str()) } } @@ -4587,11 +4585,12 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> { format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len) } ty::Tuple(tys) => format!( - "({})", + "({}{})", tys.iter() .map(|ty| self.ty_kind_suggestion(param_env, ty)) .collect::>>()? - .join(", ") + .join(", "), + if tys.len() == 1 { "," } else { "" } ), _ => "value".to_string(), }) diff --git a/tests/ui/return/suggest-a-value.stderr b/tests/ui/return/suggest-a-value.stderr index 3e0045a3ec4c6..573ade7b712d8 100644 --- a/tests/ui/return/suggest-a-value.stderr +++ b/tests/ui/return/suggest-a-value.stderr @@ -8,8 +8,8 @@ LL | return; | help: give the `return` a value of the expected type | -LL | return (42); - | ++++ +LL | return (42,); + | +++++ error: aborting due to 1 previous error