Skip to content

Commit 325b24d

Browse files
Fix 1-tuple value suggestion
1 parent 4af94cf commit 325b24d

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -4577,21 +4577,20 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
45774577
if let (ty::Str, hir::Mutability::Not) = (ty.kind(), mutability) {
45784578
"\"\"".to_string()
45794579
} else {
4580-
let Some(ty) = self.ty_kind_suggestion(param_env, *ty) else {
4581-
return None;
4582-
};
4580+
let ty = self.ty_kind_suggestion(param_env, *ty)?;
45834581
format!("&{}{ty}", mutability.prefix_str())
45844582
}
45854583
}
45864584
ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
45874585
format!("[{}; {}]", self.ty_kind_suggestion(param_env, *ty)?, len)
45884586
}
45894587
ty::Tuple(tys) => format!(
4590-
"({})",
4588+
"({}{})",
45914589
tys.iter()
45924590
.map(|ty| self.ty_kind_suggestion(param_env, ty))
45934591
.collect::<Option<Vec<String>>>()?
4594-
.join(", ")
4592+
.join(", "),
4593+
if tys.len() == 1 { "," } else { "" }
45954594
),
45964595
_ => "value".to_string(),
45974596
})

tests/ui/return/suggest-a-value.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ LL | return;
88
|
99
help: give the `return` a value of the expected type
1010
|
11-
LL | return (42);
12-
| ++++
11+
LL | return (42,);
12+
| +++++
1313

1414
error: aborting due to 1 previous error
1515

0 commit comments

Comments
 (0)