From 325b24d7631b5da4806fedb542a3ae2971a30ea2 Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Sun, 14 Apr 2024 09:41:16 -0400 Subject: [PATCH] Fix 1-tuple value suggestion --- .../src/traits/error_reporting/suggestions.rs | 9 ++++----- tests/ui/return/suggest-a-value.stderr | 4 ++-- 2 files changed, 6 insertions(+), 7 deletions(-) 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