Skip to content

Commit

Permalink
Fix 1-tuple value suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Apr 14, 2024
1 parent 4af94cf commit 325b24d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4577,21 +4577,20 @@ 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())
}
}
ty::Array(ty, len) if let Some(len) = len.try_eval_target_usize(tcx, param_env) => {
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::<Option<Vec<String>>>()?
.join(", ")
.join(", "),
if tys.len() == 1 { "," } else { "" }
),
_ => "value".to_string(),
})
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/return/suggest-a-value.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 325b24d

Please sign in to comment.